... | ... | @@ -145,8 +145,31 @@ constraints |
|
|
```
|
|
|
|
|
|
- Addmod
|
|
|
|
|
|
- Mulmod
|
|
|
|
|
|
- Normallength
|
|
|
|
|
|
输入:length,offset,data_size
|
|
|
|
|
|
输出:normal_length, zero_length
|
|
|
|
|
|
计算方式:
|
|
|
|
|
|
以codecopy为例,length:为要copy的长度,offset为bytecode偏移量(即复制起始位置),data_size为bytecode的总长度
|
|
|
|
|
|
```rust
|
|
|
fn normal_length(length: u64, offset: u64, data_size: u64) -> (normal_length: u64, zero_length: u64) {
|
|
|
if offset > data_size {
|
|
|
return 0, length
|
|
|
} else if offset + length < data_size {
|
|
|
return length,0
|
|
|
}else{
|
|
|
return data_size-offset, offset+length - data_size
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
# 实现 arithmetic 子电路中 Add 例子
|
|
|
|
|
|
如果我们希望为某一个 tag 实现它的约束,我们需要实现 OperationGadget trait,然后在 config 方法中实现相应 tag 的约束就好。具体如下所示
|
... | ... | |