Skip to content

Commit

Permalink
wip: upgrade dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jan 31, 2024
1 parent c400ffc commit b45e327
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 46 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ members = [
"snark-verifier",
"snark-verifier-sdk"
]

[patch.crates-io]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }
halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.0" }

[patch."https://github.com/privacy-scaling-explorations/halo2wrong"]
halo2_wrong_ecc = { git = "https://www.github.com/privacy-scaling-explorations/halo2wrong", tag = "v2024_01_31", package = "ecc", optional = true}
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.69.0
1.75.0
6 changes: 3 additions & 3 deletions snark-verifier-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }
snark-verifier = { path = "../snark-verifier", default-features = false }

# system_halo2
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20" } # not optional for now
halo2curves = { git = 'https://github.com/privacy-scaling-explorations/halo2curves', tag = "0.3.2" } # must be same version as in halo2_proofs
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v0.3.0" } # not optional for now
halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.0" }

# loader_halo2
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20", package = "ecc", optional = true }
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2024_01_31", package = "ecc", optional = true }
poseidon = { git = "https://github.com/privacy-scaling-explorations/poseidon", tag = "v2023_04_20", optional = true }

# loader_evm
Expand Down
7 changes: 6 additions & 1 deletion snark-verifier-sdk/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use halo2_proofs::{
},
transcript::{TranscriptReadBuffer, TranscriptWriterBuffer},
};
use halo2curves::pairing::Engine;
use itertools::Itertools;
use rand::{rngs::StdRng, SeedableRng};
pub use snark_verifier::loader::evm::encode_calldata;
Expand Down Expand Up @@ -127,7 +128,11 @@ where
Rc<EvmLoader>,
VerifyingKey = KzgAsVerifyingKey,
Accumulator = KzgAccumulator<G1Affine, Rc<EvmLoader>>,
> + AccumulationDecider<G1Affine, Rc<EvmLoader>, DecidingKey = KzgDecidingKey<Bn256>>,
> + AccumulationDecider<
G1Affine,
Rc<EvmLoader>,
DecidingKey = KzgDecidingKey<Bn256, <Bn256 as Engine>::G1Affine>,
>,
{
let protocol = compile(
params,
Expand Down
8 changes: 4 additions & 4 deletions snark-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ num-integer = "0.1.45"
num-traits = "0.2.15"
rand = "0.8"
hex = "0.4"
halo2_curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "0.3.2", package = "halo2curves" }
halo2_curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.0", package = "halo2curves" }

# parallel
rayon = { version = "1.5.3", optional = true }

# system_halo2
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20", optional = true }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v0.3.0", optional = true }

# loader_evm
sha3 = { version = "0.10", optional = true }
revm = { version = "3.5.0", optional = true, default-features = false }

# loader_halo2
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20", package = "ecc", optional = true }
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2024_01_31", package = "ecc", optional = true }
poseidon = { git = "https://github.com/privacy-scaling-explorations/poseidon", tag = "v2023_04_20", optional = true }

# derive_serde
Expand All @@ -35,7 +35,7 @@ rand_chacha = "0.3.1"
paste = "1.0.7"

# system_halo2
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20", package = "ecc" }
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2024_01_31", package = "ecc" }

[features]
default = ["loader_evm", "loader_halo2", "system_halo2"]
Expand Down
8 changes: 5 additions & 3 deletions snark-verifier/src/pcs/kzg/accumulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub struct KzgAs<M, MOS>(PhantomData<(M, MOS)>);
impl<M, L, MOS> AccumulationScheme<M::G1Affine, L> for KzgAs<M, MOS>
where
M: MultiMillerLoop,
M::Scalar: PrimeField,
M::G1Affine: CurveAffine,
M::Fr: PrimeField,
L: Loader<M::G1Affine>,
MOS: Clone + Debug,
{
Expand Down Expand Up @@ -140,7 +141,8 @@ where
impl<M, MOS> AccumulationSchemeProver<M::G1Affine> for KzgAs<M, MOS>
where
M: MultiMillerLoop,
M::Scalar: PrimeField,
M::G1Affine: CurveAffine,
M::Fr: PrimeField,
MOS: Clone + Debug,
{
type ProvingKey = KzgAsProvingKey<M::G1Affine>;
Expand All @@ -165,7 +167,7 @@ where
let blind = pk
.zk()
.then(|| {
let s = M::Scalar::random(rng);
let s = M::Fr::random(rng);
let (g, s_g) = pk.0.unwrap();
let lhs = (s_g * s).to_affine();
let rhs = (g * s).to_affine();
Expand Down
45 changes: 34 additions & 11 deletions snark-verifier/src/pcs/kzg/decider.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use halo2_curves::CurveAffine;

use crate::{pcs::kzg::KzgSuccinctVerifyingKey, util::arithmetic::MultiMillerLoop};
use std::marker::PhantomData;

/// KZG deciding key.
#[derive(Debug, Clone, Copy)]
pub struct KzgDecidingKey<M: MultiMillerLoop> {
pub struct KzgDecidingKey<M: MultiMillerLoop, C: CurveAffine> {
/// KZG succinct verifying key.
pub svk: KzgSuccinctVerifyingKey<M::G1Affine>,
pub svk: KzgSuccinctVerifyingKey<C>,
/// Generator on G2.
pub g2: M::G2Affine,
/// Generator to the trusted-setup secret on G2.
pub s_g2: M::G2Affine,
_marker: PhantomData<M>,
}

impl<M: MultiMillerLoop> KzgDecidingKey<M> {
impl<C: CurveAffine, M: MultiMillerLoop<G1Affine = C>> KzgDecidingKey<M, C>
where
M::G1Affine: CurveAffine,
M::G2Affine: CurveAffine,
{
/// Initialize a [`KzgDecidingKey`]
pub fn new(
svk: impl Into<KzgSuccinctVerifyingKey<M::G1Affine>>,
Expand All @@ -29,19 +35,29 @@ impl<M: MultiMillerLoop> KzgDecidingKey<M> {
}
}

impl<M: MultiMillerLoop> From<(M::G1Affine, M::G2Affine, M::G2Affine)> for KzgDecidingKey<M> {
fn from((g1, g2, s_g2): (M::G1Affine, M::G2Affine, M::G2Affine)) -> KzgDecidingKey<M> {
impl<C: CurveAffine, M: MultiMillerLoop<G1Affine = C>> From<(M::G1Affine, M::G2Affine, M::G2Affine)>
for KzgDecidingKey<M, C>
where
M::G1Affine: CurveAffine,
M::G2Affine: CurveAffine,
{
fn from((g1, g2, s_g2): (M::G1Affine, M::G2Affine, M::G2Affine)) -> KzgDecidingKey<M, C> {
KzgDecidingKey::new(g1, g2, s_g2)
}
}

impl<M: MultiMillerLoop> AsRef<KzgSuccinctVerifyingKey<M::G1Affine>> for KzgDecidingKey<M> {
impl<C: CurveAffine, M: MultiMillerLoop<G1Affine = C>> AsRef<KzgSuccinctVerifyingKey<M::G1Affine>>
for KzgDecidingKey<M, C>
{
fn as_ref(&self) -> &KzgSuccinctVerifyingKey<M::G1Affine> {
&self.svk
}
}

mod native {

use halo2_curves::CurveAffine;

use crate::{
loader::native::NativeLoader,
pcs::{
Expand All @@ -59,10 +75,11 @@ mod native {
impl<M, MOS> AccumulationDecider<M::G1Affine, NativeLoader> for KzgAs<M, MOS>
where
M: MultiMillerLoop,
M::Scalar: PrimeField,
M::G1Affine: CurveAffine,
M::Fr: PrimeField,
MOS: Clone + Debug,
{
type DecidingKey = KzgDecidingKey<M>;
type DecidingKey = KzgDecidingKey<M, M::G1Affine>;

fn decide(
dk: &Self::DecidingKey,
Expand Down Expand Up @@ -113,10 +130,12 @@ mod evm {
impl<M, MOS> AccumulationDecider<M::G1Affine, Rc<EvmLoader>> for KzgAs<M, MOS>
where
M: MultiMillerLoop,
M::Scalar: PrimeField<Repr = [u8; 0x20]>,
M::G1Affine: CurveAffine,
M::G2Affine: CurveAffine,
<M::G1Affine as CurveAffine>::ScalarExt: PrimeField<Repr = [u8; 0x20]>,
MOS: Clone + Debug,
{
type DecidingKey = KzgDecidingKey<M>;
type DecidingKey = KzgDecidingKey<M, M::G1Affine>;

fn decide(
dk: &Self::DecidingKey,
Expand Down Expand Up @@ -162,7 +181,11 @@ mod evm {
loader.code_mut().runtime_append(code);
let challenge = loader.scalar(Value::Memory(challenge_ptr));

let powers_of_challenge = LoadedScalar::<M::Scalar>::powers(&challenge, lhs.len());
let powers_of_challenge =
LoadedScalar::<<M::G1Affine as CurveAffine>::ScalarExt>::powers(
&challenge,
lhs.len(),
);
let [lhs, rhs] = [lhs, rhs].map(|msms| {
msms.iter()
.zip(powers_of_challenge.iter())
Expand Down
15 changes: 9 additions & 6 deletions snark-verifier/src/pcs/kzg/multiopen/bdfg21.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use halo2_curves::group::prime::PrimeCurveAffine;

use crate::{
cost::{Cost, CostEstimation},
loader::{LoadedScalar, Loader, ScalarLoader},
Expand Down Expand Up @@ -27,7 +29,8 @@ pub struct Bdfg21;
impl<M, L> PolynomialCommitmentScheme<M::G1Affine, L> for KzgAs<M, Bdfg21>
where
M: MultiMillerLoop,
M::Scalar: PrimeField + Ord,
M::G1Affine: CurveAffine,
M::Fr: PrimeField + Ord,
L: Loader<M::G1Affine>,
{
type VerifyingKey = KzgSuccinctVerifyingKey<M::G1Affine>;
Expand All @@ -36,7 +39,7 @@ where

fn read_proof<T>(
_: &KzgSuccinctVerifyingKey<M::G1Affine>,
_: &[Query<M::Scalar>],
_: &[Query<<M::G1Affine as PrimeCurveAffine>::Scalar>],
transcript: &mut T,
) -> Result<Bdfg21Proof<M::G1Affine, L>, Error>
where
Expand All @@ -49,7 +52,7 @@ where
svk: &KzgSuccinctVerifyingKey<M::G1Affine>,
commitments: &[Msm<M::G1Affine, L>],
z: &L::LoadedScalar,
queries: &[Query<M::Scalar, L::LoadedScalar>],
queries: &[Query<<M::G1Affine as PrimeCurveAffine>::Scalar, L::LoadedScalar>],
proof: &Bdfg21Proof<M::G1Affine, L>,
) -> Result<Self::Output, Error> {
let sets = query_sets(queries);
Expand Down Expand Up @@ -370,11 +373,11 @@ where
impl<M> CostEstimation<M::G1Affine> for KzgAs<M, Bdfg21>
where
M: MultiMillerLoop,
M::Scalar: PrimeField,
M::Fr: PrimeField,
{
type Input = Vec<Query<M::Scalar>>;
type Input = Vec<Query<M::Fr>>;

fn estimate_cost(_: &Vec<Query<M::Scalar>>) -> Cost {
fn estimate_cost(_: &Vec<Query<M::Fr>>) -> Cost {
Cost {
num_commitment: 2,
num_msm: 2,
Expand Down
15 changes: 9 additions & 6 deletions snark-verifier/src/pcs/kzg/multiopen/gwc19.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use halo2_curves::group::prime::PrimeCurveAffine;

use crate::{
cost::{Cost, CostEstimation},
loader::{LoadedScalar, Loader},
Expand All @@ -23,7 +25,8 @@ pub struct Gwc19;
impl<M, L> PolynomialCommitmentScheme<M::G1Affine, L> for KzgAs<M, Gwc19>
where
M: MultiMillerLoop,
M::Scalar: PrimeField,
M::G1Affine: CurveAffine,
M::Fr: PrimeField,
L: Loader<M::G1Affine>,
{
type VerifyingKey = KzgSuccinctVerifyingKey<M::G1Affine>;
Expand All @@ -32,7 +35,7 @@ where

fn read_proof<T>(
_: &Self::VerifyingKey,
queries: &[Query<M::Scalar>],
queries: &[Query<<M::G1Affine as PrimeCurveAffine>::Scalar>],
transcript: &mut T,
) -> Result<Self::Proof, Error>
where
Expand All @@ -45,7 +48,7 @@ where
svk: &Self::VerifyingKey,
commitments: &[Msm<M::G1Affine, L>],
z: &L::LoadedScalar,
queries: &[Query<M::Scalar, L::LoadedScalar>],
queries: &[Query<<M::G1Affine as PrimeCurveAffine>::Scalar, L::LoadedScalar>],
proof: &Self::Proof,
) -> Result<Self::Output, Error> {
let sets = query_sets(queries);
Expand Down Expand Up @@ -161,11 +164,11 @@ where
impl<M> CostEstimation<M::G1Affine> for KzgAs<M, Gwc19>
where
M: MultiMillerLoop,
M::Scalar: PrimeField,
M::Fr: PrimeField,
{
type Input = Vec<Query<M::Scalar>>;
type Input = Vec<Query<M::Fr>>;

fn estimate_cost(queries: &Vec<Query<M::Scalar>>) -> Cost {
fn estimate_cost(queries: &Vec<Query<M::Fr>>) -> Cost {
let num_w = query_sets(queries).len();
Cost {
num_commitment: num_w,
Expand Down
17 changes: 10 additions & 7 deletions snark-verifier/src/system/halo2/test/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
system::halo2::test::{read_or_create_srs, MainGateWithRange},
util::arithmetic::{fe_to_limbs, CurveAffine, MultiMillerLoop, PrimeField},
};
use halo2_curves::serde::SerdeObject;
use halo2_curves::{serde::SerdeObject, CurveExt};
use halo2_proofs::poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG};
use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};

Expand All @@ -21,17 +21,20 @@ pub const BITS: usize = 68;

pub fn setup<M: MultiMillerLoop>(k: u32) -> ParamsKZG<M>
where
M::Scalar: PrimeField,
M::Fr: PrimeField,
M::G1Affine: SerdeObject + CurveAffine,
M::G1: CurveExt<AffineExt = M::G1Affine>,
{
ParamsKZG::<M>::setup(k, ChaCha20Rng::from_seed(Default::default()))
}

pub fn main_gate_with_range_with_mock_kzg_accumulator<M: MultiMillerLoop>(
) -> MainGateWithRange<M::Scalar>
pub fn main_gate_with_range_with_mock_kzg_accumulator<
C: CurveAffine,
M: MultiMillerLoop<G1Affine = C, Fr = C::ScalarExt, G1 = C::CurveExt>,
>() -> MainGateWithRange<<M::G1Affine as CurveAffine>::ScalarExt>
where
M::Scalar: PrimeField,
M::G1Affine: SerdeObject,
M::G2Affine: SerdeObject,
M::G2Affine: CurveAffine + SerdeObject,
M::G1Affine: CurveAffine + SerdeObject,
{
let srs = read_or_create_srs(TESTDATA_DIR, 1, setup::<M>);
let [g1, s_g1] = [srs.get_g()[0], srs.get_g()[1]].map(|point| point.coordinates().unwrap());
Expand Down
7 changes: 5 additions & 2 deletions snark-verifier/src/system/halo2/test/kzg/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use crate::{
},
verifier::plonk::PlonkVerifier,
};
use halo2_curves::bn256::{Bn256, G1Affine};
use halo2_curves::{
bn256::{Bn256, G1Affine},
pairing::Engine,
};
use halo2_proofs::poly::kzg::multiopen::{ProverGWC, ProverSHPLONK, VerifierGWC, VerifierSHPLONK};
use paste::paste;
use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};
Expand Down Expand Up @@ -120,7 +123,7 @@ test!(
zk_main_gate_with_range_with_mock_kzg_accumulator,
9,
halo2_kzg_config!(true, 1, (0..4 * LIMBS).map(|idx| (0, idx)).collect()),
main_gate_with_range_with_mock_kzg_accumulator::<Bn256>()
main_gate_with_range_with_mock_kzg_accumulator::<<Bn256 as Engine>::G1Affine, Bn256>()
);
test!(
#[cfg(feature = "loader_halo2")],
Expand Down
7 changes: 5 additions & 2 deletions snark-verifier/src/system/halo2/test/kzg/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use crate::{
},
verifier::plonk::PlonkVerifier,
};
use halo2_curves::bn256::{Bn256, G1Affine};
use halo2_curves::{
bn256::{Bn256, G1Affine},
pairing::Engine,
};
use halo2_proofs::{
poly::kzg::multiopen::{ProverGWC, ProverSHPLONK, VerifierGWC, VerifierSHPLONK},
transcript::{Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer},
Expand Down Expand Up @@ -64,5 +67,5 @@ test!(
zk_main_gate_with_range_with_mock_kzg_accumulator,
9,
halo2_kzg_config!(true, 2, (0..4 * LIMBS).map(|idx| (0, idx)).collect()),
main_gate_with_range_with_mock_kzg_accumulator::<Bn256>()
main_gate_with_range_with_mock_kzg_accumulator::<<Bn256 as Engine>::G1Affine, Bn256>()
);

0 comments on commit b45e327

Please sign in to comment.