Skip to content

Commit 2057d3d

Browse files
Move row proof to a separate module
1 parent 04e10f2 commit 2057d3d

File tree

3 files changed

+72
-62
lines changed

3 files changed

+72
-62
lines changed

rust/catalyst-contest/src/choices.rs

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use cbork_utils::decode_helper::decode_array_len;
44
use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
55

6-
use crate::elgamal_ristretto255_choice::ElgamalRistretto255Choice;
6+
use crate::{elgamal_ristretto255_choice::ElgamalRistretto255Choice, row_proof::RowProof};
77

88
/// Voters Choices.
99
///
@@ -34,32 +34,6 @@ pub enum Choices {
3434
},
3535
}
3636

37-
/// A universal encrypted row proof.
38-
///
39-
/// The CDDL schema:
40-
/// ```cddl
41-
/// row-proof = [0, zkproof-elgamal-ristretto255-unit-vector-with-single-selection ]
42-
///
43-
/// zkproof-elgamal-ristretto255-unit-vector-with-single-selection = [ +zkproof-elgamal-ristretto255-unit-vector-with-single-selection-item, zkproof-ed25519-scalar ]
44-
///
45-
/// zkproof-elgamal-ristretto255-unit-vector-with-single-selection-item = ( zkproof-elgamal-announcement, ~elgamal-ristretto255-encrypted-choice, zkproof-ed25519-r-response )
46-
///
47-
/// zkproof-elgamal-announcement = ( zkproof-elgamal-group-element, zkproof-elgamal-group-element, zkproof-elgamal-group-element )
48-
///
49-
/// zkproof-elgamal-group-element = bytes .size 32
50-
///
51-
/// zkproof-ed25519-r-response = ( zkproof-ed25519-scalar, zkproof-ed25519-scalar, zkproof-ed25519-scalar )
52-
///
53-
/// zkproof-ed25519-scalar = bytes .size 32
54-
/// ```
55-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
56-
pub struct RowProof {
57-
/// A list of a single selection proofs.
58-
selections: Vec<()>,
59-
/// An individual Ed25519 scalar used in ZK proofs.
60-
scalar: (),
61-
}
62-
6337
impl Decode<'_, ()> for Choices {
6438
fn decode(
6539
d: &mut Decoder<'_>,
@@ -124,33 +98,12 @@ impl Encode<()> for Choices {
12498
}
12599
}
126100

127-
impl Decode<'_, ()> for RowProof {
128-
fn decode(
129-
d: &mut Decoder<'_>,
130-
ctx: &mut (),
131-
) -> Result<Self, minicbor::decode::Error> {
132-
// TODO: FIXME:
133-
todo!()
134-
}
135-
}
136-
137-
impl Encode<()> for RowProof {
138-
fn encode<W: Write>(
139-
&self,
140-
e: &mut Encoder<W>,
141-
ctx: &mut (),
142-
) -> Result<(), minicbor::encode::Error<W::Error>> {
143-
// TODO: FIXME:
144-
todo!()
145-
}
146-
}
147-
148101
#[cfg(test)]
149102
mod tests {
150103
use super::*;
151104

152105
#[test]
153-
fn clear_choices_roundtrip() {
106+
fn clear_roundtrip() {
154107
let original = Choices::Clear(vec![1, 2, 3]);
155108
let mut buffer = Vec::new();
156109
original
@@ -161,7 +114,7 @@ mod tests {
161114
}
162115

163116
#[test]
164-
fn elgamal_ristretto255_choices_roundtrip() {
117+
fn elgamal_ristretto255_roundtrip() {
165118
let original = Choices::ElgamalRistretto255 {
166119
choices: vec![],
167120
row_proof: Some(RowProof {}),
@@ -173,15 +126,4 @@ mod tests {
173126
let decoded = Choices::decode(&mut Decoder::new(&buffer), &mut ()).unwrap();
174127
assert_eq!(original, decoded);
175128
}
176-
177-
#[test]
178-
fn row_proof_roundtrip() {
179-
let original = RowProof {};
180-
let mut buffer = Vec::new();
181-
original
182-
.encode(&mut Encoder::new(&mut buffer), &mut ())
183-
.unwrap();
184-
let decoded = RowProof::decode(&mut Decoder::new(&buffer), &mut ()).unwrap();
185-
assert_eq!(original, decoded);
186-
}
187129
}

rust/catalyst-contest/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ mod contest_ballot;
1313
mod elgamal_ristretto255_choice;
1414
mod encrypted_choices;
1515
mod matrix_proof;
16+
mod row_proof;
1617

1718
pub use crate::{
18-
choices::{Choices, RowProof},
19+
choices::Choices,
1920
column_proof::ColumnProof,
2021
contest_ballot::ContentBallot,
2122
elgamal_ristretto255_choice::ElgamalRistretto255Choice,
2223
encrypted_choices::{EncryptedBlock, EncryptedChoices},
2324
matrix_proof::MatrixProof,
25+
row_proof::RowProof,
2426
};
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//! A universal encrypted row proof.
2+
3+
use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
4+
5+
/// A universal encrypted row proof.
6+
///
7+
/// The CDDL schema:
8+
/// ```cddl
9+
/// row-proof = [0, zkproof-elgamal-ristretto255-unit-vector-with-single-selection ]
10+
///
11+
/// zkproof-elgamal-ristretto255-unit-vector-with-single-selection = [ +zkproof-elgamal-ristretto255-unit-vector-with-single-selection-item, zkproof-ed25519-scalar ]
12+
///
13+
/// zkproof-elgamal-ristretto255-unit-vector-with-single-selection-item = ( zkproof-elgamal-announcement, ~elgamal-ristretto255-encrypted-choice, zkproof-ed25519-r-response )
14+
///
15+
/// zkproof-elgamal-announcement = ( zkproof-elgamal-group-element, zkproof-elgamal-group-element, zkproof-elgamal-group-element )
16+
///
17+
/// zkproof-elgamal-group-element = bytes .size 32
18+
///
19+
/// zkproof-ed25519-r-response = ( zkproof-ed25519-scalar, zkproof-ed25519-scalar, zkproof-ed25519-scalar )
20+
///
21+
/// zkproof-ed25519-scalar = bytes .size 32
22+
/// ```
23+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
24+
pub struct RowProof {
25+
/// A list of a single selection proofs.
26+
pub selections: Vec<()>,
27+
/// An individual Ed25519 scalar used in ZK proofs.
28+
pub scalar: (),
29+
}
30+
31+
impl Decode<'_, ()> for RowProof {
32+
fn decode(
33+
d: &mut Decoder<'_>,
34+
ctx: &mut (),
35+
) -> Result<Self, minicbor::decode::Error> {
36+
// TODO: FIXME:
37+
todo!()
38+
}
39+
}
40+
41+
impl Encode<()> for RowProof {
42+
fn encode<W: Write>(
43+
&self,
44+
e: &mut Encoder<W>,
45+
ctx: &mut (),
46+
) -> Result<(), minicbor::encode::Error<W::Error>> {
47+
// TODO: FIXME:
48+
todo!()
49+
}
50+
}
51+
52+
#[cfg(test)]
53+
mod tests {
54+
use super::*;
55+
56+
#[test]
57+
fn roundtrip() {
58+
let original = RowProof {};
59+
let mut buffer = Vec::new();
60+
original
61+
.encode(&mut Encoder::new(&mut buffer), &mut ())
62+
.unwrap();
63+
let decoded = RowProof::decode(&mut Decoder::new(&buffer), &mut ()).unwrap();
64+
assert_eq!(original, decoded);
65+
}
66+
}

0 commit comments

Comments
 (0)