... | @@ -26,6 +26,8 @@ pub struct Row { |
... | @@ -26,6 +26,8 @@ pub struct Row { |
|
pub sum_2: U256,
|
|
pub sum_2: U256,
|
|
/// The counter for one operation
|
|
/// The counter for one operation
|
|
pub cnt: U256,
|
|
pub cnt: U256,
|
|
|
|
/// Operand 2 most significant byte index
|
|
|
|
pub index: U256,
|
|
}
|
|
}
|
|
|
|
|
|
pub enum Tag {
|
|
pub enum Tag {
|
... | @@ -59,8 +61,12 @@ pub struct BitwiseCircuitConfig<F: Field> { |
... | @@ -59,8 +61,12 @@ pub struct BitwiseCircuitConfig<F: Field> { |
|
pub sum_2: Column<Advice>,
|
|
pub sum_2: Column<Advice>,
|
|
/// The counter for one operation
|
|
/// The counter for one operation
|
|
pub cnt: Column<Advice>,
|
|
pub cnt: Column<Advice>,
|
|
|
|
/// Index of the most significant byte
|
|
|
|
pub index: Column<Advice>,
|
|
/// IsZero chip for column cnt
|
|
/// IsZero chip for column cnt
|
|
pub cnt_is_zero: IsZeroWithRotationConfig<F>,
|
|
pub cnt_is_zero: IsZeroWithRotationConfig<F>,
|
|
|
|
/// acc_2 is zero flag
|
|
|
|
pub acc_2_is_zero: IsZeroWithRotationConfig<F>,
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
... | @@ -70,13 +76,15 @@ pub struct BitwiseCircuitConfig<F: Field> { |
... | @@ -70,13 +76,15 @@ pub struct BitwiseCircuitConfig<F: Field> { |
|
|
|
|
|
`byte_0`和`byte_1`分别是两个数值的某一个位置上的byte,`byte_2`为`byte_0`和`byte_1`的运算结果,`acc_0`、`acc_1`、`acc_2`分别是`byte_0`、`byte_1`、`byte_2`的累加值,即`acc=byte+acc_pre*256`,`sum_2`为`byte_2`的累加和,即`sum=byte+sum_pre`。
|
|
`byte_0`和`byte_1`分别是两个数值的某一个位置上的byte,`byte_2`为`byte_0`和`byte_1`的运算结果,`acc_0`、`acc_1`、`acc_2`分别是`byte_0`、`byte_1`、`byte_2`的累加值,即`acc=byte+acc_pre*256`,`sum_2`为`byte_2`的累加和,即`sum=byte+sum_pre`。
|
|
|
|
|
|
|
|
`index`用于表示最高有效字节数,在`cnt==0`时,如果`acc_2`为0,`index = 0`,否则`index = 16`;对于`cnt != 0 `的行,当`acc_2`从0值变为非0值时,`index = 16-cnt`,否则`index = prev_index`。
|
|
|
|
|
|
例如:0xabcdef AND 0xaabbcc
|
|
例如:0xabcdef AND 0xaabbcc
|
|
|
|
|
|
| tag | byte_0 | byte_1 | byte_2 | acc_0 | acc_1 | acc_2 | sum_2 | cnt |
|
|
| tag | byte_0 | byte_1 | byte_2 | acc_0 | acc_1 | acc_2 | sum_2 | cnt | index |
|
|
| ---- | ------ | ------ | ------ | -------- | -------- | -------- | ----- | ---- |
|
|
| ---- | ------ | ------ | ------ | -------- | -------- | -------- | ----- | ---- | ----- |
|
|
| And | 0xab | 0xaa | 0xaa | 0xab | 0xaa | 0xaa | 0xaa | 0 |
|
|
| And | 0xab | 0xaa | 0xaa | 0xab | 0xaa | 0xaa | 0xaa | 0 | 16 |
|
|
| And | 0xcd | 0xbb | 0x89 | 0xabcd | 0xaabb | 0xaa89 | 0x133 | 1 |
|
|
| And | 0xcd | 0xbb | 0x89 | 0xabcd | 0xaabb | 0xaa89 | 0x133 | 1 | 16 |
|
|
| And | 0xef | 0xcc | 0xcc | 0xabcdef | 0xaabbcc | 0xaa89cc | 0x1ff | 2 |
|
|
| And | 0xef | 0xcc | 0xcc | 0xabcdef | 0xaabbcc | 0xaa89cc | 0x1ff | 2 | 16 |
|
|
|
|
|
|
### 门约束
|
|
### 门约束
|
|
|
|
|
... | @@ -86,6 +94,10 @@ pub struct BitwiseCircuitConfig<F: Field> { |
... | @@ -86,6 +94,10 @@ pub struct BitwiseCircuitConfig<F: Field> { |
|
- tag_is_not_nil,cnt != 0 ---> `acc_0=byte_0+acc_0_pre*256`,`acc_1=byte_1+acc_1_pre*256`,`acc_2=acc_2_pre*256`, `sum_2=byte_2+sum2_pre`,`cnt=cnt_pre+1`,`tag=tag_pre`
|
|
- tag_is_not_nil,cnt != 0 ---> `acc_0=byte_0+acc_0_pre*256`,`acc_1=byte_1+acc_1_pre*256`,`acc_2=acc_2_pre*256`, `sum_2=byte_2+sum2_pre`,`cnt=cnt_pre+1`,`tag=tag_pre`
|
|
- tag_is_not_nil,next_cnt=0 --> cnt=15
|
|
- tag_is_not_nil,next_cnt=0 --> cnt=15
|
|
|
|
|
|
|
|
- tag_is_not_nil, cnt == 0 ==> index = 16 or 0
|
|
|
|
|
|
|
|
- tag_is_not_nil, cnt != 0 ==> index = index_prev or index = 16 - cnt
|
|
|
|
|
|
- tag_is_nil ---> byte_0=0, byte_1=0, byte_2=0, acc_0=0, acc_1=0, acc_2=0, sum_2=0, cnt=0
|
|
- tag_is_nil ---> byte_0=0, byte_1=0, byte_2=0, acc_0=0, acc_1=0, acc_2=0, sum_2=0, cnt=0
|
|
|
|
|
|
### LookUp约束
|
|
### LookUp约束
|
... | | ... | |