Skip to content

Commit

Permalink
feat: assert maximum bit size when creating a U128 from an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jan 12, 2024
1 parent bc9a44f commit 81b597c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion noir_stdlib/src/uint128.nr
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ impl U128 {

pub fn from_integer<T>(i: T) -> U128 {
let f = crate::as_field(i);
// Reject values which would overflow a u128
f.assert_max_bit_size(128);
let lo = f as u64 as Field;
let hi = (f-lo) / pow64;
U128 {
Expand Down Expand Up @@ -289,4 +291,4 @@ impl Shr for U128 {
}
self / U128::from_integer(y)
}
}
}

0 comments on commit 81b597c

Please sign in to comment.