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
  • 8 arithmetic

8 arithmetic · Changes

Page history
feat: add slt_sgt doc authored Dec 26, 2023 by liuxingxing1's avatar liuxingxing1
Show whitespace changes
Inline Side-by-side
Showing with 9 additions and 9 deletions
+9 -9
  • zkevm-docs/8-arithmetic.markdown zkevm-docs/8-arithmetic.markdown +9 -9
  • No files found.
zkevm-docs/8-arithmetic.markdown
View page @ 28663843
...@@ -69,9 +69,10 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b ...@@ -69,9 +69,10 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b
- 注意:carry_hi=1 等价于 a<b; carry_hi=0 等价于 a>=b - 注意:carry_hi=1 等价于 a<b; carry_hi=0 等价于 a>=b
- Div_Mod (a\*b+c=d 同时约束 c 小于 b) - Div_Mod (a\*b+c=d 同时约束 c 小于 b)
```
if tag is div, (a,b,c,d) = (push, pop2, pop1 - push \* pop2, pop1) if tag is div, (a,b,c,d) = (push, pop2, pop1 - push \* pop2, pop1)
if tag is mod, (a,b,c,d) = (if pop2 is zero{0}else{pop1/pop2},pop2,if pop2 is zero{pop1}else{push},pop1) if tag is mod, (a,b,c,d) = (if pop2 is zero{0}else{pop1/pop2},pop2,if pop2 is zero{pop1}else{push},pop1)
define
- define t0 = a0 \* b0 - define t0 = a0 \* b0
- define t1 = a0 \* b1 + a1 \* b0 - define t1 = a0 \* b1 + a1 \* b0
- define t2 = a0 \* b2 + a2 \* b0 + a1 \* b1 - define t2 = a0 \* b2 + a2 \* b0 + a1 \* b1
...@@ -80,8 +81,7 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b ...@@ -80,8 +81,7 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b
- define t_hi=(t2)+(t3)\*2^64 - define t_hi=(t2)+(t3)\*2^64
- define carry_lo = (t0 + (t1 << 64) + c_lo).saturating_sub(d_lo) >> 128 - define carry_lo = (t0 + (t1 << 64) + c_lo).saturating_sub(d_lo) >> 128
- define carry_hi = (t2 + (t3 << 64) + c_hi + carry_lo).saturating_sub(d_hi) >> 128 - define carry_hi = (t2 + (t3 << 64) + c_hi + carry_lo).saturating_sub(d_hi) >> 128
```
- constraint
- 如果是 0 行,约束 num_row is 8,并且约束 cnt 自增的有效性 - 如果是 0 行,约束 num_row is 8,并且约束 cnt 自增的有效性
- a_lo = u16 sum(rotation cur) - a_lo = u16 sum(rotation cur)
- a_hi = u16 sum(rotation -1) - a_hi = u16 sum(rotation -1)
...@@ -96,6 +96,8 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b ...@@ -96,6 +96,8 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b
- residue < divisor when divisor != 0 - residue < divisor when divisor != 0
- carry_hi == 0 - carry_hi == 0
- Mul(需要 6 行对 a,b,c lookup ) 其中 operand0 是 a,operand1 是 b - Mul(需要 6 行对 a,b,c lookup ) 其中 operand0 是 a,operand1 是 b
- define t0 = a0 \* b0 - define t0 = a0 \* b0
...@@ -116,8 +118,8 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b ...@@ -116,8 +118,8 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b
- (t_lo-car_lo\*2^128) -(c_lo) - (t_lo-car_lo\*2^128) -(c_lo)
- (t_hi+car_lo-car_hi\*2^128)- (c_hi) - (t_hi+car_lo-car_hi\*2^128)- (c_hi)
- Slt_Sgt (我们使用 a-b=c 的公式来约束有相同符号的内容)
- Slt_Sgt (我们使用 a-b=c 的公式来约束有相同符号的内容)
- 比较最高u16位确定a,b符号。同时我们需要约束a_hi和b_hi等于对应的u16s_sum - 比较最高u16位确定a,b符号。同时我们需要约束a_hi和b_hi等于对应的u16s_sum
- 不相等时。(a_lt - b_lt)作为不相等condition, - 不相等时。(a_lt - b_lt)作为不相等condition,
- 当 a_lt == 1 时 carry == 0。a_lt == 0时,carry=1.所以有约束 1-(a_lt + carry_hi) - 当 a_lt == 1 时 carry == 0。a_lt == 0时,carry=1.所以有约束 1-(a_lt + carry_hi)
...@@ -132,10 +134,10 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b ...@@ -132,10 +134,10 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b
- b_hi + carry_hi \* 2^128 - carry_lo= a_hi + c_hi - b_hi + carry_hi \* 2^128 - carry_lo= a_hi + c_hi
- 注意:carry_hi=1 等价于 a<b; carry_hi=0 等价于 a>=b - 注意:carry_hi=1 等价于 a<b; carry_hi=0 等价于 a>=b
- Sdiv_Smod(这里我们还是使用 a\*b+c=d 的公式来进行核心约束,值的关注的是对有符号的数进行操作,我们需要运用到补码的知识。) - Sdiv_Smod(这里我们还是使用 a\*b+c=d 的公式来进行核心约束,值的关注的是对有符号的数进行操作,我们需要运用到补码的知识。)
对有符号整数进行计算时。所有的输入值都由 core circuit 传递。我们在这里约束传递值如下 对有符号整数进行计算时。所有的输入值都由 core circuit 传递。我们在这里约束传递值如下
```
```
if tag is sdiv if tag is sdiv
- a = push - a = push
- b = pop2 - b = pop2
...@@ -146,15 +148,13 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b ...@@ -146,15 +148,13 @@ operand* 用来存放算术中的参数值,如 a+b=c+overflow 指令中的 a,b
- b = pop2 - b = pop2
- c = if pop2.is_zero() { pop1 } else { push } - c = if pop2.is_zero() { pop1 } else { push }
- d = pop1 - d = pop1
```
constraints
- a_abs,b_abs,c_abs,d_abs - a_abs,b_abs,c_abs,d_abs
- mul_add_words - mul_add_words
- c lt b - c lt b
- d is_signed_overflow - d is_signed_overflow
- a,b,c is zero - a,b,c is zero
```
- Addmod - Addmod
- Mulmod - Mulmod
......
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号