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

Generic transcript #3

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ark-ec.workspace = true
ark-poly.workspace = true
ark-serialize.workspace = true
fflonk.workspace = true
merlin.workspace = true
merlin = { workspace = true, optional = true }
rayon = { workspace = true, optional = true }
getrandom_or_panic = { version = "0.0.3", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
Expand All @@ -31,7 +31,7 @@ std = [
"ark-poly/std",
"ark-serialize/std",
"fflonk/std",
"merlin/std",
"merlin?/std",
"getrandom_or_panic/std"
]
parallel = [
Expand Down
9 changes: 5 additions & 4 deletions common/src/transcript.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use ark_ff::PrimeField;
use ark_poly::GeneralEvaluationDomain;
use ark_serialize::CanonicalSerialize;
use ark_std::{vec, vec::Vec};
use ark_std::rand::SeedableRng;
use ark_std::vec::Vec;
use fflonk::pcs::{PCS, PcsParams};
use rand_chacha::ChaCha20Rng;

Expand Down Expand Up @@ -66,6 +65,7 @@ pub trait Transcript<F: PrimeField, CS: PCS<F>>: Clone {
fn to_rng(self) -> ChaCha20Rng;
}

#[cfg(feature = "merlin")]
impl<F: PrimeField, CS: PCS<F>> Transcript<F, CS> for merlin::Transcript {
fn _128_bit_point(&mut self, label: &'static [u8]) -> F {
let mut buf = [0u8; 16];
Expand All @@ -74,14 +74,15 @@ impl<F: PrimeField, CS: PCS<F>> Transcript<F, CS> for merlin::Transcript {
}

fn _add_serializable(&mut self, label: &'static [u8], message: &impl CanonicalSerialize) {
let mut buf = vec![0; message.uncompressed_size()];
let mut buf = ark_std::vec![0; message.uncompressed_size()];
message.serialize_uncompressed(&mut buf).unwrap();
self.append_message(label, &buf);
}

fn to_rng(mut self) -> ChaCha20Rng {
use ark_std::rand::SeedableRng;
let mut buf = [0u8; 32];
self.challenge_bytes(b"transcript_rng", &mut buf);
ChaCha20Rng::from_seed(buf)
}
}
}
10 changes: 8 additions & 2 deletions ring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ ark-ec.workspace = true
ark-poly.workspace = true
ark-serialize.workspace = true
fflonk.workspace = true
merlin.workspace = true
merlin = { workspace = true, optional = true }
rayon = { workspace = true, optional = true }
common = { path = "../common", default-features = false }
blake2 = { version = "0.10", default-features = false }
arrayvec = { version = "0.7", default-features = false }

[dev-dependencies]
merlin.workspace = true
common = { path = "../common", features = ["merlin"] }
ark-bls12-381 = { version = "0.4", default-features = false, features = ["curve"] }
ark-ed-on-bls12-381-bandersnatch = { version = "0.4", default-features = false }

Expand All @@ -32,7 +34,7 @@ std = [
"ark-ec/std",
"ark-poly/std",
"ark-serialize/std",
"merlin/std",
"merlin?/std",
"fflonk/std",
"common/std"
]
Expand All @@ -50,6 +52,10 @@ print-trace = [
"ark-std/print-trace",
"common/print-trace"
]
merlin = [
"dep:merlin",
"common/merlin"
]
asm = [
"fflonk/asm"
]
1 change: 1 addition & 0 deletions ring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub type RingProof<F, CS> = Proof<F, CS, RingCommitments<F, <CS as PCS<F>>::C>,
pub use fflonk::pcs;

/// Transcript for `RingProver` and `RingVerifier` construction.
#[cfg(feature = "merlin")]
pub use merlin::Transcript;

// Calling the method for a prime-order curve results in an infinite loop.
Expand Down
24 changes: 18 additions & 6 deletions ring/src/ring_prover.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
use ark_ec::short_weierstrass::{Affine, SWCurveConfig};
use ark_ff::PrimeField;
use fflonk::pcs::PCS;

use common::transcript::Transcript;
use common::prover::PlonkProver;
use fflonk::pcs::PCS;

use crate::piop::{FixedColumns, PiopProver, ProverKey};
use crate::piop::params::PiopParams;
use crate::RingProof;

pub struct RingProver<F: PrimeField, CS: PCS<F>, Curve: SWCurveConfig<BaseField=F>> {
pub struct RingProver<F, CS, Curve, T>
where
F: PrimeField,
CS: PCS<F>,
Curve: SWCurveConfig<BaseField=F>,
T: Transcript<F, CS>
{
piop_params: PiopParams<F, Curve>,
fixed_columns: FixedColumns<F, Affine<Curve>>,
k: usize,
plonk_prover: PlonkProver<F, CS, merlin::Transcript>,
plonk_prover: PlonkProver<F, CS, T>,
}


impl<F: PrimeField, CS: PCS<F>, Curve: SWCurveConfig<BaseField=F>> RingProver<F, CS, Curve> {
impl<F, CS, Curve, T> RingProver<F, CS, Curve, T>
where
F: PrimeField,
CS: PCS<F>,
Curve: SWCurveConfig<BaseField=F>,
T: Transcript<F, CS>
{
pub fn init(prover_key: ProverKey<F, CS, Affine<Curve>>,
piop_params: PiopParams<F, Curve>,
k: usize,
empty_transcript: merlin::Transcript,
empty_transcript: T,
) -> Self {
let ProverKey { pcs_ck, fixed_columns, verifier_key } = prover_key;

Expand Down
21 changes: 17 additions & 4 deletions ring/src/ring_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ark_ec::CurveGroup;
use ark_ec::short_weierstrass::{Affine, SWCurveConfig};
use ark_ff::PrimeField;
use common::transcript::Transcript;
use fflonk::pcs::{PCS, RawVerifierKey};

use common::domain::EvaluatedDomain;
Expand All @@ -11,16 +12,28 @@ use crate::piop::{FixedColumnsCommitted, PiopVerifier, VerifierKey};
use crate::piop::params::PiopParams;
use crate::RingProof;

pub struct RingVerifier<F: PrimeField, CS: PCS<F>, Curve: SWCurveConfig<BaseField=F>> {
pub struct RingVerifier<F, CS, Curve, T>
where
F: PrimeField,
CS: PCS<F>,
Curve: SWCurveConfig<BaseField=F>,
T: Transcript<F, CS>,
{
piop_params: PiopParams<F, Curve>,
fixed_columns_committed: FixedColumnsCommitted<F, CS::C>,
plonk_verifier: PlonkVerifier<F, CS, merlin::Transcript>,
plonk_verifier: PlonkVerifier<F, CS, T>,
}

impl<F: PrimeField, CS: PCS<F>, Curve: SWCurveConfig<BaseField=F>> RingVerifier<F, CS, Curve> {
impl<F, CS, Curve, T> RingVerifier<F, CS, Curve, T>
where
F: PrimeField,
CS: PCS<F>,
Curve: SWCurveConfig<BaseField=F>,
T: Transcript<F, CS>,
{
pub fn init(verifier_key: VerifierKey<F, CS>,
piop_params: PiopParams<F, Curve>,
empty_transcript: merlin::Transcript,
empty_transcript: T,
) -> Self {
let pcs_vk = verifier_key.pcs_raw_vk.prepare();
let plonk_verifier = PlonkVerifier::init(pcs_vk, &verifier_key, empty_transcript);
Expand Down
Loading