Skip to content

Commit eca8f63

Browse files
refactor: remove ark_halo2_interop module (#1010)
# Rationale for this change A previous PR updated the HyperKZG commitment scheme to run without the Blitzar feature flag. In order to do this, a new module `ark_halo2_interop` was copied from the Blitzar-rs project. This was not necessary since functions that did the same work already existed in the HyperKZG proof primitive. This PR removes the `ark_halo2_interop` module and replaces the appropriate functions with functions from the `halo2_conversions` module. # What changes are included in this PR? - The `ark_halo2_interop` module is removed - Functions in `halo2_conversions` module are made public and replace functions that use to be found in the `ark_halo2_interop` module # Are these changes tested? Yes
2 parents 06e8a00 + 5b749b7 commit eca8f63

File tree

6 files changed

+26
-101
lines changed

6 files changed

+26
-101
lines changed

crates/proof-of-sql/src/proof_primitive/hyperkzg/arkworks_halo2_interop.rs

Lines changed: 0 additions & 77 deletions
This file was deleted.

crates/proof-of-sql/src/proof_primitive/hyperkzg/commitment_evaluation_proof.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{BNScalar, HyperKZGCommitment, HyperKZGEngine, HyperKZGPublicSetup};
22
use crate::{
33
base::{commitment::CommitmentEvaluationProof, slice_ops},
44
proof_primitive::hyperkzg::{
5-
convert_to_halo2_bn256_g1_affine, nova_commitment::NovaCommitment,
5+
convert_g1_affine_from_ark_to_halo2, nova_commitment::NovaCommitment,
66
},
77
};
88
use ark_bn254::{G1Affine, G1Projective};
@@ -81,7 +81,7 @@ impl CommitmentEvaluationProof for HyperKZGCommitmentEvaluationProof {
8181

8282
let span = span!(Level::DEBUG, "initialize nova_ck").entered();
8383
let nova_ck: CommitmentKey<HyperKZGEngine> = CommitmentKey::new(
84-
slice_ops::slice_cast_with(setup, convert_to_halo2_bn256_g1_affine),
84+
slice_ops::slice_cast_with(setup, convert_g1_affine_from_ark_to_halo2),
8585
Affine::default(), // I'm pretty sure this is unused in the proof
8686
G2Affine::default(), // I'm pretty sure this is unused in the proof
8787
);
@@ -127,7 +127,7 @@ impl CommitmentEvaluationProof for HyperKZGCommitmentEvaluationProof {
127127
.fold(G1Projective::default(), Add::add)
128128
.into();
129129
let nova_commit = nova_snark::provider::hyperkzg::Commitment::new(
130-
convert_to_halo2_bn256_g1_affine(&commit).into(),
130+
convert_g1_affine_from_ark_to_halo2(&commit).into(),
131131
);
132132
let nova_eval = evaluations
133133
.iter()

crates/proof-of-sql/src/proof_primitive/hyperkzg/halo2_conversions.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use halo2curves::group::prime::PrimeCurveAffine;
2+
13
fn convert_limbs_to_halo2_fq(value: [u64; 4]) -> halo2curves::bn256::Fq {
24
unsafe { core::mem::transmute(value) }
35
}
@@ -24,18 +26,23 @@ fn convert_fr_from_halo2_to_ark(field: halo2curves::bn256::Fr) -> ark_bn254::Fr
2426
ark_ff::Fp::new_unchecked(ark_ff::BigInt(convert_halo2_fr_to_limbs(field)))
2527
}
2628

27-
fn convert_g1_affine_from_halo2_to_ark(point: halo2curves::bn256::G1Affine) -> ark_bn254::G1Affine {
28-
use halo2curves::group::prime::PrimeCurveAffine;
29-
if point == halo2curves::bn256::G1Affine::identity() {
29+
/// Converts a Halo2 BN256 G1 Affine point to an Arkworks BN254 G1 Affine point.
30+
pub fn convert_g1_affine_from_halo2_to_ark(
31+
point: &halo2curves::bn256::G1Affine,
32+
) -> ark_bn254::G1Affine {
33+
if point.is_identity().into() {
3034
ark_bn254::G1Affine::identity()
3135
} else {
3236
let x = convert_fq_from_halo2_to_ark(point.x);
3337
let y = convert_fq_from_halo2_to_ark(point.y);
3438
ark_bn254::G1Affine::new_unchecked(x, y)
3539
}
3640
}
37-
fn convert_g1_affine_from_ark_to_halo2(point: ark_bn254::G1Affine) -> halo2curves::bn256::G1Affine {
38-
use halo2curves::group::prime::PrimeCurveAffine;
41+
42+
/// Converts an Arkworks BN254 G1 Affine point to a Halo2 BN256 G1 Affine point.
43+
pub fn convert_g1_affine_from_ark_to_halo2(
44+
point: &ark_bn254::G1Affine,
45+
) -> halo2curves::bn256::G1Affine {
3946
if point.infinity {
4047
halo2curves::bn256::G1Affine::identity()
4148
} else {
@@ -48,13 +55,13 @@ fn convert_g1_affine_from_ark_to_halo2(point: ark_bn254::G1Affine) -> halo2curve
4855
impl From<&super::HyperKZGCommitment> for halo2curves::bn256::G1Affine {
4956
fn from(commitment: &super::HyperKZGCommitment) -> Self {
5057
use ark_ec::CurveGroup;
51-
convert_g1_affine_from_ark_to_halo2(commitment.commitment.into_affine())
58+
convert_g1_affine_from_ark_to_halo2(&commitment.commitment.into_affine())
5259
}
5360
}
5461
impl From<halo2curves::bn256::G1Affine> for super::HyperKZGCommitment {
5562
fn from(point: halo2curves::bn256::G1Affine) -> Self {
5663
use ark_ec::AffineRepr;
57-
let commitment = convert_g1_affine_from_halo2_to_ark(point).into_group();
64+
let commitment = convert_g1_affine_from_halo2_to_ark(&point).into_group();
5865
Self { commitment }
5966
}
6067
}

crates/proof-of-sql/src/proof_primitive/hyperkzg/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ pub use public_setup::{
2222
mod commitment;
2323
pub use commitment::HyperKZGCommitment;
2424

25-
#[cfg(feature = "hyperkzg_proof")]
26-
mod arkworks_halo2_interop;
27-
#[cfg(feature = "hyperkzg_proof")]
28-
pub(crate) use arkworks_halo2_interop::{
29-
convert_to_ark_bn254_g1_affine, convert_to_halo2_bn256_g1_affine,
30-
};
31-
3225
#[cfg(feature = "hyperkzg_proof")]
3326
mod nova_commitment;
3427

@@ -44,6 +37,10 @@ pub use commitment_evaluation_proof::HyperKZGCommitmentEvaluationProof;
4437

4538
#[cfg(feature = "hyperkzg_proof")]
4639
mod halo2_conversions;
40+
#[cfg(feature = "hyperkzg_proof")]
41+
pub(crate) use halo2_conversions::{
42+
convert_g1_affine_from_ark_to_halo2, convert_g1_affine_from_halo2_to_ark,
43+
};
4744

4845
#[cfg(all(test, feature = "hyperkzg_proof"))]
4946
mod evm_tests;

crates/proof-of-sql/src/proof_primitive/hyperkzg/nova_commitment.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ mod tests {
1414
scalar::Scalar,
1515
},
1616
proof_primitive::hyperkzg::{
17-
nova_commitment_key_to_hyperkzg_public_setup, BNScalar, HyperKZGCommitment,
17+
convert_g1_affine_from_ark_to_halo2, nova_commitment_key_to_hyperkzg_public_setup,
18+
BNScalar, HyperKZGCommitment,
1819
},
1920
};
2021
use ark_bn254::G1Affine;
@@ -30,10 +31,7 @@ mod tests {
3031

3132
fn ark_to_nova_commitment(commitment: HyperKZGCommitment) -> NovaCommitment {
3233
NovaCommitment::new(
33-
blitzar::compute::convert_to_halo2_bn256_g1_affine(&G1Affine::from(
34-
commitment.commitment,
35-
))
36-
.into(),
34+
convert_g1_affine_from_ark_to_halo2(&G1Affine::from(commitment.commitment)).into(),
3735
)
3836
}
3937

crates/proof-of-sql/src/proof_primitive/hyperkzg/nova_engine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
proof::{Keccak256Transcript, Transcript},
55
slice_ops,
66
},
7-
proof_primitive::hyperkzg::convert_to_ark_bn254_g1_affine,
7+
proof_primitive::hyperkzg::convert_g1_affine_from_halo2_to_ark,
88
};
99
use nova_snark::{
1010
errors::NovaError,
@@ -55,5 +55,5 @@ impl TranscriptEngineTrait<HyperKZGEngine> for Keccak256Transcript {
5555
pub fn nova_commitment_key_to_hyperkzg_public_setup(
5656
setup: &CommitmentKey<HyperKZGEngine>,
5757
) -> HyperKZGPublicSetupOwned {
58-
slice_ops::slice_cast_with(setup.ck(), convert_to_ark_bn254_g1_affine)
58+
slice_ops::slice_cast_with(setup.ck(), convert_g1_affine_from_halo2_to_ark)
5959
}

0 commit comments

Comments
 (0)