Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Constrain slices from field decomposition functions to be expected length #2451

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions noir_stdlib/src/field.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

impl Field {
#[builtin(to_le_bits)]
fn to_le_bits(_x : Field, _bit_size: u32) -> [u1] {}
#[builtin(to_be_bits)]
fn to_be_bits(_x : Field, _bit_size: u32) -> [u1] {}

fn to_le_bits(x : Field, bit_size: u32) -> [u1] {
let bit_array = x.__to_le_bits(bit_size);
assert(bit_array.len() == bit_size as Field);
bit_array
}
fn to_be_bits(x : Field, bit_size: u32) -> [u1] {
let bit_array = x.__to_be_bits(bit_size);
assert(bit_array.len() == bit_size as Field);
bit_array
}

fn to_le_bytes(x : Field, byte_size: u32) -> [u8] {
x.to_le_radix(256, byte_size)
Expand All @@ -12,12 +19,30 @@ impl Field {
x.to_be_radix(256, byte_size)
}

#[builtin(to_le_radix)]
fn to_le_radix(x : Field, radix: u32, result_len: u32) -> [u8] {
let radix_array = x.__to_le_radix(radix, result_len);
assert(radix_array.len() == result_len as Field);
radix_array
}

fn to_be_radix(x : Field, radix: u32, result_len: u32) -> [u8] {
let radix_array = x.__to_be_radix(radix, result_len);
assert(radix_array.len() == result_len as Field);
radix_array
}

#[builtin(to_le_bits)]
fn __to_le_bits(_x : Field, _bit_size: u32) -> [u1] {}
#[builtin(to_be_bits)]
fn __to_be_bits(_x : Field, _bit_size: u32) -> [u1] {}


//decompose _x into a _result_len vector over the _radix basis
//_radix must be less than 256
fn to_le_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {}
#[builtin(to_le_radix)]
fn __to_le_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {}
#[builtin(to_be_radix)]
fn to_be_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {}
fn __to_be_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {}

// Returns self to the power of the given exponent value.
// Caution: we assume the exponent fits into 32 bits
Expand Down