... | ... | @@ -190,7 +190,7 @@ a * b + c = d |
|
|
5. 取余结果值约束
|
|
|
为了保证mul乘法的有效当b==0时,我们设置d==a.(d是余数,b是除数)。但是在eth中计算取余时有b==0时,我们设置d==0.所以在core circuit部分我们需要增加b=0时d==0
|
|
|
|
|
|
```
|
|
|
```
|
|
|
|
|
|
## AddMod
|
|
|
|
... | ... | @@ -288,6 +288,38 @@ carry_2 = (t4 + (t5 << 64) + carry_1).saturating_sub(d_lo) >> 128 |
|
|
|
|
|
|
|
|
|
|
|
### layout
|
|
|
|
|
|
| cnt | o_0_hi | o_0_lo | o_1_hi | o_1_lo | u16s_0 |
|
|
|
| ---- | ------------------- | ------------------- | -------------- | -------------- | ------------------------ |
|
|
|
| 26 | | | | | k2n_carry_0 |
|
|
|
| 25 | | | | | k2n_carry_1 |
|
|
|
| 24 | | | | | k2n_carry_2 |
|
|
|
| 23 | | | | | r_lo_u16s |
|
|
|
| 22 | | | | | r_hi_u16s |
|
|
|
| 21 | | | | | k2_lo_u16s |
|
|
|
| 20 | | k2n_carry_2 | k2n_carry_1 | k2n_carry_0 | k2_hi_u16s |
|
|
|
| 19 | r_diff_hi | r_diff_lo | r_lt_hi | r_lt_lo | r_diff_lo_u16s |
|
|
|
| 18 | k2_hi | k2_lo | | | r_diff_hi_u16s |
|
|
|
| 17 | | | | | arb_carry_0 |
|
|
|
| 16 | | | | | arb_carry_1 |
|
|
|
| 15 | | | | | arb_carry_2 |
|
|
|
| 14 | | | | | d_lo_u16s |
|
|
|
| 13 | | | | | d_hi_u16s |
|
|
|
| 12 | | | | | e_lo_u16s |
|
|
|
| 11 | | | | | e_hi_u16s |
|
|
|
| 10 | | arb_carry_2 | arb_carry_1 | arb_carry_0 | b_lo_u16s |
|
|
|
| 9 | e_hi | e_lo | d_hi | d_lo | b_hi_u16s |
|
|
|
| 8 | | | | | a_remainder_diff_lo_u16s |
|
|
|
| 7 | | | | | a_remainder_diff_hi_u16s |
|
|
|
| 6 | | | | | a_rem_carry_lo_u16s |
|
|
|
| 5 | | | | | a_remainder_lo_u16s |
|
|
|
| 4 | a_remainder_diff_hi | a_remainder_diff_lo | a_rem_lt_hi | a_rem_lt_lo | a_remainder_hi_u16s |
|
|
|
| 3 | k1_carry_hi | k1_carry_lo | | | n_lo_u16s |
|
|
|
| 2 | k1_hi | k1_lo | a_remainder_hi | a_remainder_lo | n_hi_u16s |
|
|
|
| 1 | n_hi | n_lo | r_hi | r_lo | k1_lo_u16s |
|
|
|
| 0 | a_hi | a_lo | b_hi | b_lo | k1_hi_u16s |
|
|
|
|
|
|
## Length
|
|
|
|
|
|
arithmetic中的布局:
|
... | ... | |