Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Update halo2 dependency to v2023_04_20 #1374

Merged
merged 7 commits into from
May 4, 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
89 changes: 42 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [
]

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

# Definition of benchmarks profile to use.
[profile.bench]
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mock = { path = "../mock", optional = true }

ethers-core = "0.17.0"
ethers-providers = "0.17.0"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
itertools = "0.10"
lazy_static = "1.4"
log = "0.4.14"
Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
ark-std = { version = "0.3", features = ["print-trace"] }
zkevm-circuits = { path = "../zkevm-circuits", features = ["test"]}
keccak256 = { path = "../keccak256" }
Expand Down
2 changes: 1 addition & 1 deletion eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ethers-core = "0.17.0"
ethers-signers = "0.17.0"
hex = "0.4"
lazy_static = "1.4"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
regex = "1.5.4"
serde = {version = "1.0.130", features = ["derive"] }
serde_json = "1.0.66"
Expand Down
32 changes: 24 additions & 8 deletions eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ pub mod sign_types;

pub use bytecode::Bytecode;
pub use error::Error;
use halo2_proofs::{
arithmetic::{Field as Halo2Field, FieldExt},
halo2curves::{
bn256::{Fq, Fr},
group::ff::PrimeField,
},
use halo2_proofs::halo2curves::{
bn256::{Fq, Fr},
ff::{Field as Halo2Field, FromUniformBytes, PrimeField},
};

use crate::evm_types::{
Expand All @@ -47,9 +44,28 @@ pub use ethers_core::{
use serde::{de, Deserialize, Serialize};
use std::{collections::HashMap, fmt, str::FromStr};

/// Trait used to reduce verbosity with the declaration of the [`FieldExt`]
/// Trait used to reduce verbosity with the declaration of the [`PrimeField`]
/// trait and its repr.
pub trait Field: FieldExt + Halo2Field + PrimeField<Repr = [u8; 32]> {}
pub trait Field: Halo2Field + PrimeField<Repr = [u8; 32]> + FromUniformBytes<64> + Ord {
/// Gets the lower 128 bits of this field element when expressed
/// canonically.
fn get_lower_128(&self) -> u128 {
let bytes = self.to_repr();
bytes[..16]
.iter()
.rev()
.fold(0u128, |acc, value| acc * 256u128 + *value as u128)
}
/// Gets the lower 32 bits of this field element when expressed
/// canonically.
fn get_lower_32(&self) -> u32 {
let bytes = self.to_repr();
bytes[..4]
.iter()
.rev()
.fold(0u32, |acc, value| acc * 256u32 + *value as u32)
}
}

// Impl custom `Field` trait for BN256 Fr to be used and consistent with the
// rest of the workspace.
Expand Down
14 changes: 7 additions & 7 deletions eth-types/src/sign_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use crate::{ToBigEndian, Word};
use halo2_proofs::{
arithmetic::{CurveAffine, FieldExt},
arithmetic::{CurveAffine, Field},
halo2curves::{
group::{
ff::{Field as GroupField, PrimeField},
ff::{FromUniformBytes, PrimeField},
Curve,
},
secp256k1::{self, Secp256k1Affine},
Expand Down Expand Up @@ -36,7 +36,7 @@ pub fn sign(
let mut x_bytes = [0u8; 64];
x_bytes[..32].copy_from_slice(&x_repr[..]);

let sig_r = secp256k1::Fq::from_bytes_wide(&x_bytes); // get x cordinate (E::Base) on E::Scalar
let sig_r = secp256k1::Fq::from_uniform_bytes(&x_bytes); // get x cordinate (E::Base) on E::Scalar
let sig_s = randomness_inv * (msg_hash + sig_r * sk);
(sig_r, sig_s)
}
Expand All @@ -56,11 +56,11 @@ pub struct SignData {
lazy_static! {
static ref SIGN_DATA_DEFAULT: SignData = {
let generator = Secp256k1Affine::generator();
let sk = secp256k1::Fq::one();
let sk = secp256k1::Fq::ONE;
let pk = generator * sk;
let pk = pk.to_affine();
let msg_hash = secp256k1::Fq::one();
let randomness = secp256k1::Fq::one();
let msg_hash = secp256k1::Fq::ONE;
let randomness = secp256k1::Fq::ONE;
let (sig_r, sig_s) = sign(randomness, sk, msg_hash);

SignData {
Expand Down Expand Up @@ -123,7 +123,7 @@ pub fn recover_pk(
lazy_static! {
/// Secp256k1 Curve Scalar. Referece: Section 2.4.1 (parameter `n`) in "SEC 2: Recommended
/// Elliptic Curve Domain Parameters" document at http://www.secg.org/sec2-v2.pdf
pub static ref SECP256K1_Q: BigUint = BigUint::from_bytes_le(&(secp256k1::Fq::zero() - secp256k1::Fq::one()).to_repr()) + 1u64;
pub static ref SECP256K1_Q: BigUint = BigUint::from_bytes_le(&(secp256k1::Fq::ZERO - secp256k1::Fq::ONE).to_repr()) + 1u64;
}

/// Helper function to convert a `CtOption` into an `Result`. Similar to
Expand Down
2 changes: 1 addition & 1 deletion gadgets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The appliedzkp team"]
license = "MIT OR Apache-2.0"

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
sha3 = "0.7.2"
eth-types = { path = "../eth-types" }
digest = "0.7.6"
Expand Down
Loading