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

sync group ff 0.13.0 #1

Open
wants to merge 2 commits into
base: develop
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
testdata

Cargo.lock
*.srs
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ debug = true

# patch until PR https://github.com/privacy-scaling-explorations/halo2/pull/111 is merged
[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/axiom-crypto/halo2.git", branch = "feat/serde-raw" }
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "halo2-ecc-snark-verifier-0220" }

[patch."https://github.com/privacy-scaling-explorations/poseidon.git"]
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "halo2-ecc-snark-verifier-0220" }

[patch.crates-io]
# temporary solution to funty@1.2.0 being yanked, tracking issue: https://github.com/ferrilab/funty/issues/7
funty = { git = "https://github.com/ferrilab/funty/", rev = "7ef0d890fbcd8b3def1635ac1a877fc298488446" }
19 changes: 12 additions & 7 deletions snark-verifier-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ serde_json = "1.0"
bincode = "1.3.3"
ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }

halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.2.2", default-features = false }
# halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.2.2", default-features = false }
halo2-base = { git = "https://github.com/scroll-tech/halo2-lib.git", branch = "halo2-ecc-snark-verifier-0220" }
snark-verifier = { path = "../snark-verifier", default-features = false }

# loader_evm
Expand All @@ -28,10 +29,14 @@ ethereum-types = { version = "0.14", default-features = false, features = ["std"
# rlp = { version = "0.5", default-features = false, features = ["std"], optional = true }

# zkevm benchmarks
zkevm-circuits = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", features = ["test"], optional = true }
bus-mapping = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
eth-types = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
mock = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
# zkevm-circuits = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", features = ["test"], optional = true }
# bus-mapping = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
# eth-types = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
# mock = { git = "https://github.com/jonathanpwang/zkevm-circuits.git", branch = "bench-12-04", optional = true }
zkevm-circuits = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "halo2-ecc-snark-verifier-0220", features = ["test"], optional = true }
bus-mapping = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "halo2-ecc-snark-verifier-0220", optional = true }
eth-types = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "halo2-ecc-snark-verifier-0220", optional = true }
mock = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "halo2-ecc-snark-verifier-0220", optional = true }

[dev-dependencies]
ark-std = { version = "0.3.0", features = ["print-trace"] }
Expand All @@ -44,14 +49,14 @@ crossterm = { version = "0.25" }
tui = { version = "0.19", default-features = false, features = ["crossterm"] }

[features]
default = ["loader_halo2", "loader_evm", "halo2-axiom", "halo2-base/jemallocator"]
default = ["loader_halo2", "loader_evm", "halo2-pse", "halo2-base/jemallocator"]
display = ["snark-verifier/display", "dep:ark-std"]
loader_evm = ["snark-verifier/loader_evm", "dep:ethereum-types"]
loader_halo2 = ["snark-verifier/loader_halo2"]
parallel = ["snark-verifier/parallel"]
# EXACTLY one of halo2-pse / halo2-axiom should always be turned on; not sure how to enforce this with Cargo
halo2-pse = ["snark-verifier/halo2-pse"]
halo2-axiom = ["snark-verifier/halo2-axiom"]
# halo2-axiom = ["snark-verifier/halo2-axiom"]

zkevm = ["dep:zkevm-circuits", "dep:bus-mapping", "dep:mock", "dep:eth-types"]

Expand Down
4 changes: 2 additions & 2 deletions snark-verifier-sdk/benches/standard_plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mod application {
#[cfg(feature = "halo2-axiom")]
{
region.assign_advice(config.a, 0, Value::known(self.0))?;
region.assign_fixed(config.q_a, 0, -Fr::one());
region.assign_fixed(config.q_a, 0, -Fr::ONE);
region.assign_advice(config.a, 1, Value::known(-Fr::from(5u64)))?;
for (idx, column) in (1..).zip([
config.q_a,
Expand All @@ -158,7 +158,7 @@ mod application {
region.assign_fixed(column, 1, Fr::from(idx as u64));
}

let a = region.assign_advice(config.a, 2, Value::known(Fr::one()))?;
let a = region.assign_advice(config.a, 2, Value::known(Fr::ONE))?;
a.copy_advice(&mut region, config.b, 3);
a.copy_advice(&mut region, config.c, 4);
}
Expand Down
8 changes: 4 additions & 4 deletions snark-verifier-sdk/src/halo2/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ pub fn load_verify_circuit_degree() -> u32 {
params.degree
}

pub fn flatten_accumulator<'b, 'a: 'b>(
pub fn flatten_accumulator<'a>(
accumulator: KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>,
) -> Vec<AssignedValue<'b, Fr>> {
) -> Vec<AssignedValue<Fr>> {
let KzgAccumulator { lhs, rhs } = accumulator;
let lhs = lhs.into_assigned();
let rhs = rhs.into_assigned();
Expand Down Expand Up @@ -372,7 +372,7 @@ impl Circuit<Fr> for AggregationCircuit {

// Expose instances
for (i, cell) in instances.into_iter().enumerate() {
layouter.constrain_instance(cell, config.instance, i);
layouter.constrain_instance(cell, config.instance, i)?;
}
#[cfg(feature = "display")]
end_timer!(witness_time);
Expand Down Expand Up @@ -510,7 +510,7 @@ impl Circuit<Fr> for PublicAggregationCircuit {
.unwrap();
// Expose instances
for (i, cell) in instances.into_iter().enumerate() {
layouter.constrain_instance(cell, config.instance, i);
layouter.constrain_instance(cell, config.instance, i)?;
}
#[cfg(feature = "display")]
end_timer!(witness_time);
Expand Down
22 changes: 14 additions & 8 deletions snark-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ rand = "0.8"
rustc-hash = "1.1.0"
serde = { version = "1.0", features = ["derive"] }

# Use halo2-base as non-optional dependency because it re-exports halo2_proofs, halo2curves, and poseidon, using different repos based on feature flag "halo2-axiom" or "halo2-pse"
halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.2.2", default-features = false }
# This poseidon is identical to PSE (for now) but uses axiom's halo2curves; otherwise would require patching
poseidon-axiom = { git = "https://github.com/axiom-crypto/halo2.git", branch = "axiom/faster-witness-generation", package = "poseidon", optional = true }
poseidon= { git = "https://github.com/privacy-scaling-explorations/poseidon", optional = true }
# # Use halo2-base as non-optional dependency because it re-exports halo2_proofs, halo2curves, and poseidon, using different repos based on feature flag "halo2-axiom" or "halo2-pse"
# halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.2.2", default-features = false }
# # This poseidon is identical to PSE (for now) but uses axiom's halo2curves; otherwise would require patching
# poseidon-axiom = { git = "https://github.com/axiom-crypto/halo2.git", branch = "axiom/faster-witness-generation", package = "poseidon", optional = true }
# poseidon= { git = "https://github.com/privacy-scaling-explorations/poseidon", optional = true }

ff = "0.13"
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "sync-ff-0.13" }
halo2-base = { git = "https://github.com/scroll-tech/halo2-lib.git", branch = "sync-ff-0.13" }
poseidon = { git = "https://github.com/scroll-tech/poseidon", branch = "sync-ff-0.13", optional = true }

# parallel
rayon = { version = "1.5.3", optional = true }
Expand All @@ -31,7 +36,8 @@ bytes = { version = "1.2", optional = true }
rlp = { version = "0.5", default-features = false, features = ["std"], optional = true }

# loader_halo2
halo2-ecc = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.2.2", default-features = false, optional = true }
# halo2-ecc = { git = "https://github.com/axiom-crypto/halo2-lib.git", tag = "v0.2.2", default-features = false, optional = true }
halo2-ecc = { git = "https://github.com/scroll-tech/halo2-lib.git", branch = "sync-ff-0.13", default-features = false, optional = true }

[dev-dependencies]
ark-std = { version = "0.3.0", features = ["print-trace"] }
Expand All @@ -44,14 +50,14 @@ crossterm = { version = "0.25" }
tui = { version = "0.19", default-features = false, features = ["crossterm"] }

[features]
default = ["loader_evm", "loader_halo2", "halo2-axiom"]
default = ["loader_evm", "loader_halo2", "halo2-pse"]
display = ["halo2-base/display", "halo2-ecc?/display"]
loader_evm = ["dep:ethereum-types", "dep:sha3", "dep:revm", "dep:bytes", "dep:rlp"]
loader_halo2 = ["halo2-ecc"]
parallel = ["dep:rayon"]
# EXACTLY one of halo2-pse / halo2-axiom should always be turned on; not sure how to enforce this with Cargo
halo2-pse = ["halo2-base/halo2-pse", "halo2-ecc?/halo2-pse", "poseidon"]
halo2-axiom = ["halo2-base/halo2-axiom", "halo2-ecc?/halo2-axiom", "poseidon-axiom"]
# halo2-axiom = ["halo2-base/halo2-axiom", "halo2-ecc?/halo2-axiom", "poseidon-axiom"]

[[example]]
name = "evm-verifier"
Expand Down
7 changes: 3 additions & 4 deletions snark-verifier/examples/evm-verifier-with-accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ mod application {
poly::Rotation,
};
use super::Fr;
use halo2_base::halo2_proofs::plonk::Assigned;
use rand::RngCore;

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -166,7 +165,7 @@ mod application {
0,
Value::known(Assigned::Trivial(self.0)),
)?;
region.assign_fixed(config.q_a, 0, Assigned::Trivial(-Fr::one()));
region.assign_fixed(config.q_a, 0, Assigned::Trivial(-Fr::ONE));

region.assign_advice(
config.a,
Expand All @@ -186,7 +185,7 @@ mod application {
let a = region.assign_advice(
config.a,
2,
Value::known(Assigned::Trivial(Fr::one())),
Value::known(Assigned::Trivial(Fr::ONE)),
)?;
a.copy_advice(&mut region, config.b, 3);
a.copy_advice(&mut region, config.c, 4);
Expand Down Expand Up @@ -525,7 +524,7 @@ mod aggregation {
// TODO: use less instances by following Scroll's strategy of keeping only last bit of y coordinate
let mut layouter = layouter.namespace(|| "expose");
for (i, cell) in assigned_instances.unwrap().into_iter().enumerate() {
layouter.constrain_instance(cell, config.instance, i);
layouter.constrain_instance(cell, config.instance, i)?;
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions snark-verifier/examples/evm-verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use halo2_proofs::{
dev::MockProver,
halo2curves::bn256::{Bn256, Fq, Fr, G1Affine},
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Assigned, Circuit, Column,
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Circuit, Column,
ConstraintSystem, Error, Fixed, Instance, ProvingKey, VerifyingKey,
},
poly::{
Expand Down Expand Up @@ -141,7 +141,7 @@ impl Circuit<Fr> for StandardPlonk {
#[cfg(feature = "halo2-axiom")]
{
region.assign_advice(config.a, 0, Value::known(Assigned::Trivial(self.0)))?;
region.assign_fixed(config.q_a, 0, Assigned::Trivial(-Fr::one()));
region.assign_fixed(config.q_a, 0, Assigned::Trivial(-Fr::ONE));

region.assign_advice(
config.a,
Expand All @@ -161,7 +161,7 @@ impl Circuit<Fr> for StandardPlonk {
let a = region.assign_advice(
config.a,
2,
Value::known(Assigned::Trivial(Fr::one())),
Value::known(Assigned::Trivial(Fr::ONE)),
)?;
a.copy_advice(&mut region, config.b, 3);
a.copy_advice(&mut region, config.c, 4);
Expand Down
43 changes: 21 additions & 22 deletions snark-verifier/examples/recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use halo2_proofs::{
halo2curves::{
bn256::{Bn256, Fq, Fr, G1Affine},
group::ff::Field,
FieldExt,
},
plonk::{
self, create_proof, keygen_pk, keygen_vk, Circuit, ConstraintSystem, Error, ProvingKey,
Expand Down Expand Up @@ -370,8 +369,8 @@ mod recursion {
svk: &Svk,
loader: &Rc<Halo2Loader<'a>>,
snark: &SnarkWitness,
preprocessed_digest: Option<AssignedValue<'a, Fr>>,
) -> (Vec<Vec<AssignedValue<'a, Fr>>>, Vec<KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>>) {
preprocessed_digest: Option<AssignedValue<Fr>>,
) -> (Vec<Vec<AssignedValue<Fr>>>, Vec<KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>>) {
let protocol = if let Some(preprocessed_digest) = preprocessed_digest {
let preprocessed_digest = loader.scalar_from_assigned(preprocessed_digest);
let protocol = snark.protocol.loaded_preprocessed_as_witness(loader);
Expand Down Expand Up @@ -415,7 +414,7 @@ mod recursion {

fn select_accumulator<'a>(
loader: &Rc<Halo2Loader<'a>>,
condition: &AssignedValue<'a, Fr>,
condition: &AssignedValue<Fr>,
lhs: &KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>,
rhs: &KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>,
) -> Result<KzgAccumulator<G1Affine, Rc<Halo2Loader<'a>>>, Error> {
Expand Down Expand Up @@ -587,7 +586,7 @@ mod recursion {
snark.instances = vec![[g[1].x, g[1].y, g[0].x, g[0].y]
.into_iter()
.flat_map(fe_to_limbs::<_, _, LIMBS, BITS>)
.chain([Fr::zero(); 4])
.chain([Fr::ZERO; 4])
.collect_vec()];
snark
}
Expand Down Expand Up @@ -674,7 +673,7 @@ mod recursion {
main_gate.assign_integer(&mut ctx, Value::known(instance)).unwrap()
});
let first_round = main_gate.is_zero(&mut ctx, &round);
let not_first_round = main_gate.not(&mut ctx, Existing(&first_round));
let not_first_round = main_gate.not(&mut ctx, Existing(first_round));

let loader = Halo2Loader::new(config.ecc_chip(), ctx);
let (mut app_instances, app_accumulators) =
Expand Down Expand Up @@ -716,31 +715,31 @@ mod recursion {
(
&main_gate.mul(
&mut ctx,
Existing(&preprocessed_digest),
Existing(&not_first_round),
Existing(preprocessed_digest),
Existing(not_first_round),
),
&previous_instances[Self::PREPROCESSED_DIGEST_ROW],
),
// Propagate initial_state
(
&main_gate.mul(
&mut ctx,
Existing(&initial_state),
Existing(&not_first_round),
Existing(initial_state),
Existing(not_first_round),
),
&previous_instances[Self::INITIAL_STATE_ROW],
),
// Verify initial_state is same as the first application snark
(
&main_gate.mul(
&mut ctx,
Existing(&initial_state),
Existing(&first_round),
Existing(initial_state),
Existing(first_round),
),
&main_gate.mul(
&mut ctx,
Existing(&app_instances[0]),
Existing(&first_round),
Existing(app_instances[0]),
Existing(first_round),
),
),
// Verify current state is same as the current application snark
Expand All @@ -749,8 +748,8 @@ mod recursion {
(
&main_gate.mul(
&mut ctx,
Existing(&app_instances[0]),
Existing(&not_first_round),
Existing(app_instances[0]),
Existing(not_first_round),
),
&previous_instances[Self::STATE_ROW],
),
Expand All @@ -759,12 +758,12 @@ mod recursion {
&round,
&main_gate.add(
&mut ctx,
Existing(&not_first_round),
Existing(&previous_instances[Self::ROUND_ROW]),
Existing(not_first_round),
Existing(previous_instances[Self::ROUND_ROW]),
),
),
] {
ctx.region.constrain_equal(lhs.cell(), rhs.cell());
ctx.region.constrain_equal(lhs.cell(), rhs.cell())?;
}

// IMPORTANT:
Expand All @@ -787,7 +786,7 @@ mod recursion {

assert_eq!(assigned_instances.len(), 4 * LIMBS + 4);
for (row, limb) in assigned_instances.into_iter().enumerate() {
layouter.constrain_instance(limb, config.instance, row);
layouter.constrain_instance(limb, config.instance, row)?;
}

Ok(())
Expand Down Expand Up @@ -825,8 +824,8 @@ mod recursion {
recursion_params,
gen_dummy_snark::<ConcreteCircuit>(app_params, Some(app_vk)),
RecursionCircuit::initial_snark(recursion_params, None),
Fr::zero(),
Fr::zero(),
Fr::ZERO,
Fr::ZERO,
0,
);
gen_pk(recursion_params, &recursion)
Expand Down
7 changes: 1 addition & 6 deletions snark-verifier/src/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ impl Cost {
num_evaluation: usize,
num_msm: usize,
) -> Self {
Self {
num_instance,
num_commitment,
num_evaluation,
num_msm,
}
Self { num_instance, num_commitment, num_evaluation, num_msm }
}
}

Expand Down
2 changes: 1 addition & 1 deletion snark-verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod util;
pub mod verifier;

pub(crate) use halo2_base::halo2_proofs;
pub(crate) use halo2_proofs::halo2curves as halo2_curves;
pub(crate) use halo2_base::halo2_proofs::halo2curves as halo2_curves;
#[cfg(feature = "halo2-pse")]
pub(crate) use poseidon;
#[cfg(feature = "halo2-axiom")]
Expand Down
Loading