Skip to content

Commit 988fc08

Browse files
authored
Fix silent integer truncations (#71)
1 parent e0ab176 commit 988fc08

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

lightclient-circuits/src/gadget/crypto/sha256_wide.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, F: Field> HashInstructions<F> for Sha256ChipWide<'a, F> {
5151
let binary_input: HashInput<u8> = HashInput::Single(
5252
assigned_bytes
5353
.iter()
54-
.map(|av| av.value().get_lower_32() as u8)
54+
.map(|av| u8::try_from(av.value().get_lower_32()).expect("truncated"))
5555
.collect_vec()
5656
.into(),
5757
);

lightclient-circuits/src/util/circuit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Halo2ConfigPinning for Eth2ConfigPinning {
7373
}
7474

7575
fn degree(&self) -> u32 {
76-
self.params.k as u32
76+
u32::try_from(self.params.k).expect("k is too large for u32")
7777
}
7878
}
7979

test-utils/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ pub fn get_initial_sync_committee_poseidon<const EPOCHS_PER_SYNC_COMMITTEE_PERIO
4444
poseidon_committee_commitment_from_uncompressed(&pubkeys_uncompressed, LIMB_BITS);
4545
let committee_poseidon =
4646
ethers::prelude::U256::from_little_endian(&committee_poseidon.to_bytes());
47-
let sync_period = (bootstrap.header.beacon.slot as usize) / EPOCHS_PER_SYNC_COMMITTEE_PERIOD;
47+
let sync_period = (usize::try_from(bootstrap.header.beacon.slot).expect("truncated"))
48+
/ EPOCHS_PER_SYNC_COMMITTEE_PERIOD;
4849
Ok((sync_period, committee_poseidon))
4950
}
5051

0 commit comments

Comments
 (0)