Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
zkevm-circuits
zkevm-circuits
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

新注册的用户请输入邮箱并保存,随后登录邮箱激活账号。后续可直接使用邮箱登录!

  • zkp
  • zkevm-circuitszkevm-circuits
  • Wiki
    • Zkevm docs
  • 9 bitwise

9 bitwise · Changes

Page history
update bitwise authored 11 months ago by xiaoranlu's avatar xiaoranlu
Show whitespace changes
Inline Side-by-side
Showing with 17 additions and 5 deletions
+17 -5
  • zkevm-docs/9-bitwise.markdown zkevm-docs/9-bitwise.markdown +17 -5
  • No files found.
zkevm-docs/9-bitwise.markdown
View page @ ea2be830
......@@ -26,6 +26,8 @@ pub struct Row {
pub sum_2: U256,
/// The counter for one operation
pub cnt: U256,
/// Operand 2 most significant byte index
pub index: U256,
}
pub enum Tag {
......@@ -59,8 +61,12 @@ pub struct BitwiseCircuitConfig<F: Field> {
pub sum_2: Column<Advice>,
/// The counter for one operation
pub cnt: Column<Advice>,
/// Index of the most significant byte
pub index: Column<Advice>,
/// IsZero chip for column cnt
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> {
`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
| tag | byte_0 | byte_1 | byte_2 | acc_0 | acc_1 | acc_2 | sum_2 | cnt |
| ---- | ------ | ------ | ------ | -------- | -------- | -------- | ----- | ---- |
| And | 0xab | 0xaa | 0xaa | 0xab | 0xaa | 0xaa | 0xaa | 0 |
| And | 0xcd | 0xbb | 0x89 | 0xabcd | 0xaabb | 0xaa89 | 0x133 | 1 |
| And | 0xef | 0xcc | 0xcc | 0xabcdef | 0xaabbcc | 0xaa89cc | 0x1ff | 2 |
| 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 | 16 |
| And | 0xcd | 0xbb | 0x89 | 0xabcd | 0xaabb | 0xaa89 | 0x133 | 1 | 16 |
| And | 0xef | 0xcc | 0xcc | 0xabcdef | 0xaabbcc | 0xaa89cc | 0x1ff | 2 | 16 |
### 门约束
......@@ -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,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
### LookUp约束
......
Clone repository
  • basics
    • evm
    • halo2
  • code notes
    • binary_number_with_real_selector
    • how to use macro
    • simple_lt
    • simple_lt_word
  • Home
  • image
  • zkevm docs
    • 1 introduction
    • 10 public
    • 11 fixed
    • 12 exp
    • 13 keccak
    • 14 comparisons
    • 15 differences
View All Pages

Copyright © 2024 ChainWeaver Org. All Rights Reserved. 版权所有。

京ICP备2023035722号-3

京公网安备 11010802044225号