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
  • 13 keccak

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

13 keccak

本项目使用开源的Keccak子电路,链接:https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/b8ae7af639af035a6ad5081716012ee2ea48e7cb/zkevm-circuits/src/keccak_circuit.rs,版本为commit:

commit b8ae7af639af035a6ad5081716012ee2ea48e7cb
Author: Eduard S <eduardsanou@posteo.net>
Date:   Thu May 4 16:35:02 2023 +0200

    Update halo2 dependency to v2023_04_20 (#1374)

本文主要介绍开源代码如何使用,如何接入。

Keccak 电路简介

在 https://github.com/privacy-scaling-explorations/zkevm-circuits 的 Keccak 子电路用于证明一个输入字节串和输入的 Keccak 哈希之间的对应关系。在其他电路里,需要使用三个变量(input_rlc, input_len, output_rlc)向 Keccak 子电路进行查表(lookup),以验证这三个变量的对应关系。具体的输入和哈希的计算由 Keccak 内部实现,本项目不做改动。

RLC(随机线性组合,Random Linear Combination)计算 RLC 需要使用随机值 Challenge。

zkevm中的使用

在某电路(例如 Core 电路)中,如果需要验证 Keccak 哈希,首先由此电路负责将输入的 RLC、哈希的 RLC 算好,然后将输入的 RLC、哈希的 RLC、输入的长度这三个变量(input_rlc, input_len, output_rlc)向 Keccak 子电路进行查表lookup。

计算 RLC 可以由一个 RLC 子电路实现,也可以由 Copy 子电路直接实现。子电路需要提供 Challenge,由更新后的 SubCircuit 接口的 synthesize 函数提供。

开源代码接入

导入 Keccak 子电路代码:

  • 将 keccak_circuit.rs 和其子目录中的代码接入此项目。
  • 将其依赖的其他工具类代码也接入进来。

将 Keccak 子电路接入 SuperCircuit:

  • 将 Keccak 子电路集成到 SuperCircuit 中。
  • 确保 SuperCircuit 能够调用 Keccak 子电路并进行相应的查表操作。

好处

通过对 Witness 中的 Bytecode 计算哈希,并检查是否与 code hash 一致,可以验证 Bytecode 的正确性。这样,Bytecode 子电路的所有列可以不用公开了,只需公开 code hash。

本项目的更新

在原有设计中,output_rlc 表示 Keccak 哈希值的随机线性组合。为了更好地处理哈希值,代码进行了改动,将 output_rlc 拆分为 output_hi 和 output_lo,分别表示哈希值的高 128 位和低 128 位。

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号