Skip to content

Commit 32837b1

Browse files
Add some documentation
1 parent c805686 commit 32837b1

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

rust/catalyst-contest/src/choices.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ use cbork_utils::decode_helper::decode_array_len;
44
use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
55

66
/// Voters Choices.
7+
///
8+
/// The CDDL schema:
9+
/// ```cddl
10+
/// choices = [ 0, clear-choices ] /
11+
/// [ 1, elgamal-ristretto255-encrypted-choices ]
12+
///
13+
/// clear-choices = ( +clear-choice )
14+
///
15+
/// clear-choice = int
16+
///
17+
/// elgamal-ristretto255-encrypted-choices = [
18+
/// [+ elgamal-ristretto255-encrypted-choice]
19+
/// ? row-proof
20+
/// ]
21+
/// ```
722
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
823
pub enum Choices {
924
/// A universal unencrypted set of choices.
@@ -18,6 +33,16 @@ pub enum Choices {
1833
}
1934

2035
/// An elgamal encrypted ciphertext `(c1, c2)`.
36+
///
37+
/// The CDDL schema:
38+
/// ```cddl
39+
/// elgamal-ristretto255-encrypted-choice = [
40+
/// c1: elgamal-ristretto255-group-element
41+
/// c2: elgamal-ristretto255-group-element
42+
/// ]
43+
///
44+
/// elgamal-ristretto255-group-element = bytes .size 32
45+
/// ```
2146
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2247
pub struct ElgamalRistretto255Choice {
2348
/// An individual Elgamal group element that composes the elgamal cipher text.
@@ -27,9 +52,29 @@ pub struct ElgamalRistretto255Choice {
2752
}
2853

2954
/// A universal encrypted row proof.
55+
///
56+
/// The CDDL schema:
57+
/// ```cddl
58+
/// row-proof = [0, zkproof-elgamal-ristretto255-unit-vector-with-single-selection ]
59+
///
60+
/// zkproof-elgamal-ristretto255-unit-vector-with-single-selection = [ +zkproof-elgamal-ristretto255-unit-vector-with-single-selection-item, zkproof-ed25519-scalar ]
61+
///
62+
/// zkproof-elgamal-ristretto255-unit-vector-with-single-selection-item = ( zkproof-elgamal-announcement, ~elgamal-ristretto255-encrypted-choice, zkproof-ed25519-r-response )
63+
///
64+
/// zkproof-elgamal-announcement = ( zkproof-elgamal-group-element, zkproof-elgamal-group-element, zkproof-elgamal-group-element )
65+
///
66+
/// zkproof-elgamal-group-element = bytes .size 32
67+
///
68+
/// zkproof-ed25519-r-response = ( zkproof-ed25519-scalar, zkproof-ed25519-scalar, zkproof-ed25519-scalar )
69+
///
70+
/// zkproof-ed25519-scalar = bytes .size 32
71+
/// ```
3072
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
3173
pub struct RowProof {
32-
// TODO: FIXME:
74+
/// A list of a single selection proofs.
75+
selections: Vec<()>,
76+
/// An individual Ed25519 scalar used in ZK proofs.
77+
scalar: (),
3378
}
3479

3580
impl Decode<'_, ()> for Choices {

rust/catalyst-contest/src/column_proof.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
77
const ARRAY_LEN: u64 = 2;
88

99
/// A universal encrypted column proof.
10+
///
11+
/// The CDDL schema:
12+
/// ```cddl
13+
/// column-proof = [ uint, [ +undefined ] ]
14+
/// ```
1015
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1116
pub struct ColumnProof(pub u64);
1217

rust/catalyst-contest/src/contest_ballot.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
88
use crate::{Choices, ColumnProof, EncryptedChoices, MatrixProof};
99

1010
/// An individual Ballot cast in a Contest by a registered user.
11+
///
12+
/// The CDDL schema:
13+
/// ```cddl
14+
/// contest-ballot-payload = {
15+
/// + uint => choices
16+
/// ? "column-proof" : column-proof
17+
/// ? "matrix-proof" : matrix-proof
18+
/// ? "voter-choice" : voter-choice
19+
/// }
20+
/// ```
1121
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1222
pub struct ContentBallot {
1323
/// A map of voters choices.

rust/catalyst-contest/src/encrypted_choices.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
77
const ENCRYPTED_BLOCK_ARRAY_LEN: u64 = 16;
88

99
/// Encrypted voter choices.
10+
///
11+
/// The CDDL schema:
12+
/// ```cddl
13+
/// voter-choice = [ 0, aes-ctr-encrypted-choices ]
14+
///
15+
/// aes-ctr-encrypted-choices = +aes-ctr-encrypted-block
16+
/// ```
1017
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1118
pub struct EncryptedChoices(pub Vec<EncryptedBlock>);
1219

1320
/// An AES-CTR encrypted data block.
21+
///
22+
/// The CDDL schema:
23+
/// ```cddl
24+
/// aes-ctr-encrypted-block = bytes .size 16
25+
/// ```
1426
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1527
pub struct EncryptedBlock(pub [u8; ENCRYPTED_BLOCK_ARRAY_LEN as usize]);
1628

@@ -25,10 +37,10 @@ impl Decode<'_, ()> for EncryptedChoices {
2537
"Unexpected encrypted choices array length: {len}, expected at least 2"
2638
)));
2739
}
28-
let val = u64::decode(d, ctx)?;
29-
if val != 0 {
40+
let version = u64::decode(d, ctx)?;
41+
if version != 0 {
3042
return Err(minicbor::decode::Error::message(format!(
31-
"Unexpected encrypted choices array value: {val}, expected 0"
43+
"Unexpected encrypted choices array value: {version}, expected 0"
3244
)));
3345
}
3446

rust/catalyst-contest/src/matrix_proof.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
77
const ARRAY_LEN: u64 = 2;
88

99
/// A universal encrypted matrix proof.
10+
///
11+
/// The CDDL schema:
12+
/// ```cddl
13+
/// matrix-proof = [ uint, undefined ]
14+
/// ```
1015
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1116
pub struct MatrixProof(pub u64);
1217

0 commit comments

Comments
 (0)