Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix silent integer truncations #71

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -79,7 +79,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
Loading