... | ... | @@ -52,12 +52,9 @@ cnt=1,vers[16]~vers[23]的位置用来存进栈顶的值stack_push。 |
|
|
### 门约束
|
|
|
1. Auxiliary字段约束(state_stamp、stack_pointer、log_stamp、read_only)
|
|
|
2. Stack Value约束(tag、state_stamp、 call_id、stack_pointer、is_write)
|
|
|
3. lookup_value约束:lookup_stack_pop_b = stack_top0(栈顶的值需要和lookup_stack_pop_b相等)
|
|
|
4. lookup_value约束:lookup_stack_pop_a = stack_top1 (弹出一个值后,栈顶的值需要和lookup_stack_pop_a相等)
|
|
|
5. lookup_value约束:lookup_stack_push = stack_top1(存进一个值后,栈顶的元素需要和lookup_stack_push相等)
|
|
|
6. lookup_value约束:arithmetic_operand_b = lookup_stack_pop_b,arithmetic_operand_a = lookup_stack_pop_a,arithmetic_operand_push = lookup_stack_push(这里对三个操作数的hi,lo进行约束,需要和state lookup里的值相等)
|
|
|
7. 当前的OPCODE=ADD
|
|
|
8. arithmetic tag = ADD
|
|
|
3. lookup_value约束:arithmetic_operand_b = lookup_stack_pop_b,arithmetic_operand_a = lookup_stack_pop_a,arithmetic_operand_push = lookup_stack_push(这里对三个操作数的hi,lo进行约束,需要和state lookup里的值相等)
|
|
|
4. 当前的OPCODE=ADD
|
|
|
5. arithmetic tag = ADD
|
|
|
|
|
|
参考如下代码:
|
|
|
|
... | ... | @@ -106,47 +103,11 @@ fn get_constraints( |
|
|
|
|
|
### LookUp约束
|
|
|
|
|
|
cnt=2的vers[0]~vers[8]的位置用来存放操作数的信息。
|
|
|
|
|
|
来源:core
|
|
|
|
|
|
去向:arithmetic
|
|
|
|
|
|
参考代码如下:
|
|
|
|
|
|
|
|
|
```Rust
|
|
|
fn gen_witness(&self, trace: &GethExecStep, current_state: &mut WitnessExecHelper) -> Witness {
|
|
|
assert_eq!(trace.op, OpcodeId::ADD);
|
|
|
let (stack_pop_a, a) = current_state.get_pop_stack_row_value(&trace);
|
|
|
let (stack_pop_b, b) = current_state.get_pop_stack_row_value(&trace);
|
|
|
let (arithmetic, result) = operation::add::gen_witness(vec![a, b]);
|
|
|
|
|
|
let stack_push = current_state.get_push_stack_row(trace, result[0]);
|
|
|
let mut core_row_2 = current_state.get_core_row_without_versatile(&trace, 2);
|
|
|
core_row_2.insert_arithmetic_lookup(&arithmetic);
|
|
|
let mut core_row_1 = current_state.get_core_row_without_versatile(&trace, 1);
|
|
|
core_row_1.insert_state_lookups([&stack_pop_a, &stack_pop_b, &stack_push]);
|
|
|
let core_row_0 = ExecutionState::ADD.into_exec_state_core_row(
|
|
|
trace,
|
|
|
current_state,
|
|
|
NUM_STATE_HI_COL,
|
|
|
NUM_STATE_LO_COL,
|
|
|
);
|
|
|
|
|
|
Witness {
|
|
|
core: vec![core_row_2, core_row_1, core_row_0],
|
|
|
state: vec![stack_pop_b, stack_pop_a, stack_push],
|
|
|
arithmetic,
|
|
|
..Default::default()
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
|
|
|
#### get_lookups
|
|
|
|
|
|
这里的lookup类型为LookupEntry::State和LookupEntry::Arithmetic。
|
|
|
|
|
|
这里的四个lookup, 类型为LookupEntry::State和LookupEntry::Arithmetic, 具体可以参考Witness Core Row部分的说明。
|
|
|
|
|
|
参考代码如下:
|
|
|
|
... | ... | |