Add debug expr in EVMConstraintBuilder#1500
Conversation
Introduce the `debug_expression` method to the `EVMConstraintBuilder` which allows specifying an expression inside an ExecutionGadget to be evaluated and printed during assignment.
e77e7d7 to
ae37c38
Compare
ChihChengLiang
left a comment
There was a problem hiding this comment.
LGTM. I tried it locally, and it works!
KimiWu123
left a comment
There was a problem hiding this comment.
Awesome! LGTM, only one nit.
| // Set to true when we're assigning the next step before the current step to have | ||
| // next step assignments for evaluation of the stored expressions in current step that | ||
| // depend on the next step. | ||
| is_next: bool, |
There was a problem hiding this comment.
Will is_final or is_final_step be better? Or has_next if final_step is not accurate. I understand to use is as prefix while it's a bool type but in this case is_next is not clear to know what it really means.
There was a problem hiding this comment.
I think is_final or has_next doesn't hold the real meaning here. Let me explain why I call this is_next. Each step is assigned two times. The list of steps is iterated in a window of size 2 where we have (current_step, next_step), and we assign the next first and the current afterwards in each iteration. See https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/b6be48943f203374ad1d734a52bc66754529de68/zkevm-circuits/src/evm_circuit/execution.rs#L1180-L1206
So if we have the steps [a, b, c] we pair them like (cur=a, next=b), (cur=b, next=c), (cur=c, next=None). And we do the following assignments:
- b (next)
- a (cur)
- b (cur)
- c (next)
- c (cur)
So here the is_next means that we're assigning the next step before we assign the current steps for it's "side effects", but we'll go over and assign that step again later.
Do you have another suggestion instead of is_next that conveys this meaning?
There was a problem hiding this comment.
Thanks for your explanation, is_next makes sense to me now. :)
There was a problem hiding this comment.
This is nice proposed! Have try to use it and work like a charm!
Just have 2 suggestion
- can use
&'static strtype instead ofString(as I understand it took extra heap copy) . - swap first and second parameter of
debug_expression(name, expr), as we used to havenamego first
Here is commit bc7a15d which apply above change. Feel free to cherry-pick it :)
Thanks for the suggestions! I've swapped the argument order so that name goes first. cb.debug_expression("tx_id", tx_id.expr());
```rust
or dynamic Stringcb.debug_expression(format!("limb{}", i), word.limbs[i].expr()); |
hero78119
left a comment
There was a problem hiding this comment.
Thanks for address the reviews! Into<String> make sense to preserve more flexibility in debug purpose 👍
Description
Introduce the
debug_expressionmethod to theEVMConstraintBuilderwhich allows specifying an expression inside an ExecutionGadget to be evaluated and printed during assignment.This can be very useful for debugging. With this we can print the value of cells, but also of arbitrary expressions. For example, it allows printing the evaluation of all the expressions used in a lookup (previous to the RLC).
Type of change
Contents
When calling
cb.debug_expression, the expression is stored in theEVMConstraintBuilderalong with a string. Later on, at assignment, whenever a step is assigned to anExecutionStatethat had some debug expressions specified, those expressions will be evaluated and printed.Example usage
In the
PushGadget::configuremethod I include the following line:Then I run the a test that assigns this state (with
--nocaptureto see the stdout):And I will get the following: