Skip to content

Commit

Permalink
fix: Dynamic assert messages in brillig (#4531)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Temporary regisers are not conserved when calling and returning from
another function, only alive variables are conserved. The condition in
an assert was computed before the call to the dynamic message handler so
it could be overwritten by the callee. I just compute the condition
after the potential call.

## Summary\*



## Additional Context



## Documentation\*

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

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
sirasistant authored Mar 12, 2024
1 parent b3fd24d commit e24d3fc
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,6 @@ impl<'block> BrilligBlock<'block> {
self.convert_ssa_binary(binary, dfg, result_var);
}
Instruction::Constrain(lhs, rhs, assert_message) => {
let condition = SingleAddrVariable {
address: self.brillig_context.allocate_register(),
bit_size: 1,
};

self.convert_ssa_binary(
&Binary { lhs: *lhs, rhs: *rhs, operator: BinaryOp::Eq },
dfg,
condition,
);

let assert_message = if let Some(error) = assert_message {
match error.as_ref() {
ConstrainError::Static(string) => Some(string.clone()),
Expand All @@ -282,6 +271,17 @@ impl<'block> BrilligBlock<'block> {
None
};

let condition = SingleAddrVariable {
address: self.brillig_context.allocate_register(),
bit_size: 1,
};

self.convert_ssa_binary(
&Binary { lhs: *lhs, rhs: *rhs, operator: BinaryOp::Eq },
dfg,
condition,
);

self.brillig_context.constrain_instruction(condition.address, assert_message);
self.brillig_context.deallocate_register(condition.address);
}
Expand Down

0 comments on commit e24d3fc

Please sign in to comment.