Skip to content

Commit

Permalink
fix(ssa): set correct predecessors of IF join (#1171)
Browse files Browse the repository at this point in the history
fix predecessors of IF join
  • Loading branch information
guipublic authored Apr 18, 2023
1 parent 809b85f commit 7628ed6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions crates/nargo_cli/tests/test_data/regression/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,61 @@ fn compact_decode<N>(input: [u8; N], length: Field) -> ([u4; NIBBLE_LENGTH], Fie
out
}

fn enc<N>(value: [u8; N], value_length: Field) -> ([u8; 32], Field)
{
constrain value.len() as u8 >= value_length as u8;
let mut out_value = [0; 32];
if value_length == 0
{
let out = (out_value, value_length);
out
}
else { if value_length as u8 < 31
{
out_value[0] = 0x80 + value_length as u8;

for i in 1..value.len()
{
out_value[i] = value[i-1];
}

let out = (out_value, value_length + 1);

out
}
else
{
let out = (out_value, 32);
out
}
}
}

fn main(x: [u8; 5], z: Field)
{
//Issue 1144
let (nib, len) = compact_decode(x,z);
constrain len == 5;
constrain [nib[0], nib[1], nib[2], nib[3], nib[4]] == [15, 1, 12, 11, 8];


}

#[test]
// Issue 1144
fn test_1144()
{
main([0x3f, 0x1c, 0xb8, 0x99, 0xab], 3);
}

// Issue 1169
fn enc_test()
{
let val1 = [0xb8,0x8f,0x61,0xe6,0xfb,0xda,0x83,0xfb,0xff,0xfa,0xbe,0x36,0x41,0x12,0x13,0x74,0x80,0x39,0x80,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00];
let val1_length = 20;

let enc_val1 = enc(val1,val1_length);

constrain enc_val1.0 == [0x94,0xb8,0x8f,0x61,0xe6,0xfb,0xda,0x83,0xfb,0xff,0xfa,0xbe,0x36,0x41,0x12,0x13,0x74,0x80,0x39,0x80,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00];
constrain enc_val1.1 == 21;
}
1 change: 1 addition & 0 deletions crates/noirc_evaluator/src/ssa/ssa_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ impl IrGenerator {
self.context.get_current_block_mut().left = Some(exit_block);

//Exit block plumbing
let block2 = self.context.current_block;
self.context.current_block = exit_block;
self.context.get_current_block_mut().predecessor.push(block2);
ssa_form::seal_block(&mut self.context, exit_block, entry_block);
Expand Down

0 comments on commit 7628ed6

Please sign in to comment.