Skip to content

Commit

Permalink
Improve prove finality structure
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayKostadinov21 committed Dec 18, 2023
1 parent ae96e5f commit 1960626
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
21 changes: 10 additions & 11 deletions casper-finality-proofs/src/prove_finality/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ impl Circuit for ProveFinality {
fn define<L: PlonkParameters<D>, const D: usize>(builder: &mut CircuitBuilder<L, D>) {
let source = builder.read::<CheckpointVariable>();
let target = builder.read::<CheckpointVariable>();
let target_source_difference = builder.sub(target.epoch, source.epoch);
let slot = builder.read::<Gwei>();
let total_number_of_validators = builder.read::<Gwei>();
let justification_bits = builder.read::<JustificationBitsVariable>();
let previous_epoch_attested_validators = builder.read::<Gwei>();
let current_epoch_attested_validators = builder.read::<Gwei>();

let zero = builder.constant::<U64Variable>(0);
let one = builder.constant::<U64Variable>(1);
let two = builder.constant::<U64Variable>(2);
let thirty_two = builder.constant::<U64Variable>(32);

let target_source_difference = builder.sub(target.epoch, source.epoch);
let target_source_difference_equals_one = builder.is_equal(target_source_difference, one);
let target_source_difference_equals_two = builder.is_equal(target_source_difference, two);
let target_source_difference_equals_one_or_two = builder.or(
Expand All @@ -29,22 +37,13 @@ impl Circuit for ProveFinality {
);
assert_is_true(builder, target_source_difference_equals_one_or_two);

let slot = builder.read::<Gwei>();
let zero = builder.constant::<U64Variable>(0);
let thirty_two = builder.constant::<U64Variable>(32);

let current_epoch = builder.div(slot, thirty_two);
let current_epoch_target_difference = builder.sub(current_epoch, target.epoch);
let target_is_first_bit = builder.is_equal(current_epoch_target_difference, zero);
let target_is_second_bit = builder.is_equal(current_epoch_target_difference, one);
let is_target_first_or_second_bit = builder.or(target_is_first_bit, target_is_second_bit);
assert_is_true(builder, is_target_first_or_second_bit);

let total_number_of_validators = builder.read::<Gwei>();
let justification_bits = builder.read::<JustificationBitsVariable>();
let previous_epoch_attested_validators = builder.read::<Gwei>();
let current_epoch_attested_validators = builder.read::<Gwei>();

let new_justification_bits = process_justifications(
builder,
total_number_of_validators,
Expand All @@ -55,7 +54,7 @@ impl Circuit for ProveFinality {

let new_justification_bits = new_justification_bits.bits.as_slice();
let source_index = builder.sub(current_epoch, source.epoch);
let target_index = builder.sub(current_epoch, target.epoch);
let target_index = current_epoch_target_difference;
for i in 0..4 {
let current_index = builder.constant::<U64Variable>(i as u64);
let in_range_source_index = builder.lte(current_index, source_index);
Expand Down
1 change: 1 addition & 0 deletions casper-finality-proofs/vendor
Submodule vendor added at 080c96

0 comments on commit 1960626

Please sign in to comment.