Skip to content

Commit 2e58820

Browse files
authored
Fragment generator add epoch slot (#610)
add epoch and slot for testing
1 parent 45dcf7c commit 2e58820

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/sign/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- Alice private key
1313
- proposal to vote on
1414
- vote plan id (hash of voteplan)
15+
- epoch
16+
- slot
1517

1618
*Example usage:*
1719

@@ -28,7 +30,9 @@ ALICE_SK=56e367979579e2ce27fbd305892b0706b7dede999a534a864a7430a5c6aefd3c
2830
ALICE_PK=ea084d2d80ed0ab681333d934efc56df3868d13d46a2de3b7f27f40b62e5344d
2931
PROPOSAL=5
3032
VOTE_PLAN_ID=36ad42885189a0ac3438cdb57bc8ac7f6542e05a59d1f2e4d1d38194c9d4ac7b
33+
EPOCH=0
34+
SLOT=0
3135

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
36+
./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 --epoch $EPOCH --slot $SLOT
3337

3438
```

src/sign/src/fragment.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ const VOTE_CAST_TAG: u8 = 11;
1717
/// INPUT-ACCOUNT = %xff VALUE UNTAG-ACCOUNT-ID
1818
const INPUT_ACCOUNT: u8 = 255;
1919

20-
/// Block epoch + slot
21-
/// This is redundant as time checks have been removed
22-
const EPOCH: u32 = 0;
23-
const SLOT: u32 = 0;
24-
2520
/// Only 1 input (subsequently 1 witness), no output
2621
/// VoteCast TX should have only 1 input, 0 output and 1 witness (signature).
2722
const INPUT: u8 = 1;
@@ -51,6 +46,8 @@ pub fn generate_vote_fragment(
5146
proof: Vec<u8>,
5247
proposal: u8,
5348
vote_plan_id: &[u8],
49+
epoch: u32,
50+
slot: u32,
5451
) -> Result<Vec<u8>, Box<dyn error::Error>> {
5552
let mut vote_cast = Codec::new(Vec::new());
5653

@@ -62,7 +59,8 @@ pub fn generate_vote_fragment(
6259

6360
let data_to_sign = vote_cast.into_inner().clone();
6461

65-
let (inputs, witness) = compose_inputs_and_witnesses(keypair, data_to_sign.clone())?;
62+
let (inputs, witness) =
63+
compose_inputs_and_witnesses(keypair, data_to_sign.clone(), epoch, slot)?;
6664

6765
let mut vote_cast = Codec::new(Vec::new());
6866
vote_cast.put_bytes(&data_to_sign)?;
@@ -85,11 +83,13 @@ pub fn generate_vote_fragment(
8583
fn compose_inputs_and_witnesses(
8684
keypair: Keypair,
8785
data_to_sign: Vec<u8>,
86+
epoch: u32,
87+
slot: u32,
8888
) -> Result<(Vec<u8>, Vec<u8>), Box<dyn error::Error>> {
8989
let mut inputs = Codec::new(Vec::new());
9090

91-
inputs.put_be_u32(EPOCH)?;
92-
inputs.put_be_u32(SLOT)?;
91+
inputs.put_be_u32(epoch)?;
92+
inputs.put_be_u32(slot)?;
9393
inputs.put_u8(INPUT)?;
9494
inputs.put_u8(OUTPUT)?;
9595

@@ -219,6 +219,8 @@ mod tests {
219219
proof,
220220
5,
221221
&hex::decode(vote_plan_id.clone()).unwrap(),
222+
0,
223+
0,
222224
)
223225
.unwrap();
224226

src/sign/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ pub struct Args {
3535
/// proposal to vote on
3636
#[clap(short, long)]
3737
proposal: u8,
38+
/// Epoch
39+
#[clap(short, long)]
40+
epoch: u32,
41+
/// Slot
42+
#[clap(short, long)]
43+
slot: u32,
3844
/// vote plan hash
3945
#[clap(short, long)]
4046
vote_plan_id: String,
@@ -77,6 +83,8 @@ fn main() -> Result<(), Box<dyn Error>> {
7783
proof,
7884
args.proposal,
7985
&hex::decode(args.vote_plan_id)?,
86+
args.epoch,
87+
args.slot,
8088
)?;
8189

8290
// fragment in hex: output consumed as input to another program

0 commit comments

Comments
 (0)