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
  • 12 exp

12 exp · Changes

Page history
fix: exp circuit constraints update --story=1 authored Feb 20, 2024 by on_my_way's avatar on_my_way
Show whitespace changes
Inline Side-by-side
Showing with 8 additions and 17 deletions
+8 -17
  • zkevm-docs/12-exp.markdown zkevm-docs/12-exp.markdown +8 -17
  • No files found.
zkevm-docs/12-exp.markdown
View page @ ad5810a2
...@@ -58,8 +58,6 @@ pub struct ExpCircuitConfig<F: Field> { ...@@ -58,8 +58,6 @@ pub struct ExpCircuitConfig<F: Field> {
pub count_is_zero: IsZeroWithRotationConfig<F>, pub count_is_zero: IsZeroWithRotationConfig<F>,
/// for chip to determine whether count is 128 /// for chip to determine whether count is 128
pub count_is_128: IsZeroConfig<F>, pub count_is_128: IsZeroConfig<F>,
/// for chip to determine whether count is 256
pub count_is_256: IsZeroConfig<F>,
/// arithmetic table for lookup /// arithmetic table for lookup
arithmetic_table: ArithmeticTable, arithmetic_table: ArithmeticTable,
} }
...@@ -72,27 +70,23 @@ pub struct ExpCircuitConfig<F: Field> { ...@@ -72,27 +70,23 @@ pub struct ExpCircuitConfig<F: Field> {
pub fn from_operands( pub fn from_operands(
base: U256, base: U256,
index: U256, index: U256,
) -> (U256, Vec<Self>, Vec<arithmetic::Row>, Vec<arithmetic::Row>) ) -> (U256, Vec<Self>, Vec<arithmetic::Row>)
``` ```
- 入参: base为底数,index为指数 - 入参: base为底数,index为指数
- 返回参数: exp运算结果,exp生成witness row 数组(exp rows),使用的乘法电路运算生成的witness row(mul rows),使用的加法电路运算生成的witness row(add rows) - 返回参数: exp运算结果,exp生成witness row 数组(exp rows),使用的乘法电路运算生成的witness row(mul rows)
- 算法: - 算法:
- 生成Tag::Zero 行,将其添加到exp rows中 - 生成Tag::Zero 行,将其添加到exp rows中
- 若index == 0,则直接返回 - 若index == 0,则直接返回
- 生成Tag::One 行, 将其添加到exp rows中 - 生成Tag::One 行, 将其添加到exp rows中
- 循环对 div 做2的除法和取模运算,记商为div,余数为rem - 循环对 div 做2的除法和取模运算,记商为div,余数为rem
- 生成Tag::Bit0/Tag::Bit1 Row;其中count = (exp rows中的前一行的row)的count, is_high = (exp rows中的前一行的row)的is_high - 生成Tag::Bit0/Tag::Bit1 Row;其中count = (exp rows中的前一行的row)的count
- 若rem == 0 , 则生成Tag::Bit0 Row,将其添加到exp rows中;其中index hi/lo = (exp rows中的两行前的row)的 index hi/lo;power hi/lo = (exp rows中的两行前的row)的 power hi/lo - 若rem == 0 , 则生成Tag::Bit0 Row,将其添加到exp rows中;其中index hi/lo = (exp rows中的两行前的row)的 index hi/lo;power hi/lo = (exp rows中的两行前的row)的 power hi/lo
- 若rem == 1 , 则生成Tag::Bit1 Row,将其添加到exp rows中;其中index hi/lo = (exp rows中的两行前的row)的 index hi/lo + (exp rows中的前一行的row)的index hi/lo, 调用加法电路生成add row,将其添加到add rows中;power hi/lo = (exp rows中的两行前的row)的 power hi/lo * (exp rows中的前一行的row)的 power hi/lo,调用乘法电路生成mul row,将其添加到mul rows中 - 若rem == 1 , 则生成Tag::Bit1 Row,将其添加到exp rows中;其中index hi/lo = (exp rows中的两行前的row)的 index hi/lo + (exp rows中的前一行的row)的index hi/lo;power hi/lo = (exp rows中的两行前的row)的 power hi/lo * (exp rows中的前一行的row)的 power hi/lo,调用乘法电路生成mul row,将其添加到mul rows中
- 若div == 0, 则中断循环 - 若div == 0, 则中断循环
- 否则: - 否则:
- 生成Tag::SQUARE Row,将其添加到exp rows中;其中index hi/lo = (exp rows中的两行前的row)的 index hi/lo * 2 ,调用乘法电路生成mul row,将其添加到mul rows中;power hi/lo = (exp rows中的两行前的row)的 power hi/lo 的平方,调用乘法电路生成mul row,将其添加到mul rows中;count = (exp rows中的前一行的row)的count + 1; - 生成Tag::SQUARE Row,将其添加到exp rows中;count = (exp rows中的前一行的row)的count + 1;若count = 128,则index hi = 1; index lo = 0; 若count <> 128,则index hi/lo = (exp rows中的两行前的row)的 index hi/lo * 2 ;power hi/lo = (exp rows中的两行前的row)的 power hi/lo 的平方,调用乘法电路生成mul row,将其添加到mul rows中;
- 若count == 0 ,则is_high = 0 - 去exp rows中最后一行的power hi/lo, 将power hi << 128 + power lo作为最终的power value, return (power value,exp rows, mul rows)
- 若count == 128 ,则is_high = 1
- 否则 is_high = (exp rows中的两行前的row)的is_high
- 去exp rows中最后一行的power hi/lo, 将power hi << 128 + power lo作为最终的power value, return (power value,exp rows, mul rows, add rows)
## 门约束 ## 门约束
...@@ -117,16 +111,13 @@ pub struct ExpCircuitConfig<F: Field> { ...@@ -117,16 +111,13 @@ pub struct ExpCircuitConfig<F: Field> {
- 若当前行的Tag为ONE,则index为1,power为BASE(底数) - 若当前行的Tag为ONE,则index为1,power为BASE(底数)
- 若当前行的Tag为Bit0,则index等于前两行index,power等于前两行的power - 若当前行的Tag为Bit0,则index等于前两行index,power等于前两行的power
- 若当前行的Tag为SQUARE,且count为128,则index hi为1,index lo为0 - 若当前行的Tag为SQUARE,且count为128,则index hi为1,index lo为0
- 若当前行的Tag为SQUARE,且count不等于128,则index hi/lo 等于两行前的index hi/lo * 2
- 若当前行的Tag为Bit1,则index hi/lo 等于两行前的 index hi/lo 与 前一行的 index hi/lo 之和
## Lookup约束 ## Lookup约束
### Tag为SQUARE,Index运算lookup
若Tag为SQUARE时,index 等于两行前的index * 2
### Tag为SQUARE,Power运算lookup ### Tag为SQUARE,Power运算lookup
若Tag为SQUARE时,power为两行前的power的平方 若Tag为SQUARE时,power为两行前的power的平方
### Tag为Bit1,Index运算lookup
若Tag为Bit1,index为两行前的index + 一行前的index
### Tag为Bit1,Power运算lookup ### Tag为Bit1,Power运算lookup
若Tag为Bit1,power为两行前的power * 一行前的power 若Tag为Bit1,power为两行前的power * 一行前的power
\ No newline at end of file
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号