Add zero case for mul

This commit is contained in:
wborgeaud 2022-07-05 21:22:05 +02:00
parent fb8a67b0d9
commit 8ffd25c127
2 changed files with 39 additions and 4 deletions

View File

@ -1,10 +1,12 @@
// #define N 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47 // BN254 base field order
global ec_add:
//PUSH 2
//PUSH 1
//PUSH 0x1bf9384aa3f0b3ad763aee81940cacdde1af71617c06f46e11510f14f3d5d121
//PUSH 0xe7313274bb29566ff0c8220eb9841de1d96c2923c6a4028f7dd3c6a14cee770
// Uncomment for test inputs.
// PUSH 0xdeadbeef
// PUSH 2
// PUSH 1
// PUSH 0x1bf9384aa3f0b3ad763aee81940cacdde1af71617c06f46e11510f14f3d5d121
// PUSH 0xe7313274bb29566ff0c8220eb9841de1d96c2923c6a4028f7dd3c6a14cee770
JUMPDEST
// stack: x0, y0, x1, y1, retdest
DUP2

View File

@ -10,6 +10,22 @@ global ec_mul:
// stack: y, x, y, s, retdest
DUP2
// stack: x, y, x, y, s, retdest
ISZERO
// stack: x==0, y, x, y, s, retdest
SWAP1
// stack: y, x==0, x, y, s, retdest
ISZERO
// stack: y==0, x==0, x, y, s, retdest
AND
// stack: y==0 & x==0, x, y, s, retdest
PUSH ret_zero
// stack: ret_zero, y==0 & x==0, x, y, s, retdest
JUMPI
// stack: x, y, s, retdest
DUP2
// stack: y, x, y, s, retdest
DUP2
// stack: x, y, x, y, s, retdest
%ec_check
// stack: isValid(x, y), x, y, s, retdest
PUSH ec_mul_valid_point
@ -118,3 +134,20 @@ odd_scalar:
PUSH ec_add
// stack: ec_add, x', y', x, y, retdest
JUMP
ret_zero:
JUMPDEST
// stack: x, y, s, retdest
POP
// stack: y, s, retdest
POP
// stack: s, retdest
POP
// stack: retdest
PUSH 0
// stack: 0, retdest
PUSH 0
// stack: 0, 0, retdest
SWAP2
// stack: retdest, 0, 0
JUMP