Working ecmul

This commit is contained in:
wborgeaud 2022-07-05 21:12:11 +02:00
parent 006b74f4dc
commit fb8a67b0d9
3 changed files with 21 additions and 13 deletions

View File

@ -10,8 +10,8 @@ pub(crate) fn combined_kernel() -> Kernel {
let files = vec![ let files = vec![
include_str!("asm/basic_macros.asm"), include_str!("asm/basic_macros.asm"),
// include_str!("asm/exp.asm"), // include_str!("asm/exp.asm"),
include_str!("asm/curve_mul.asm"),
include_str!("asm/curve_add.asm"), include_str!("asm/curve_add.asm"),
// include_str!("asm/curve_mul.asm"),
include_str!("asm/moddiv.asm"), include_str!("asm/moddiv.asm"),
// include_str!("asm/storage_read.asm"), // include_str!("asm/storage_read.asm"),
// include_str!("asm/storage_write.asm"), // include_str!("asm/storage_write.asm"),

View File

@ -1,10 +1,10 @@
// #define N 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47 // BN254 base field order // #define N 0x30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47 // BN254 base field order
global ec_add: global ec_add:
PUSH 2 //PUSH 2
PUSH 1 //PUSH 1
PUSH 0 //PUSH 0x1bf9384aa3f0b3ad763aee81940cacdde1af71617c06f46e11510f14f3d5d121
PUSH 0 //PUSH 0xe7313274bb29566ff0c8220eb9841de1d96c2923c6a4028f7dd3c6a14cee770
JUMPDEST JUMPDEST
// stack: x0, y0, x1, y1, retdest // stack: x0, y0, x1, y1, retdest
DUP2 DUP2
@ -250,13 +250,15 @@ ec_add_valid_points_with_lambda:
SWAP1 SWAP1
// stack: lambda * (x1 - x2), y1, x2, lambda, x0, y0, x1, y1, retdest // stack: lambda * (x1 - x2), y1, x2, lambda, x0, y0, x1, y1, retdest
%submod %submod
// stack: y2, x2, x0, y0, x1, y1, retdest // stack: y2, x2, lambda, x0, y0, x1, y1, retdest
SWAP4 SWAP5
// stack: x1, x2, x0, y0, y2, y1, retdest // stack: x1, x2, lambda, x0, y0, y2, y1, retdest
POP POP
// stack: x2, x0, y0, y2, y1, retdest // stack: x2, lambda, x0, y0, y2, y1, retdest
SWAP4 SWAP5
// stack: y1, x0, y0, y2, x2, retdest // stack: y1, lambda, x0, y0, y2, x2, retdest
POP
// stack: lambda, x0, y0, y2, x2, retdest
POP POP
// stack: x0, y0, y2, x2, retdest // stack: x0, y0, y2, x2, retdest
POP POP
@ -267,6 +269,7 @@ ec_add_valid_points_with_lambda:
// stack: retdest, x2, y2 // stack: retdest, x2, y2
JUMP JUMP
// Assumption: (x0,y0) and (x1,y1) are valid points and x0 == x1
ec_add_equal_first_coord: ec_add_equal_first_coord:
JUMPDEST JUMPDEST
// stack: x0, y0, x1, y1, retdest with x0 == x1 // stack: x0, y0, x1, y1, retdest with x0 == x1

View File

@ -1,4 +1,9 @@
global ec_mul: global ec_mul:
// Uncomment for test inputs.
// PUSH 0xdeadbeef
// PUSH 0xd
// PUSH 2
// PUSH 1
JUMPDEST JUMPDEST
// stack: x, y, s, retdest // stack: x, y, s, retdest
DUP2 DUP2
@ -110,6 +115,6 @@ recursion_return:
odd_scalar: odd_scalar:
JUMPDEST JUMPDEST
// stack: x', y', x, y, retdest // stack: x', y', x, y, retdest
PUSH ec_add_valid_points PUSH ec_add
// stack: ec_add_valid_points, x', y', x, y, retdest // stack: ec_add, x', y', x, y, retdest
JUMP JUMP