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
  • memory chunk

Last edited by gzxu Aug 07, 2024
Page history
This is an old version of this page. You can view the most recent version or browse the history.

memory chunk

memory chunk

memory_chunk 是 auxiliary 中的一个变量,保存了当前 opcode 执行完成之后,memory 的 byte size。与之对应的是常用的 memory_chunk_prev,指的是opcode 执行之前的数值,通常通过读取上一opcode的auxiliary获取。

trace 打印出来,memory 有多少行,memory chunk 就是多少。由于 EVM 生成的 trace 的 memory 是执行前,所以使用preprocess_trace 这个函数,统一处理成,每个 trace step 对应的 memory 是执行之后的。

约束实现

  1. 首先需要计算出访问到的内存段的右区间 offset_bound = offset + size。

  2. 使用 memory_expansion 比较 offset_bound 和 memory_chunk_prev,得出当前是否有内存拓展 expansion_tag,和 access_memory_size。

  3. 跟据上述计算,可以计算出当前步骤执行完之后 memory 的正确数值 memory_chunk_to,那么在get_auxiliary_constraints 传入相关的delta memory_chunk: ExpressionOutcome::To(memory_chunk_to)进行约束。

call 时的 context 转换

因为 call 同时对memory进行两次 access,所以需要两次 memory_expansion,上下文转换和 stack_pointer 类似,不赘述。

需要注意的是 memory_chunk 在call_4 才计算完 memory_expansion 。所以在 current_state 这里跳过前几步的 memory_chunk 更新。

let memory_chunk = match self {
            ExecutionState::CALL_1 | ExecutionState::CALL_2 | ExecutionState::CALL_3 => {
                current_state.memory_chunk_prev
            }
            _ => current_state.memory_chunk,
        };
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号