Skip to content

Commit

Permalink
Merge pull request #243 from zksecurity/fix/check-prime-bit
Browse files Browse the repository at this point in the history
fix potential uint overflow
  • Loading branch information
mimoo authored Dec 15, 2024
2 parents e0e9e55 + eb046e6 commit 1b515e8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/stdlib/native/int/lib.no
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ struct Uint8 {
fn Uint8.new(val: Field) -> Uint8 {
let bit_len = 8;

bits::check_field_size(bit_len);
// has to ensure multiply won't overflow prime field
bits::check_field_size(bit_len * 2);

// range check
let ignore_ = bits::to_bits(bit_len, val);
Expand All @@ -33,7 +34,8 @@ struct Uint16 {
fn Uint16.new(val: Field) -> Uint16 {
let bit_len = 16;

bits::check_field_size(bit_len);
// has to ensure multiply won't overflow prime field
bits::check_field_size(bit_len * 2);

// range check
let ignore_ = bits::to_bits(bit_len, val);
Expand All @@ -52,7 +54,8 @@ struct Uint32 {
fn Uint32.new(val: Field) -> Uint32 {
let bit_len = 32;

bits::check_field_size(bit_len);
// has to ensure multiply won't overflow prime field
bits::check_field_size(bit_len * 2);

// range check
let ignore_ = bits::to_bits(bit_len, val);
Expand All @@ -71,7 +74,8 @@ struct Uint64 {
fn Uint64.new(val: Field) -> Uint64 {
let bit_len = 64;

bits::check_field_size(bit_len);
// has to ensure multiply won't overflow prime field
bits::check_field_size(bit_len * 2);

// range check
let ignore_ = bits::to_bits(bit_len, val);
Expand Down

0 comments on commit 1b515e8

Please sign in to comment.