diff --git a/evm/src/cpu/kernel/asm/curve_add.asm b/evm/src/cpu/kernel/asm/curve_add.asm index 00e88495..779f3b7c 100644 --- a/evm/src/cpu/kernel/asm/curve_add.asm +++ b/evm/src/cpu/kernel/asm/curve_add.asm @@ -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 diff --git a/evm/src/cpu/kernel/asm/curve_mul.asm b/evm/src/cpu/kernel/asm/curve_mul.asm index 3a3253e4..bd092571 100644 --- a/evm/src/cpu/kernel/asm/curve_mul.asm +++ b/evm/src/cpu/kernel/asm/curve_mul.asm @@ -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