Skip to content

Commit

Permalink
fix fp6 arithmetic (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColoCarletti authored Sep 7, 2023
1 parent 31057fb commit 526dbee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion precompiles/Playground.yul
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ object "Playground" {
let tmp8, tmp9 := fp2Sub(a00, a01, a10, a11)
tmp0, tmp1 := fp2Add(tmp8, tmp9, a20, a21)

let tmp10, tmp11 := fp2Mul(a00, a01, a20, a21)
let tmp10, tmp11 := fp2Mul(a10, a11, a20, a21)
tmp2, tmp3 := fp2Add(tmp10, tmp11, tmp10, tmp11)
tmp0, tmp1 := fp2Mul(tmp0, tmp1, tmp0, tmp1)

Expand Down
18 changes: 9 additions & 9 deletions scripts/fp6.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def square(a_00, a_01, a_10, a_11, a_20, a_21):
c2 = fp2.sub(*c4, *c5)
c3 = fp2.exp(a_00, a_01, 2)
c4 = fp2.add(*fp2.sub(a_00, a_01, a_10, a_11), a_20, a_21)
c5 = fp2.scalar_mul(*fp2.mul(a_00, a_01, a_20, a_21), monty.TWO)
c5 = fp2.scalar_mul(*fp2.mul(a_10, a_11, a_20, a_21), monty.TWO)
c4 = fp2.exp(*c4, 2)
c0 = fp2.add(*fp2.mul_by_xi(*c5), *c3)
c2 = fp2.sub(*fp2.add(*fp2.add(*c2, *c4), *c5), *c3)
Expand Down Expand Up @@ -125,14 +125,14 @@ def main():

# INVERSE
fp6_inversed = inv(*fp2_a_0, *fp2_a_1, *fp2_a_2)
fp6_zero = mul(*fp2_a_0, *fp2_a_1, *fp2_a_2, *fp6_inversed)

assert(fp6_zero[0] == monty.ONE)
assert(fp6_zero[1] == 0)
assert(fp6_zero[2] == 0)
assert(fp6_zero[3] == 0)
assert(fp6_zero[4] == 0)
assert(fp6_zero[5] == 0)
fp6_one = mul(*fp2_a_0, *fp2_a_1, *fp2_a_2, *fp6_inversed)

assert(fp6_one[0] == monty.ONE)
assert(fp6_one[1] == 0)
assert(fp6_one[2] == 0)
assert(fp6_one[3] == 0)
assert(fp6_one[4] == 0)
assert(fp6_one[5] == 0)

if __name__ == '__main__':
main()

0 comments on commit 526dbee

Please sign in to comment.