Skip to content

Commit

Permalink
Fix silent integer truncations (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltea authored Mar 11, 2024
1 parent e0ab176 commit 988fc08
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lightclient-circuits/src/gadget/crypto/sha256_wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a, F: Field> HashInstructions<F> for Sha256ChipWide<'a, F> {
let binary_input: HashInput<u8> = HashInput::Single(
assigned_bytes
.iter()
.map(|av| av.value().get_lower_32() as u8)
.map(|av| u8::try_from(av.value().get_lower_32()).expect("truncated"))
.collect_vec()
.into(),
);
Expand Down
2 changes: 1 addition & 1 deletion lightclient-circuits/src/util/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Halo2ConfigPinning for Eth2ConfigPinning {
}

fn degree(&self) -> u32 {
self.params.k as u32
u32::try_from(self.params.k).expect("k is too large for u32")
}
}

Expand Down
3 changes: 2 additions & 1 deletion test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ pub fn get_initial_sync_committee_poseidon<const EPOCHS_PER_SYNC_COMMITTEE_PERIO
poseidon_committee_commitment_from_uncompressed(&pubkeys_uncompressed, LIMB_BITS);
let committee_poseidon =
ethers::prelude::U256::from_little_endian(&committee_poseidon.to_bytes());
let sync_period = (bootstrap.header.beacon.slot as usize) / EPOCHS_PER_SYNC_COMMITTEE_PERIOD;
let sync_period = (usize::try_from(bootstrap.header.beacon.slot).expect("truncated"))
/ EPOCHS_PER_SYNC_COMMITTEE_PERIOD;
Ok((sync_period, committee_poseidon))
}

Expand Down

0 comments on commit 988fc08

Please sign in to comment.