Skip to content

Commit

Permalink
Merge branch 'main' into weigh_justification_and_finalization
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-nikolov96 authored Oct 11, 2023
2 parents feb05df + 8bd1efe commit b03aba0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
7 changes: 3 additions & 4 deletions beacon-light-client/plonky2/circuits/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ pub fn biguint_is_equal<F: RichField + Extendable<D>, const D: usize>(
) -> BoolTarget {
assert!(a.limbs.len() == b.limbs.len());

let mut all_equal = Vec::new();
all_equal.push(builder._true());
let mut all_equal = builder._true();

for i in 0..a.limbs.len() {
let equal = builder.is_equal(a.limbs[i].0, b.limbs[i].0);
all_equal.push(builder.and(all_equal[i], equal));
all_equal = builder.and(all_equal, equal);
}

all_equal[a.limbs.len()]
all_equal
}

pub fn create_bool_target_array<F: RichField + Extendable<D>, const D: usize>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
is_active_validator::is_active_validator,
targets_serialization::{ReadTargets, WriteTargets},
utils::{
biguint_is_equal, create_bool_target_array, if_biguint,
ssz_num_from_bits, ETH_SHA256_BIT_SIZE,
biguint_is_equal, create_bool_target_array, if_biguint, ssz_num_from_bits,
ETH_SHA256_BIT_SIZE,
},
validator_hash_tree_root_poseidon::{
hash_tree_root_validator_poseidon, ValidatorPoseidonHashTreeRootTargets,
Expand Down Expand Up @@ -143,9 +143,7 @@ pub fn validator_balance_verification<F: RichField + Extendable<D>, const D: usi

let current_epoch = builder.add_virtual_biguint_target(2);

let mut sums: Vec<BigUintTarget> = Vec::new();

sums.push(builder.zero_biguint());
let mut sum = builder.zero_biguint();

for i in 0..validators_len {
let is_equal = biguint_is_equal(
Expand All @@ -172,16 +170,14 @@ pub fn validator_balance_verification<F: RichField + Extendable<D>, const D: usi

let current = if_biguint(builder, will_be_counted, &balance, &zero);

let mut tmp_sum = builder.add_biguint(&sums[i], &current);

tmp_sum.limbs.pop();
sum = builder.add_biguint(&sum, &current);

sums.push(tmp_sum);
sum.limbs.pop();
}

ValidatorBalanceVerificationTargets {
validator_is_zero: validator_is_zero,
range_total_value: sums[validators_len].clone(),
range_total_value: sum,
range_balances_root: balances_hash_tree_root_targets.hash_tree_root,
range_validator_commitment: hash_tree_root_poseidon_targets.hash_tree_root,
validators: validators_leaves
Expand Down

0 comments on commit b03aba0

Please sign in to comment.