Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update for plonky2 #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ anyhow = "1.0.71"
hex = "0.4.3"
bitvec = "1"
rayon = "1.7.0"
plonky2 = {git="https://github.com/InternetMaximalism/plonky2", rev="541e127"}
plonky2_u32={git="https://github.com/InternetMaximalism/plonky2", rev="541e127"}
plonky2_ecdsa={git="https://github.com/InternetMaximalism/plonky2", rev="541e127"}
starky = {git="https://github.com/InternetMaximalism/plonky2", rev="541e127"}
plonky2-bn254={git="https://github.com/qope/plonky2-bn254.git", rev="d616d57"}
starky-bn254={git="http://github.com/qope/starky-bn254", rev="2165be0"}
plonky2 = "0.2.2"
plonky2-bn254 = { git = "https://github.com/Lagrange-Labs/plonky2-bn254" }
plonky2_ecdsa = { git = "https://github.com/Lagrange-Labs/plonky2-ecdsa" }

[patch.crates-io]
plonky2 = { git = "https://github.com/Lagrange-Labs/plonky2", branch = "upstream" }
plonky2_field = { git = "https://github.com/Lagrange-Labs/plonky2", branch = "upstream" }
3 changes: 1 addition & 2 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[toolchain]
channel = "nightly-2023-06-15"
nightly
3 changes: 1 addition & 2 deletions src/final_exp_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,9 @@ mod tests {
use ark_ff::Field;
use ark_std::UniformRand;
use num_bigint::BigUint;
use starky_bn254::utils::biguint_to_bits;

use crate::miller_loop_native::{miller_loop_native, multi_miller_loop_native};
use plonky2_bn254::fields::debug_tools::print_ark_fq;
use plonky2_bn254::{fields::debug_tools::print_ark_fq, utils::biguint_to_bits};

use super::{final_exp_native, pow_native, BN_X};

Expand Down
51 changes: 10 additions & 41 deletions src/final_exp_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use plonky2::{
};

use plonky2_bn254::fields::{fq12_target::Fq12Target, fq2_target::Fq2Target};
use starky_bn254::{circuits::fq12_exp_u64_circuit, input_target::Fq12ExpU64InputTarget};

use crate::final_exp_native::{frob_coeffs, BN_X};

Expand Down Expand Up @@ -75,53 +74,31 @@ where
{
let offset = Fq12Target::constant(builder, Fq12::one());
let exp_val = builder.constant(F::from_canonical_u64(BN_X));
let mut exp_inputs = vec![];
let mut exp_outputs = vec![];

let mp = frobenius_map(builder, m, 1);
let mp2 = frobenius_map(builder, m, 2);
let mp3 = frobenius_map(builder, m, 3);

let mp2_mp3 = mp2.mul(builder, &mp3);
let y0 = mp.mul(builder, &mp2_mp3);
let y1 = m.confugate(builder);
let y0: Fq12Target<F, D> = mp.mul(builder, &mp2_mp3);
let y1 = m.conjugate(builder);

// let mx = pow(builder, m, BN_X);
let mx = Fq12Target::empty(builder);
exp_inputs.push(Fq12ExpU64InputTarget {
x: m.clone(),
offset: offset.clone(),
exp_val,
});
exp_outputs.push(mx.clone());
let mx = m.pow(builder, &offset, exp_val);

let mxp = frobenius_map(builder, &mx, 1);
// let mx2 = pow(builder, &mx, BN_X);
let mx2 = Fq12Target::empty(builder);
exp_inputs.push(Fq12ExpU64InputTarget {
x: mx.clone(),
offset: offset.clone(),
exp_val,
});
exp_outputs.push(mx2.clone());
let mx2 = mx.pow(builder, &offset, exp_val);
let mx2p = frobenius_map(builder, &mx2, 1);
let y2 = frobenius_map(builder, &mx2, 2);
let y5 = mx2.confugate(builder);
// let mx3 = pow(builder, &mx2, BN_X);
let mx3 = Fq12Target::empty(builder);
exp_inputs.push(Fq12ExpU64InputTarget {
x: mx2.clone(),
offset,
exp_val,
});
exp_outputs.push(mx3.clone());
let y5 = mx2.conjugate(builder);
let mx3 = mx2.pow(builder, &offset, exp_val);
let mx3p = frobenius_map(builder, &mx3, 1);

let y3 = mxp.confugate(builder);
let y3 = mxp.conjugate(builder);
let mx_mx2p = mx.mul(builder, &mx2p);
let y4 = mx_mx2p.confugate(builder);
let y4 = mx_mx2p.conjugate(builder);
let mx3_mx3p = mx3.mul(builder, &mx3p);
let y6 = mx3_mx3p.confugate(builder);
let y6 = mx3_mx3p.conjugate(builder);

let mut T0 = y6.mul(builder, &y6);
T0 = T0.mul(builder, &y4);
Expand All @@ -138,22 +115,14 @@ where
T0 = T0.mul(builder, &T0);
T0 = T0.mul(builder, &T1);

let exp_outputs2 = fq12_exp_u64_circuit::<F, C, D>(builder, &exp_inputs);
exp_outputs
.iter()
.zip(exp_outputs2.iter())
.for_each(|(a, b)| {
Fq12Target::connect(builder, a, b);
});

T0
}

fn easy_part<F: RichField + Extendable<D>, const D: usize>(
builder: &mut CircuitBuilder<F, D>,
a: &Fq12Target<F, D>,
) -> Fq12Target<F, D> {
let f1 = a.confugate(builder);
let f1 = a.conjugate(builder);
let f2 = f1.div(builder, &a);
let f3 = frobenius_map(builder, &f2, 2);
let f = f3.mul(builder, &f2);
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(generic_const_exprs)]

pub mod final_exp_native;
pub mod final_exp_target;
pub mod miller_loop_native;
Expand Down
Loading