Skip to content

Commit

Permalink
Expose ring commitment
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Jul 2, 2024
1 parent 3b4b359 commit ccdb004
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ark-bls12-381 = { version = "0.4.0", default-features = false, optional = true }
sha2 = { version = "0.10", default-features = false }
# Ring VRF (waiting for crates.io)
fflonk = { git = "https://github.com/w3f/fflonk", default-features = false, optional = true }
ring-proof = { package = "ring", git = "https://github.com/w3f/ring-proof", rev = "b273d33", default-features = false, optional = true }
ring-proof = { package = "ring", git = "https://github.com/davxy/ring-proof", branch = "extended", default-features = false, optional = true }

[dev-dependencies]
ark-ed25519 = "0.4"
Expand Down Expand Up @@ -78,3 +78,6 @@ full = [
"curves",
"ring",
]
test-vectors = [
"ring-proof?/test-vectors"
]
55 changes: 27 additions & 28 deletions src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ use crate::*;
use ark_ec::short_weierstrass::SWCurveConfig;
use pedersen::{PedersenSuite, Proof as PedersenProof};

pub mod prelude {
pub use fflonk;
pub use ring_proof;
}

#[cfg(feature = "parallel")]
use rayon::prelude::*;

Expand All @@ -12,29 +17,40 @@ pub trait RingSuite: PedersenSuite {
}

/// KZG Polynomial Commitment Scheme.
type Pcs<S> = fflonk::pcs::kzg::KZG<<S as RingSuite>::Pairing>;
pub type Pcs<S> = fflonk::pcs::kzg::KZG<<S as RingSuite>::Pairing>;

/// KZG commitment.
pub type PcsCommitment<S> = fflonk::pcs::kzg::commitment::KzgCommitment<<S as RingSuite>::Pairing>;

/// KZG Setup Parameters.
/// KZG setup parameters.
///
/// Basically the powers of tau URS.
type PcsParams<S> = fflonk::pcs::kzg::urs::URS<<S as RingSuite>::Pairing>;
/// Basically the powers of tau SRS.
pub type PcsParams<S> = fflonk::pcs::kzg::urs::URS<<S as RingSuite>::Pairing>;

/// Ring proof application specific setup parameters.
pub type PiopParams<S> = ring_proof::PiopParams<BaseField<S>, CurveConfig<S>>;

/// Ring keys commitment.
pub type RingCommitment<S> = ring_proof::FixedColumnsCommitted<BaseField<S>, PcsCommitment<S>>;

/// Ring prover key.
pub type ProverKey<S> =
ring_proof::ProverKey<BaseField<S>, Pcs<S>, ark_ec::short_weierstrass::Affine<CurveConfig<S>>>;

/// Ring verifier key.
pub type VerifierKey<S> = ring_proof::VerifierKey<BaseField<S>, Pcs<S>>;

/// Ring prover.
pub type RingProver<S> = ring_proof::ring_prover::RingProver<BaseField<S>, Pcs<S>, CurveConfig<S>>;

/// Ring verifier.
pub type RingVerifier<S> =
ring_proof::ring_verifier::RingVerifier<BaseField<S>, Pcs<S>, CurveConfig<S>>;

/// Ring proof.
pub type RingProof<S> = ring_proof::RingProof<BaseField<S>, Pcs<S>>;

pub type PiopParams<S> = ring_proof::PiopParams<BaseField<S>, CurveConfig<S>>;

const TRANSCRIPT_LABEL: &[u8] = b"";

/// Ring proof.
#[derive(Clone, CanonicalSerialize, CanonicalDeserialize)]
pub struct Proof<S: RingSuite>
where
Expand Down Expand Up @@ -147,7 +163,7 @@ where
pub fn new_random<R: ark_std::rand::RngCore>(domain_size: usize, rng: &mut R) -> Self {
use fflonk::pcs::PCS;

let pcs_params = <Pcs<S>>::setup(3 * domain_size, rng);
let pcs_params = Pcs::<S>::setup(3 * domain_size, rng);
let piop_params = make_piop_params::<S>(domain_size);
Self {
pcs_params,
Expand Down Expand Up @@ -185,15 +201,15 @@ where
prover_key,
self.piop_params.clone(),
key_index,
merlin::Transcript::new(TRANSCRIPT_LABEL),
merlin::Transcript::new(b""),
)
}

pub fn verifier(&self, verifier_key: VerifierKey<S>) -> RingVerifier<S> {
RingVerifier::<S>::init(
verifier_key,
self.piop_params.clone(),
merlin::Transcript::new(TRANSCRIPT_LABEL),
merlin::Transcript::new(b""),
)
}
}
Expand Down Expand Up @@ -287,20 +303,3 @@ where
S::COMPLEMENT_POINT.into_sw(),
)
}

pub fn make_ring_verifier<S: RingSuite>(
verifier_key: VerifierKey<S>,
domain_size: usize,
) -> RingVerifier<S>
where
BaseField<S>: ark_ff::PrimeField,
CurveConfig<S>: SWCurveConfig,
AffinePoint<S>: IntoSW<CurveConfig<S>>,
{
let piop_params = make_piop_params::<S>(domain_size);
RingVerifier::<S>::init(
verifier_key,
piop_params,
merlin::Transcript::new(TRANSCRIPT_LABEL),
)
}

0 comments on commit ccdb004

Please sign in to comment.