Skip to content

Commit 7bae119

Browse files
committed
feat: assert maximum bit size when creating a U128 from an integer
1 parent 15df7bf commit 7bae119

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

noir_stdlib/src/uint128.nr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ impl U128 {
116116

117117
pub fn from_integer<T>(i: T) -> U128 {
118118
let f = crate::as_field(i);
119+
// Reject values which would overflow a u128
120+
f.assert_max_bit_size(128);
119121
let lo = f as u64 as Field;
120122
let hi = (f-lo) / pow64;
121123
U128 {
@@ -289,4 +291,4 @@ impl Shr for U128 {
289291
}
290292
self / U128::from_integer(y)
291293
}
292-
}
294+
}

0 commit comments

Comments
 (0)