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 log

core log · Changes

Page history
update core-log authored May 29, 2024 by xiaoranlu's avatar xiaoranlu
Hide whitespace changes
Inline Side-by-side
Showing with 85 additions and 3 deletions
+85 -3
  • zkevm-docs/4-core/core-log.markdown zkevm-docs/4-core/core-log.markdown +85 -3
  • No files found.
zkevm-docs/4-core/core-log.markdown
View page @ 5a8ee13f
......@@ -14,26 +14,68 @@
**LOG0**
```
flowchart LR
LogBytes --> LogTopicNumAddr
LogBytes --> MEMORY_GAS --> LOG_GAS --> LogTopicNumAddr
```
**LOG1-LOG4**
```
flowchart LR
LogBytes --> LogTopicNumAddr --> LogTopic:topic0 --> LogTopic:topic1 --> ...
LogBytes --> MEMORY_GAS --> LOG_GAS --> LogTopicNumAddr --> LogTopic:topic0 --> LogTopic:topic1 --> ...
```
- LogBytes: 处理Log数据拷贝(Copy Lookup Memory->PublicLog)和数据长度记录(Public Lookup)
- Memory_gas 计算Log操作需要的memory gas花费;
- Log_gas: 计算Log操作最终的gas花费;
- LogTopicNumAddr: 处理Log数据地址(Public Lookup)
- LogTopic: 处理每一个TopicHash处理(Public Lookup)
主要约束及状态变化
![image.png](/uploads/2/64EF98D7F40D429E87C2F64F206269E5/image.png)
LOG0为例:
| 指令 | 状态 | State参数 | 约束 | gen witness 状态变化 |
| ---- | --------------- | ------------- | ------------------------------------------------------------ | --------------------------------- |
| LOG0 | LogBytes | state1=offset | state_stamp = pre + 2 | |
| | | state2=length | log_stamp = pre | |
| | | | next_pc = pc | |
| | | | | |
| | memory_gas | | memory_gas = GasCost::MEMORY_EXPANSION_LINEAR_COEFF.expr() * (next_word_size - memory_chunk_prev) * (next_quad_memory_cost - curr_quad_memory_cost) | |
| | | | | |
| | log_gas | | gas_cost = memory_gas_cost + GasCost::LOG.expr() + topic_gas + length * GasCost::LOG_DATA_GAS.expr() | |
| | | | | |
| | LogTopicNumAddr | - | state_stamp = pre | 根据opcode 切换值state.topic_left |
| | | | log_stamp = pre + (1*topic_left_0) | topic_left==0时log_stamp+1 |
| | | | next_pc = pc + (1*topic_left_0) | |
LOG1为例:
| 指令 | 状态 | State参数 | 约束 | gen witness 状态变化 |
| ---- | --------------- | --------------------- | ------------------------------------------------------------ | -------------------------------- |
| LOG1 | LogBytes | state1=offset | state_stamp = pre + 2 log_ | |
| | | state2=length | stamp = pre | |
| | | | next_pc = pc | |
| | | | | |
| | memory_gas | | memory_gas = GasCost::MEMORY_EXPANSION_LINEAR_COEFF.expr() * (next_word_size - memory_chunk_prev) * (next_quad_memory_cost - curr_quad_memory_cost) | |
| | | | | |
| | log_gas | | gas_cost = memory_gas_cost + GasCost::LOG.expr() + topic_gas + length * GasCost::LOG_DATA_GAS.expr() | |
| | | | | |
| | | | | |
| | LogTopicNumAddr | - | state_stamp = pre | 根据opcode切换值state.topic_left |
| | | | log_stamp = pre + (1*topic_left_0) | topic_left==0时log_stamp+1 |
| | | | next_pc = pc | |
| | | | | |
| | LogTopic | state1=cur_topic_hash | state_stamp = pre+1 | state.topic_left -=1 |
| | | | log_stamp = pre + (1*topic_left_0) | topic_left==0时log_stamp+1 |
## 具体Gadget设计
### LogBytesGadget设计
处理memory[offset:offset+length],数据从Memory拷贝到PulbicLog
......@@ -85,7 +127,47 @@ gen_witness状态变化
|---| ---
|1| len_lo_inv |
### MEMORY_GAS
| cnt | | | | | | | |
| ---- | ---------------------- | ------------- | -------------- | ---------------- | ------------------- | --------------------------- | ----------------------------- |
| 1 | MEMORY_EXPANSION(2..6) | U64DIV(7..11) | U64DIV(12..16) | SELECTOR(17..30) | | | |
| 0 | DYNAMIC(0..17) | AUX(18..24) | | MEMORY_GAS(26) | NEXT_IS_LOG_GAS(29) | NEXT_IS_PURE_MEMORY_GAS(30) | NEXT_IS_MEMORY_COPIER_GAS(31) |
主要约束:
- memory_gas = GasCost::MEMORY_EXPANSION_LINEAR_COEFF.expr() * (next_word_size - memory_chunk_prev) * (next_quad_memory_cost - curr_quad_memory_cost)
- next_word_size = (new_memory_size + 31) / 32,new_memory_size是通过stack中的offset+length;
- next_quad_memory_cost = next_word_size * next_word_size / 512;
cnt = 0行:
- 预留vers_26为计算出的memory_gas,提供给下一个状态使用,vers_29, vers_30, vers_31 为下一个状态约束需要的条件。
cnt = 1行:
- MEMORY_EXPANSION为`Max(cur_memory_size, memory_size)`
- 第一个U64Div为 `cur_memory_size * cur_memory_size / 512 = curr_quad_memory_cost`
- 第二个U64Div为 `next_memory_size * next_memory_size / 512 = next_quad_memory_cost`
- SELECTOR为opcode选择器。
### LOG_GAS
| cnt | | |
| ---- | -------------- | --------------- |
| 1 | U64OVERFLOW | SELECTOR(7..11) |
| 0 | DYNAMIC(0..17) | AUX(18..24) |
主要约束:
- gas_cost = memory_gas_cost + GasCost::LOG.expr() + topic_gas + length * GasCost::LOG_DATA_GAS.expr(),其中:
- topic_gas = n * GasCost::LOG.expr(), n为LOG_n;
- length 为 stack中的参数;
cnt = 1 行:
- U64OVERFLOW 为gas_left u64的约束;
- SELECTOR为LOG0-4的选择器。
### LogTopicNumAddrGadget设计
......
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号