Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
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
    • 4 core
  • core addmod

core addmod · Changes

Page history
docs: update the core addmod section --story=1018296 authored Jul 26, 2024 by chenxuanhui's avatar chenxuanhui
Hide whitespace changes
Inline Side-by-side
Showing with 27 additions and 5 deletions
+27 -5
  • zkevm-docs/4-core/core-addmod.markdown zkevm-docs/4-core/core-addmod.markdown +27 -5
  • No files found.
zkevm-docs/4-core/core-addmod.markdown
View page @ ff76e4dd
......@@ -24,6 +24,28 @@ PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
ADDMOD
```
由于在evm中`ADDMOD`指令会自动从栈中弹出三个操作数并将结果推入栈中,所以在trace中没有显式的`POP`操作。
示例具体操作流程如下:
**初始状态**:
- 栈内容:`[a, b, n]`
- 其中,`a` 和 `b` 是要进行加法的256位整数,`n` 是取模的值。`a` 在栈顶,`b` 在栈顶下方,`n` 在栈底。
**操作步骤**:
1. **弹出值**:从栈中弹出三个值 `a`, `b`, 和 `n`。此时栈变为空。
2. 计算:
- 执行加法操作:`sum = a + b`
- 对结果 `sum` 进行取模操作:`result = sum % n`
- 这个操作确保结果始终保持在 `n` 范围内。
3. **推入结果**:将计算得到的结果 `result` 推入栈中。
**最终状态**:
- 栈内容:`[result]`
### Witness Core Row
core row中的表格设计如下:
......@@ -31,7 +53,7 @@ core row中的表格设计如下:
| cnt | ver[0-7] | ver[8-15] | ver[16-23] | ver[24-31] | 其他 |
| ---- | ------------------- | ------------------- | ------------------- | ------------------ | ---- |
| 2 | ARITH | - | - | - | - |
| 1 | STATE (stack_pop_n) | STATE (stack_pop_b) | STATE (stack_pop_a) | STATE (stack_push) | - |
| 1 | STATE (stack_pop_a) | STATE (stack_pop_b) | STATE (stack_pop_n) | STATE (stack_push) | - |
| 0 | DYNA_SELECTOR | AUX | - | - | - |
cnt=2,vers[0]~vers[8]的位置用来存放arithmetic table lookup;
......@@ -94,9 +116,9 @@ cnt=1,vers[24]~vers[31]的位置用来存进栈顶的值stack_push。
这些约束确保算术操作数和栈操作的值一致。具体来说:
- `arithmetic_operand_n = lookup_stack_pop_n`
- `arithmetic_operand_b = lookup_stack_pop_b`
- `arithmetic_operand_a = lookup_stack_pop_a`
- `arithmetic_operand_b = lookup_stack_pop_b`
- `arithmetic_operand_n = lookup_stack_pop_n`
- `arithmetic_operand_push = lookup_stack_push`
这些约束对操作数的高位 (`hi`) 和低位 (`lo`) 进行约束,并确保它们与状态查找中的值相等。
......@@ -170,9 +192,9 @@ fn get_lookups(
let stack_lookup_3 = query_expression(meta, |meta| config.get_state_lookup(meta, 3));
let arithmetic = query_expression(meta, |meta| config.get_arithmetic_lookup(meta));
vec![
("stack pop n".into(), stack_lookup_0),
("stack pop a".into(), stack_lookup_0),
("stack pop b".into(), stack_lookup_1),
("stack pop a".into(), stack_lookup_2),
("stack pop n".into(), stack_lookup_2),
("stack push".into(), stack_lookup_3),
("arithmetic lookup".into(), arithmetic),
]
......
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号