From 81b597ca61fe9b60abc4153a39e1189ec01f61bb Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 12 Jan 2024 11:13:28 +0000 Subject: [PATCH] feat: assert maximum bit size when creating a U128 from an integer --- noir_stdlib/src/uint128.nr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/noir_stdlib/src/uint128.nr b/noir_stdlib/src/uint128.nr index 4a58b3868be..9f1e7b4b76e 100644 --- a/noir_stdlib/src/uint128.nr +++ b/noir_stdlib/src/uint128.nr @@ -116,6 +116,8 @@ impl U128 { pub fn from_integer(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 { @@ -289,4 +291,4 @@ impl Shr for U128 { } self / U128::from_integer(y) } -} \ No newline at end of file +}