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 ff 0.13 #25

Merged
merged 5 commits into from
Dec 5, 2023
Merged
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
3,491 changes: 0 additions & 3,491 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ debug-assertions = false
lto = "fat"
# codegen-units = 1
panic = "abort"
incremental = true
incremental = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this important?


# For performance profiling
[profile.flamegraph]
inherits = "release"
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/scroll-tech/halo2.git", branch = "develop-rc" }
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.0" }

[patch."https://github.com/privacy-scaling-explorations/poseidon.git"]
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "scroll-dev-0220" }
[patch."https://github.com/privacy-scaling-explorations/halo2curves.git"]
halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" }
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "main" }
24 changes: 17 additions & 7 deletions snark-verifier-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.1"
edition = "2021"

[dependencies]
log = "0.4"
itertools = "0.10.3"
lazy_static = "1.4.0"
num-bigint = "0.4.3"
Expand All @@ -15,9 +16,11 @@ hex = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
bincode = "1.3.3"
ark-std = { version = "0.4.0", features = ["print-trace"], optional = true }
ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }

halo2-base = { git = "https://github.com/scroll-tech/halo2-lib.git", tag = "v0.1.5", default-features=false, features=["halo2-pse","display"] }
ff = "0.13"
# 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 = "develop" }
snark-verifier = { path = "../snark-verifier", default-features = false }

# loader_evm
Expand All @@ -27,13 +30,18 @@ ethereum-types = { version = "0.14", default-features = false, features = ["std"
# bytes = { version = "1.2", optional = true }
# rlp = { version = "0.5", default-features = false, features = ["std"], optional = true }

env_logger = "0.10.0"
log = "0.4.17"
# 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/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]
eth-types = { git = "https://github.com/scroll-tech/zkevm-circuits.git", branch = "develop" }
ark-std = { version = "0.3.0", features = ["print-trace"] }
ethers-signers = { version = "0.17.0" }
paste = "1.0.7"
pprof = { version = "0.11", features = ["criterion", "flamegraph"] }
criterion = "0.4"
Expand All @@ -50,7 +58,9 @@ 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"]

[[bench]]
name = "standard_plonk"
Expand Down
2 changes: 1 addition & 1 deletion snark-verifier-sdk/src/halo2_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use halo2_base::halo2_proofs::{
VerificationStrategy,
},
transcript::TranscriptReadBuffer,
SerdeFormat, {self},
SerdeFormat,
};
use itertools::Itertools;
use rand::Rng;
Expand Down
6 changes: 3 additions & 3 deletions snark-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ 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/scroll-tech/halo2-lib", tag = "v0.1.5", default-features=false, features=["halo2-pse","display"] }
halo2-base = { git = "https://github.com/scroll-tech/halo2-lib", branch = "develop", default-features=false, features=["halo2-pse","display"] }
# 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/dev", package = "poseidon", optional = true }
poseidon= { git = "https://github.com/privacy-scaling-explorations/poseidon", optional = true }
poseidon = { git = "https://github.com/privacy-scaling-explorations/poseidon", optional = true }

# parallel
rayon = { version = "1.5.3", optional = true }
Expand All @@ -31,7 +31,7 @@ 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/scroll-tech/halo2-lib", tag = "v0.1.5", optional = true, default-features=false, features=["halo2-pse","display"] }
halo2-ecc = { git = "https://github.com/scroll-tech/halo2-lib", branch = "develop", optional = true, default-features=false, features=["halo2-pse","display"] }

[dev-dependencies]
ark-std = { version = "0.3.0", features = ["print-trace"] }
Expand Down
11 changes: 7 additions & 4 deletions snark-verifier/examples/evm-verifier-with-accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod application {
},
Fr,
};
use halo2_base::halo2_proofs::arithmetic::Field;
use rand::RngCore;

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -117,6 +118,8 @@ mod application {
impl Circuit<Fr> for StandardPlonk {
type Config = StandardPlonkConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
Expand All @@ -138,7 +141,7 @@ mod application {
#[cfg(feature = "halo2-pse")]
{
region.assign_advice(|| "", config.a, 0, || Value::known(self.0))?;
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::one()))?;
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::ONE))?;

region.assign_advice(
|| "",
Expand All @@ -162,7 +165,7 @@ mod application {
}

let a =
region.assign_advice(|| "", config.a, 2, || Value::known(Fr::one()))?;
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 All @@ -173,7 +176,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(-FrONE));

region.assign_advice(
config.a,
Expand All @@ -193,7 +196,7 @@ mod application {
let a = region.assign_advice(
config.a,
2,
Value::known(Assigned::Trivial(Fr::one())),
Value::known(Assigned::Trivial(FrONE)),
)?;
a.copy_advice(&mut region, config.b, 3);
a.copy_advice(&mut region, config.c, 4);
Expand Down
11 changes: 7 additions & 4 deletions snark-verifier/examples/evm-verifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ethereum_types::Address;
use halo2_base::halo2_proofs::{
arithmetic::Field,
poly::kzg::multiopen::{ProverSHPLONK, VerifierSHPLONK},
{self},
};
Expand Down Expand Up @@ -101,6 +102,8 @@ impl StandardPlonk {
impl Circuit<Fr> for StandardPlonk {
type Config = StandardPlonkConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
Expand All @@ -122,7 +125,7 @@ impl Circuit<Fr> for StandardPlonk {
#[cfg(feature = "halo2-pse")]
{
region.assign_advice(|| "", config.a, 0, || Value::known(self.0))?;
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::one()))?;
region.assign_fixed(|| "", config.q_a, 0, || Value::known(-Fr::ONE))?;

region.assign_advice(|| "", config.a, 1, || Value::known(-Fr::from(5u64)))?;
for (idx, column) in (1..).zip([
Expand All @@ -140,14 +143,14 @@ impl Circuit<Fr> for StandardPlonk {
)?;
}

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)?;
}
#[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(-FrONE));

region.assign_advice(
config.a,
Expand All @@ -167,7 +170,7 @@ impl Circuit<Fr> for StandardPlonk {
let a = region.assign_advice(
config.a,
2,
Value::known(Assigned::Trivial(Fr::one())),
Value::known(Assigned::Trivial(FrONE)),
)?;
a.copy_advice(&mut region, config.b, 3);
a.copy_advice(&mut region, config.c, 4);
Expand Down
11 changes: 7 additions & 4 deletions snark-verifier/examples/recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use halo2_proofs::{
halo2curves::{
bn256::{Bn256, Fq, Fr, G1Affine},
group::ff::Field,
FieldExt,
},
plonk::{
create_proof, keygen_pk, keygen_vk, Circuit, ConstraintSystem, Error, ProvingKey, Selector,
Expand Down Expand Up @@ -227,6 +226,8 @@ mod common {
impl<F: Field, C: CircuitExt<F>> Circuit<F> for CsProxy<F, C> {
type Config = C::Config;
type FloorPlanner = C::FloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
CsProxy(PhantomData)
Expand Down Expand Up @@ -303,6 +304,8 @@ mod application {
impl Circuit<Fr> for Square {
type Config = Selector;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
Expand Down Expand Up @@ -595,7 +598,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 @@ -833,8 +836,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
24 changes: 12 additions & 12 deletions snark-verifier/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ pub trait ScalarLoader<F: PrimeField> {

/// Load `zero` as constant.
fn load_zero(&self) -> Self::LoadedScalar {
self.load_const(&F::zero())
self.load_const(&F::ZERO)
}

/// Load `one` as constant.
fn load_one(&self) -> Self::LoadedScalar {
self.load_const(&F::one())
self.load_const(&F::ONE)
}

/// Assert lhs and rhs field elements are equal.
Expand All @@ -153,13 +153,13 @@ pub trait ScalarLoader<F: PrimeField> {

let loader = values.first().unwrap().1.loader();
iter::empty()
.chain(if constant == F::zero() {
.chain(if constant == F::ZERO {
None
} else {
Some(Cow::Owned(loader.load_const(&constant)))
})
.chain(values.iter().map(|&(coeff, value)| {
if coeff == F::one() {
if coeff == F::ONE {
Cow::Borrowed(value)
} else {
Cow::Owned(loader.load_const(&coeff) * value)
Expand All @@ -182,9 +182,9 @@ pub trait ScalarLoader<F: PrimeField> {

let loader = values.first().unwrap().1.loader();
iter::empty()
.chain(if constant == F::zero() { None } else { Some(loader.load_const(&constant)) })
.chain(if constant == F::ZERO { None } else { Some(loader.load_const(&constant)) })
.chain(values.iter().map(|&(coeff, lhs, rhs)| {
if coeff == F::one() {
if coeff == F::ONE {
lhs.clone() * rhs
} else {
loader.load_const(&coeff) * lhs * rhs
Expand All @@ -196,28 +196,28 @@ pub trait ScalarLoader<F: PrimeField> {

/// Sum field elements with coefficients.
fn sum_with_coeff(&self, values: &[(F, &Self::LoadedScalar)]) -> Self::LoadedScalar {
self.sum_with_coeff_and_const(values, F::zero())
self.sum_with_coeff_and_const(values, F::ZERO)
}

/// Sum field elements and constant.
fn sum_with_const(&self, values: &[&Self::LoadedScalar], constant: F) -> Self::LoadedScalar {
self.sum_with_coeff_and_const(
&values.iter().map(|&value| (F::one(), value)).collect_vec(),
&values.iter().map(|&value| (F::ONE, value)).collect_vec(),
constant,
)
}

/// Sum field elements.
fn sum(&self, values: &[&Self::LoadedScalar]) -> Self::LoadedScalar {
self.sum_with_const(values, F::zero())
self.sum_with_const(values, F::ZERO)
}

/// Sum product of field elements with coefficients.
fn sum_products_with_coeff(
&self,
values: &[(F, &Self::LoadedScalar, &Self::LoadedScalar)],
) -> Self::LoadedScalar {
self.sum_products_with_coeff_and_const(values, F::zero())
self.sum_products_with_coeff_and_const(values, F::ZERO)
}

/// Sum product of field elements and constant.
Expand All @@ -227,7 +227,7 @@ pub trait ScalarLoader<F: PrimeField> {
constant: F,
) -> Self::LoadedScalar {
self.sum_products_with_coeff_and_const(
&values.iter().map(|&(lhs, rhs)| (F::one(), lhs, rhs)).collect_vec(),
&values.iter().map(|&(lhs, rhs)| (F::ONE, lhs, rhs)).collect_vec(),
constant,
)
}
Expand All @@ -237,7 +237,7 @@ pub trait ScalarLoader<F: PrimeField> {
&self,
values: &[(&Self::LoadedScalar, &Self::LoadedScalar)],
) -> Self::LoadedScalar {
self.sum_products_with_const(values, F::zero())
self.sum_products_with_const(values, F::ZERO)
}

/// Product of field elements.
Expand Down
12 changes: 6 additions & 6 deletions snark-verifier/src/loader/evm/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ impl<F: PrimeField<Repr = [u8; 0x20]>> ScalarLoader<F> for Rc<EvmLoader> {
}

let push_addend = |(coeff, value): &(F, &Scalar)| {
assert_ne!(*coeff, F::zero());
match (*coeff == F::one(), &value.value) {
assert_ne!(*coeff, F::ZERO);
match (*coeff == F::ONE, &value.value) {
(true, _) => self.push(value),
(false, Value::Constant(value)) => self.push(
&self.scalar(Value::Constant(fe_to_u256(*coeff * u256_to_fe::<F>(*value)))),
Expand All @@ -696,7 +696,7 @@ impl<F: PrimeField<Repr = [u8; 0x20]>> ScalarLoader<F> for Rc<EvmLoader> {
};

let mut values = values.iter();
let initial_value = if constant == F::zero() {
let initial_value = if constant == F::ZERO {
push_addend(values.next().unwrap())
} else {
self.push(&self.scalar(Value::Constant(fe_to_u256(constant))))
Expand Down Expand Up @@ -730,8 +730,8 @@ impl<F: PrimeField<Repr = [u8; 0x20]>> ScalarLoader<F> for Rc<EvmLoader> {
}

let push_addend = |(coeff, lhs, rhs): &(F, &Scalar, &Scalar)| {
assert_ne!(*coeff, F::zero());
match (*coeff == F::one(), &lhs.value, &rhs.value) {
assert_ne!(*coeff, F::ZERO);
match (*coeff == F::ONE, &lhs.value, &rhs.value) {
(_, Value::Constant(lhs), Value::Constant(rhs)) => {
self.push(&self.scalar(Value::Constant(fe_to_u256(
*coeff * u256_to_fe::<F>(*lhs) * u256_to_fe::<F>(*rhs),
Expand Down Expand Up @@ -761,7 +761,7 @@ impl<F: PrimeField<Repr = [u8; 0x20]>> ScalarLoader<F> for Rc<EvmLoader> {
};

let mut values = values.iter();
let initial_value = if constant == F::zero() {
let initial_value = if constant == F::ZERO {
push_addend(values.next().unwrap())
} else {
self.push(&self.scalar(Value::Constant(fe_to_u256(constant))))
Expand Down
Loading