mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-11 02:03:07 +00:00
names and comments
This commit is contained in:
parent
56be7317e0
commit
6958d46c56
@ -1,7 +1,5 @@
|
||||
use std::ops::Add;
|
||||
|
||||
use ethereum_types::U256;
|
||||
|
||||
use crate::bn254_arithmetic::{gen_fp, gen_fp2, Fp, Fp12, Fp2, Fp6, UNIT_FP12, ZERO_FP, ZERO_FP2};
|
||||
|
||||
// The curve consists of pairs (x, y): (Fp, Fp) | y^2 = x^3 + 2
|
||||
|
||||
@ -37,7 +37,7 @@ custom_powers:
|
||||
// stack: val, retdest {200: y0, 212: y2, 224: y4}
|
||||
%stack () -> (200, 236, make_term_1)
|
||||
// stack: 200, 236, make_term_1, val, retdest {200: y0, 212: y2, 224: y4}
|
||||
%jump(inv_fp12)
|
||||
%jump(inv_fp254_12)
|
||||
make_term_1:
|
||||
// stack: val, retdest {212: y2, 224: y4, 236: y0^-1}
|
||||
%stack () -> (212, 224, 224, make_term_2)
|
||||
|
||||
@ -20,7 +20,7 @@ global make_invariant:
|
||||
// stack: out, retdest {out: y}
|
||||
%stack (out) -> (out, 100, first_exp, out)
|
||||
// stack: out, 100, first_exp, out, retdest {out: y}
|
||||
%jump(inv_fp12)
|
||||
%jump(inv_fp254_12)
|
||||
global first_exp:
|
||||
// stack: out, retdest {out: y , 100: y^-1}
|
||||
%frob_fp12_6
|
||||
|
||||
@ -3,13 +3,13 @@
|
||||
// Returns y * (x^-1) where the inverse is taken modulo N
|
||||
%macro divfp254
|
||||
// stack: x , y
|
||||
%inverse
|
||||
%inv_fp254
|
||||
// stack: x^-1, y
|
||||
MULFP254
|
||||
%endmacro
|
||||
|
||||
// Non-deterministically provide the inverse modulo N.
|
||||
%macro inverse
|
||||
%macro inv_fp254
|
||||
// stack: x
|
||||
PROVER_INPUT(ff::bn254_base::inverse)
|
||||
// stack: x^-1 , x
|
||||
@ -22,38 +22,18 @@
|
||||
%endmacro
|
||||
|
||||
|
||||
global inv_fp12:
|
||||
// stack: ptr, inv, retdest
|
||||
%prover_inv_fp12
|
||||
// stack: f^-1, ptr, inv, retdest
|
||||
global inv_fp254_12:
|
||||
// stack: inp, out, retdest
|
||||
%prover_inv_fp254_12
|
||||
// stack: f^-1, inp, out, retdest
|
||||
DUP14
|
||||
// stack: inv, f^-1, ptr, inv, retdest
|
||||
// stack: out, f^-1, inp, out, retdest
|
||||
%store_fp12
|
||||
// stack: ptr, inv, retdest
|
||||
%stack (ptr, inv) -> (ptr, inv, 50, check_inv)
|
||||
// stack: ptr, inv, 50, check_inv, retdest
|
||||
// stack: inp, out, retdest
|
||||
%stack (inp, out) -> (inp, out, 50, check_inv_fp254_12)
|
||||
// stack: inp, out, 50, check_inv_fp254_12, retdest
|
||||
%jump(mul_fp12)
|
||||
|
||||
global inv_fp12_old:
|
||||
// stack: ptr, inv, retdest
|
||||
DUP1 %load_fp12
|
||||
// stack: f, ptr, inv, retdest
|
||||
DUP14
|
||||
// stack: inv, f, ptr, inv, retdest
|
||||
%prover_inv_fp12
|
||||
// stack: f^-1, inv, f, ptr, inv, retdest
|
||||
DUP13 %store_fp12
|
||||
// stack: inv, f, ptr, inv, retdest
|
||||
POP %pop4 %pop4 %pop4
|
||||
// stack: ptr, inv, retdest
|
||||
PUSH 50 PUSH check_inv
|
||||
// stack: check_inv, 50, ptr, inv, retdest
|
||||
%stack (check_inv, mem, ptr, inv) -> (ptr, inv, mem, check_inv)
|
||||
// stack: ptr, inv, 50, check_inv, retdest
|
||||
%jump(mul_fp12)
|
||||
|
||||
|
||||
global check_inv:
|
||||
check_inv_fp254_12:
|
||||
// stack: retdest
|
||||
PUSH 50
|
||||
%load_fp12
|
||||
@ -62,7 +42,7 @@ global check_inv:
|
||||
// stack: retdest
|
||||
JUMP
|
||||
|
||||
%macro prover_inv_fp12
|
||||
%macro prover_inv_fp254_12
|
||||
PROVER_INPUT(ffe::bn254_base::component_11)
|
||||
PROVER_INPUT(ffe::bn254_base::component_10)
|
||||
PROVER_INPUT(ffe::bn254_base::component_9)
|
||||
@ -76,18 +56,3 @@ global check_inv:
|
||||
PROVER_INPUT(ffe::bn254_base::component_1)
|
||||
PROVER_INPUT(ffe::bn254_base::component_0)
|
||||
%endmacro
|
||||
|
||||
%macro assert_eq_unit_fp12
|
||||
%assert_eq_const(1)
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%endmacro
|
||||
|
||||
@ -1070,3 +1070,18 @@
|
||||
// stack: ind11', x11, ptr'
|
||||
%mstore_kernel_general
|
||||
%endmacro
|
||||
|
||||
%macro assert_eq_unit_fp12
|
||||
%assert_eq_const(1)
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%assert_zero
|
||||
%endmacro
|
||||
|
||||
@ -53,7 +53,7 @@ ecrecover_valid_input:
|
||||
// stack: y, hash, r, s, retdest
|
||||
DUP3
|
||||
// stack: r, y, hash, x, s, retdest (r=x)
|
||||
%inverse_secp_scalar
|
||||
%inv_fp254_secp_scalar
|
||||
// stack: r^(-1), y, hash, x, s, retdest
|
||||
DUP1
|
||||
// stack: r^(-1), r^(-1), y, hash, x, s, retdest
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
// Returns y * (x^-1) where the inverse is taken modulo N
|
||||
%macro moddiv_secp_base
|
||||
// stack: x, y
|
||||
%inverse_secp_base
|
||||
%inv_fp254_secp_base
|
||||
// stack: x^-1, y
|
||||
%mulmodn_secp_base
|
||||
%endmacro
|
||||
|
||||
@ -147,13 +147,13 @@ fn test_frob_fp12() -> Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inv_fp12() -> Result<()> {
|
||||
fn test_inv_fp254_12() -> Result<()> {
|
||||
let ptr: usize = 100;
|
||||
let inv: usize = 112;
|
||||
let f: Fp12 = gen_fp12();
|
||||
|
||||
let setup = InterpreterSetup {
|
||||
label: "inv_fp12".to_string(),
|
||||
label: "inv_fp254_12".to_string(),
|
||||
stack: vec![U256::from(ptr), U256::from(inv), U256::from(0xdeadbeefu32)],
|
||||
memory: vec![(ptr, fp12_on_stack(f))],
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user