Skip to content

Commit 8dfce7c

Browse files
authored
feat: Fragment generator | NPG-0000 (#596)
Fragment generator in byte format. [As per specification](https://github.com/input-output-hk/catalyst-core/blob/main/src/chain-libs/chain-impl-mockchain/doc/format.abnf). The original idea was to isolate and rewrite a bare bones version of the specification from scratch to verify the spec and our existing implementation. This was largely done except for the cryptography. The encrypted vote part is [manageable to rewrite](https://github.com/input-output-hk/catalyst-core/blob/main/src/chain-libs/chain-impl-mockchain/doc/format.abnf#L170) and somewhat **standard**. However the ZKP proof is not, the algorithm from the treasury paper is NOVEL and difficult to recreate with external off the shelf libs. An isolated ZKP implementation with no baggage in the context of cat-core requires a rewrite from scratch as there is no existing libs suitable; any rewrite is basically a mirror of our existing cryptography and vote crates in cat-core. In any case, we need to use the binary of this crate within the context of our load tester. We can potentially come back to alternatives implementation of the ZKP stuff in the future.
1 parent 7a8c69c commit 8dfce7c

File tree

9 files changed

+538
-0
lines changed

9 files changed

+538
-0
lines changed

Cargo.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ members = [
5858
"src/vit-servicing-station-f10/vit-servicing-station-lib-f10",
5959
"src/vit-servicing-station-f10/vit-servicing-station-server-f10",
6060
"src/vit-servicing-station-f10/vit-servicing-station-tests-f10",
61+
"src/sign",
6162
]
6263

6364
[workspace.dependencies]

src/chain-libs/chain-impl-mockchain/src/transaction/transaction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ pub(super) struct TransactionStruct {
265265
/// Verify the structure of the transaction and return all the offsets
266266
fn get_spine<P: Payload>(slice: &[u8]) -> Result<TransactionStruct, TransactionStructError> {
267267
let sz = slice.len();
268+
268269
let mut codec = Codec::new(slice);
269270

270271
// read payload

src/chain-libs/chain-vote/src/cryptography/zkps/unit_vector/zkp.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ impl Zkp {
293293
self.ibas.iter()
294294
}
295295

296+
/// Return announcement commitments group elements
297+
pub fn announcments_group_elements(&self) -> Vec<GroupElement> {
298+
let mut announcements = Vec::new();
299+
for g in self.ibas.clone() {
300+
announcements.push(g.i);
301+
announcements.push(g.b);
302+
announcements.push(g.a)
303+
}
304+
announcements
305+
}
306+
296307
/// Return an iterator of the encryptions of the polynomial coefficients
297308
pub fn ds(&self) -> impl Iterator<Item = &Ciphertext> {
298309
self.ds.iter()
@@ -303,6 +314,18 @@ impl Zkp {
303314
self.zwvs.iter()
304315
}
305316

317+
/// Return an iterator of the response related to the randomness
318+
pub fn response_randomness_group_elements(&self) -> Vec<Scalar> {
319+
let mut response = Vec::new();
320+
for z in self.zwvs.iter().clone() {
321+
response.push(z.z.clone());
322+
response.push(z.w.clone());
323+
response.push(z.v.clone());
324+
}
325+
326+
response
327+
}
328+
306329
/// Return R
307330
pub fn r(&self) -> &Scalar {
308331
&self.r

src/chain-libs/chain-vote/src/encrypted_vote.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ mod tests {
219219
#[test]
220220
fn unit_vector() {
221221
let uv = UnitVector::new(5, 0).unwrap();
222+
222223
assert_eq!(
223224
&uv.iter().collect::<Vec<_>>()[..],
224225
[true, false, false, false, false]

src/sign/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "sign"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
chain-crypto = { path = "../chain-libs/chain-crypto" }
10+
chain-vote = { path = "../chain-libs/chain-vote" }
11+
jormungandr-lib = { path = "../jormungandr/jormungandr-lib" }
12+
chain-addr = { path = "../chain-libs/chain-addr" }
13+
chain-core = { path = "../chain-libs/chain-core" }
14+
chain-impl-mockchain = { path = "../chain-libs/chain-impl-mockchain" ,features= ["audit"]}
15+
chain-ser = { path = "../chain-libs/chain-ser" }
16+
chain-storage = { path = "../chain-libs/chain-storage" }
17+
18+
19+
hex = "0.4"
20+
cryptoxide = "0.4.2"
21+
rand_chacha = "0.3"
22+
23+
clap = { version = "4", features = ["derive", "cargo"] }
24+
clap_complete_command = { version = "0.5" }
25+
26+
color-eyre = "0.6"
27+
thiserror = "1.0.40"
28+
csv = "1.1"
29+
30+
serde = "1.0"
31+
serde_json = "1.0"
32+
serde_yaml = "0.8.17"
33+
rand = "0.8.3"
34+
bech32 = "0.8"
35+
36+
37+
rand_core = { version = "0.5.1", default-features = false }
38+
39+
40+
ed25519-dalek = "1.0.1"

src/sign/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Fragment generator and signer:
2+
3+
## Specifications
4+
[*see here for format.abnf*](../chain-libs/chain-impl-mockchain/doc/format.abnf)
5+
6+
[*see here for format.md*](../chain-libs/chain-impl-mockchain/doc/format.md)
7+
8+
## Ingredients for generating a fragment
9+
10+
- Election public key
11+
- Alice public key
12+
- Alice private key
13+
- proposal to vote on
14+
- vote plan id (hash of voteplan)
15+
16+
*Example usage:*
17+
18+
```
19+
cargo build --release -p sign
20+
```
21+
22+
*Generate raw fragment in byte representation*
23+
24+
```bash
25+
26+
ELECTION_PUB_KEY=ristretto255_votepk1ppxnuxrqa4728evnp2ues000uvwvwtxmtf77ejc29lknjuqqu44s4cfmja
27+
ALICE_SK=56e367979579e2ce27fbd305892b0706b7dede999a534a864a7430a5c6aefd3c
28+
ALICE_PK=ea084d2d80ed0ab681333d934efc56df3868d13d46a2de3b7f27f40b62e5344d
29+
PROPOSAL=5
30+
VOTE_PLAN_ID=36ad42885189a0ac3438cdb57bc8ac7f6542e05a59d1f2e4d1d38194c9d4ac7b
31+
32+
./target/release/sign --election-pub-key $ELECTION_PUB_KEY --private-key $ALICE_SK --public-key $ALICE_PK --proposal $PROPOSAL --vote-plan-id $VOTE_PLAN_ID
33+
34+
```

0 commit comments

Comments
 (0)