Skip to content

Commit

Permalink
fix: change non-constant argument errors from to_be_radix from ICE …
Browse files Browse the repository at this point in the history
…to proper error (#3048)

Co-authored-by: kevaundray <[email protected]>
  • Loading branch information
TomAFrench and kevaundray authored Oct 9, 2023
1 parent 599e7a1 commit 19ce286
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
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);
}

0 comments on commit 19ce286

Please sign in to comment.