Skip to content

Commit

Permalink
chore(brillig): Fix brillig radix instruction return vector size (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
vezenovm authored Aug 17, 2023
1 parent feebee4 commit 9490cb7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use dep::std;

unconstrained fn main(x : Field) -> pub [u8; 4] {
unconstrained fn main(x : Field) -> pub [u8; 31] {
// The result of this byte array will be little-endian
let byte_array = x.to_le_bytes(31);
let mut first_four_bytes = [0; 4];
for i in 0..4 {
first_four_bytes[i] = byte_array[i];
assert(byte_array.len() == 31);

let mut bytes = [0; 31];
for i in 0..31 {
bytes[i] = byte_array[i];
}
// Issue #617 fix
// We were incorrectly mapping our output array from bit decomposition functions during acir generation
first_four_bytes[3] = byte_array[31];
first_four_bytes
bytes
}
15 changes: 7 additions & 8 deletions crates/nargo_cli/tests/execution_success/to_le_bytes/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use dep::std;

fn main(x : Field) -> pub [u8; 4] {
fn main(x : Field) -> pub [u8; 31] {
// The result of this byte array will be little-endian
let byte_array = x.to_le_bytes(31);
let mut first_four_bytes = [0; 4];
for i in 0..4 {
first_four_bytes[i] = byte_array[i];
assert(byte_array.len() == 31);

let mut bytes = [0; 31];
for i in 0..31 {
bytes[i] = byte_array[i];
}
// Issue #617 fix
// We were incorrectly mapping our output array from bit decomposition functions during acir generation
first_four_bytes[3] = byte_array[31];
first_four_bytes
bytes
}
10 changes: 0 additions & 10 deletions crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,16 +780,6 @@ impl AcirContext {
limb_vars.reverse();
}

// For legacy reasons (see #617) the to_radix interface supports 256 bits even though
// FieldElement::max_num_bits() is only 254 bits. Any limbs beyond the specified count
// become zero padding.
let max_decomposable_bits: u32 = 256;
let limb_count_with_padding = max_decomposable_bits / bit_size;
let zero = self.add_constant(FieldElement::zero());
while limb_vars.len() < limb_count_with_padding as usize {
limb_vars.push(AcirValue::Var(zero, result_element_type.clone()));
}

Ok(vec![AcirValue::Array(limb_vars.into())])
}

Expand Down

0 comments on commit 9490cb7

Please sign in to comment.