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

Upgrade halo2_proofs version #14

Merged
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
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ version = "0.1.0"
edition = "2021"

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v0.3.0" }
askama = { version = "0.12.0", features = ["config"], default-features = false }
hex = "0.4.3"
ruint = "1"
sha3 = "0.10"
itertools = "0.11.0"

# Remove when `vk.transcript_repr()` is ready for usage.
blake2b_simd = "1"

# For feature = "evm"
revm = { version = "3.3.0", default-features = false, optional = true }

[dev-dependencies]
rand = "0.8.5"
revm = { version = "3.3.0", default-features = false }
halo2_maingate = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20", package = "maingate" }
halo2_maingate = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2024_01_31", package = "maingate" }

[features]
default = []
Expand Down
18 changes: 1 addition & 17 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<'a> SolidityGenerator<'a> {
fn generate_vk(&self) -> Halo2VerifyingKey {
let constants = {
let domain = self.vk.get_domain();
let vk_digest = fr_to_u256(vk_transcript_repr(self.vk));
let vk_digest = fr_to_u256(self.vk.transcript_repr());
let num_instances = U256::from(self.num_instances);
let k = U256::from(domain.k());
let n_inv = fr_to_u256(bn256::Fr::from(1 << domain.k()).invert().unwrap());
Expand Down Expand Up @@ -298,19 +298,3 @@ impl<'a> SolidityGenerator<'a> {
* 0x20
}
}

// Remove when `vk.transcript_repr()` is ready for usage.
fn vk_transcript_repr(vk: &VerifyingKey<bn256::G1Affine>) -> bn256::Fr {
use blake2b_simd::Params;
use halo2_proofs::halo2curves::ff::FromUniformBytes;

let fmtted_pinned_vk = format!("{:?}", vk.pinned());
let mut hasher = Params::new()
.hash_length(64)
.personal(b"Halo2-Verify-Key")
.to_state();
hasher
.update(&(fmtted_pinned_vk.len() as u64).to_le_bytes())
.update(fmtted_pinned_vk.as_bytes());
FromUniformBytes::from_uniform_bytes(hasher.finalize().as_array())
}
68 changes: 30 additions & 38 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,18 @@ mod halo2 {
fn random_accumulator_limbs<M>(
acc_encoding: AccumulatorEncoding,
mut rng: impl RngCore,
) -> Vec<M::Scalar>
) -> Vec<M::Fr>
where
M: MultiMillerLoop,
M::G1Affine: CurveAffine<ScalarExt = M::Fr>,
<M::G1Affine as CurveAffine>::Base: PrimeField<Repr = [u8; 0x20]>,
M::Scalar: PrimeField<Repr = [u8; 0x20]>,
<M::G1Affine as CurveAffine>::ScalarExt: PrimeField<Repr = [u8; 0x20]>,
{
let s = M::Scalar::random(&mut rng);
let s = M::Fr::random(&mut rng);
let g1 = M::G1Affine::generator();
let g2 = M::G2Affine::generator();
let neg_s_g2 = (g2 * -s).to_affine();
let lhs_scalar = M::Scalar::random(&mut rng);
let lhs_scalar = M::Fr::random(&mut rng);
let rhs_scalar = lhs_scalar * s.invert().unwrap();
let [lhs, rhs] = [lhs_scalar, rhs_scalar].map(|scalar| (g1 * scalar).to_affine());

Expand Down Expand Up @@ -337,13 +338,14 @@ mod halo2 {
use std::{array, fmt::Debug, iter, mem};

#[derive(Clone, Debug, Default)]
pub struct HugeCircuit<M: MultiMillerLoop>(Vec<M::Scalar>);
pub struct HugeCircuit<M: MultiMillerLoop>(Vec<M::Fr>);

impl<M: MultiMillerLoop> TestCircuit<M::Scalar> for HugeCircuit<M>
impl<M: MultiMillerLoop> TestCircuit<M::Fr> for HugeCircuit<M>
where
M: MultiMillerLoop,
M::G1Affine: CurveAffine<ScalarExt = M::Fr>,
<M::G1Affine as CurveAffine>::Base: PrimeField<Repr = [u8; 0x20]>,
M::Scalar: PrimeField<Repr = [u8; 0x20]>,
<M::G1Affine as CurveAffine>::ScalarExt: PrimeField<Repr = [u8; 0x20]>,
{
fn min_k() -> u32 {
6
Expand All @@ -353,22 +355,19 @@ mod halo2 {
let instances = if let Some(acc_encoding) = acc_encoding {
random_accumulator_limbs::<M>(acc_encoding, rng)
} else {
iter::repeat_with(|| M::Scalar::random(&mut rng))
iter::repeat_with(|| M::Fr::random(&mut rng))
.take(10)
.collect()
};
Self(instances)
}

fn instances(&self) -> Vec<M::Scalar> {
fn instances(&self) -> Vec<M::Fr> {
self.0.clone()
}
}

impl<M: MultiMillerLoop> Circuit<M::Scalar> for HugeCircuit<M>
where
M::Scalar: PrimeField,
{
impl<M: MultiMillerLoop> Circuit<M::Fr> for HugeCircuit<M> {
type Config = (
[Selector; 10],
[Selector; 10],
Expand All @@ -384,7 +383,7 @@ mod halo2 {
unimplemented!()
}

fn configure(meta: &mut ConstraintSystem<M::Scalar>) -> Self::Config {
fn configure(meta: &mut ConstraintSystem<M::Fr>) -> Self::Config {
let selectors = [(); 10].map(|_| meta.selector());
let complex_selectors = [(); 10].map(|_| meta.complex_selector());
let fixeds = [(); 10].map(|_| meta.fixed_column());
Expand All @@ -411,7 +410,7 @@ mod halo2 {

meta.create_gate("", |meta| {
let selectors = selectors.map(|selector| meta.query_selector(selector));
let advices: [Expression<M::Scalar>; 10] = array::from_fn(|idx| {
let advices: [Expression<M::Fr>; 10] = array::from_fn(|idx| {
let rotation = Rotation((idx as i32 - advices.len() as i32) / 2);
meta.query_advice(advices[idx], rotation)
});
Expand Down Expand Up @@ -457,7 +456,7 @@ mod halo2 {
fn synthesize(
&self,
(selectors, complex_selectors, fixeds, advices, instance): Self::Config,
mut layouter: impl Layouter<M::Scalar>,
mut layouter: impl Layouter<M::Fr>,
) -> Result<(), plonk::Error> {
let assigneds = layouter.assign_region(
|| "",
Expand All @@ -472,7 +471,7 @@ mod halo2 {
q.enable(&mut region, next_offset())?;
}
for (idx, column) in izip!(1.., fixeds) {
let value = Value::known(M::Scalar::from(idx));
let value = Value::known(M::Fr::from(idx));
region.assign_fixed(|| "", column, next_offset(), || value)?;
}
izip!(advices, &self.0)
Expand Down Expand Up @@ -549,14 +548,15 @@ mod halo2 {

#[derive(Clone, Default)]
pub struct MainGateWithRange<M: MultiMillerLoop> {
instances: Vec<M::Scalar>,
instances: Vec<M::Fr>,
}

impl<M> TestCircuit<M::Scalar> for MainGateWithRange<M>
impl<M> TestCircuit<M::Fr> for MainGateWithRange<M>
where
M: MultiMillerLoop,
M::G1Affine: CurveAffine<ScalarExt = M::Fr>,
<M::G1Affine as CurveAffine>::Base: PrimeField<Repr = [u8; 0x20]>,
M::Scalar: PrimeField<Repr = [u8; 0x20]>,
<M::G1Affine as CurveAffine>::ScalarExt: PrimeField<Repr = [u8; 0x20]>,
{
fn min_k() -> u32 {
9
Expand All @@ -566,22 +566,19 @@ mod halo2 {
let instances = if let Some(acc_encoding) = acc_encoding {
random_accumulator_limbs::<M>(acc_encoding, rng)
} else {
iter::repeat_with(|| M::Scalar::random(&mut rng))
iter::repeat_with(|| M::Fr::random(&mut rng))
.take(10)
.collect()
};
Self { instances }
}

fn instances(&self) -> Vec<M::Scalar> {
fn instances(&self) -> Vec<M::Fr> {
self.instances.clone()
}
}

impl<M: MultiMillerLoop> Circuit<M::Scalar> for MainGateWithRange<M>
where
M::Scalar: PrimeField,
{
impl<M: MultiMillerLoop> Circuit<M::Fr> for MainGateWithRange<M> {
type Config = MainGateWithRangeConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "halo2_circuit_params")]
Expand All @@ -591,14 +588,14 @@ mod halo2 {
unimplemented!()
}

fn configure(meta: &mut ConstraintSystem<M::Scalar>) -> Self::Config {
fn configure(meta: &mut ConstraintSystem<M::Fr>) -> Self::Config {
MainGateWithRangeConfig::configure(meta, vec![8], vec![4, 7])
}

fn synthesize(
&self,
config: Self::Config,
mut layouter: impl Layouter<M::Scalar>,
mut layouter: impl Layouter<M::Fr>,
) -> Result<(), Error> {
let main_gate = config.main_gate();
let range_chip = config.range_chip();
Expand All @@ -618,25 +615,20 @@ mod halo2 {
// Dummy gates to make all fixed column with values
range_chip.decompose(
&mut ctx,
Value::known(M::Scalar::from(u64::MAX)),
Value::known(M::Fr::from(u64::MAX)),
8,
64,
)?;
range_chip.decompose(
&mut ctx,
Value::known(M::Scalar::from(u32::MAX as u64)),
Value::known(M::Fr::from(u32::MAX as u64)),
8,
39,
)?;
let a = &advices[0];
let b = main_gate.sub_sub_with_constant(
&mut ctx,
a,
a,
a,
M::Scalar::from(2),
)?;
let cond = main_gate.assign_bit(&mut ctx, Value::known(M::Scalar::ONE))?;
let b =
main_gate.sub_sub_with_constant(&mut ctx, a, a, a, M::Fr::from(2))?;
let cond = main_gate.assign_bit(&mut ctx, Value::known(M::Fr::ONE))?;
main_gate.select(&mut ctx, a, &b, &cond)?;

Ok(advices)
Expand Down
Loading