Skip to content

Commit

Permalink
fix: hoist constraints on inputs to top of program (#4076)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Followup to #4065 

## Summary\*

This PR fixes a small mistake in #4065. I mixed up the front and back of
the vector for the case where we don't find an instruction for which the
constraint's inputs are a result. This results in constraints on the
program inputs not being pushed up to the beginning of the program.

This PR fixes the index to insert these instructions so that we
constrain the inputs first.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench committed Jan 18, 2024
1 parent 66f5cdd commit 447aa34
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Ssa {
// We iterate through the previous instructions in reverse order so the index is from the
// back of the vector. Subtract from vector length to get correct index.
.map(|reversed_index| filtered_instructions.len() - reversed_index)
.unwrap_or(filtered_instructions.len());
.unwrap_or(0);

filtered_instructions.insert(index, instruction);
}
Expand Down
2 changes: 2 additions & 0 deletions test_programs/execution_success/bit_and/Prover.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
x = "0x00"
y = "0x10"
a = "0x00"
b = "0x10"
8 changes: 4 additions & 4 deletions test_programs/execution_success/bit_and/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// You can only do bit operations with integers.
// (Kobi/Daira/Circom/#37) https://github.com/iden3/circom/issues/37
fn main(x: Field, y: Field) {
fn main(x: Field, y: Field, a: Field, b: Field) {
let x_as_u8 = x as u8;
let y_as_u8 = y as u8;

Expand All @@ -9,8 +9,8 @@ fn main(x: Field, y: Field) {
let flag = (x == 0) & (y == 16);
assert(flag);
//bitwise and with odd bits:
let x_as_u11 = x as u11;
let y_as_u11 = y as u11;
assert((x_as_u11 & y_as_u11) == x_as_u11);
let a_as_u8 = a as u8;
let b_as_u8 = b as u8;
assert((a_as_u8 & b_as_u8) == a_as_u8);
}

0 comments on commit 447aa34

Please sign in to comment.