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

fix: change non-constant argument errors from to_be_radix from ICE to proper error #3048

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
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
49 changes: 39 additions & 10 deletions noir_stdlib/src/field.nr
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@

impl Field {
pub fn to_le_bits(self: Self, bit_size: u32) -> [u1] {
crate::assert_constant(bit_size);
self.__to_le_bits(bit_size)
}

pub fn to_be_bits(self: Self, bit_size: u32) -> [u1] {
crate::assert_constant(bit_size);
self.__to_be_bits(bit_size)
}

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

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

pub fn to_le_bytes(self: Self, byte_size: u32) -> [u8] {
self.to_le_radix(256, byte_size)
}

pub fn to_be_bytes(self: Self, byte_size: u32) -> [u8] {
self.to_be_radix(256, byte_size)
}


pub fn to_le_bytes(x : Field, byte_size: u32) -> [u8] {
x.to_le_radix(256, byte_size)
pub fn to_le_radix(self: Self, radix: u32, result_len: u32) -> [u8] {
crate::assert_constant(radix);
crate::assert_constant(result_len);
self.__to_le_radix(radix, result_len)
}
pub fn to_be_bytes(x : Field, byte_size: u32) -> [u8] {
x.to_be_radix(256, byte_size)

pub fn to_be_radix(self: Self, radix: u32, result_len: u32) -> [u8] {
crate::assert_constant(radix);
crate::assert_constant(result_len);
self.__to_be_radix(radix, result_len)
}



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

#[builtin(to_be_radix)]
pub fn to_be_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {}
fn __to_be_radix(_self: Self, _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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "radix_non_constant_length"
type = "bin"
authors = [""]
compiler_version = "0.10.2"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "5"
y = "10"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main(x : Field, y : pub u32) {
let bytes = x.to_be_bytes(y);
assert(bytes[0] == 0);
}