pub mod batch_verifier;
pub mod prover;
pub mod verifier;
use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
use curve25519_dalek::scalar::Scalar;
use curve25519_dalek::traits::IsIdentity;
use crate::{ProofError, Transcript};
pub trait SchnorrCS {
type ScalarVar: Copy;
type PointVar: Copy;
fn constrain(
&mut self,
lhs: Self::PointVar,
linear_combination: Vec<(Self::ScalarVar, Self::PointVar)>,
);
}
pub trait TranscriptProtocol {
fn domain_sep(&mut self, label: &'static [u8]);
fn append_scalar_var(&mut self, label: &'static [u8]);
fn append_point_var(
&mut self,
label: &'static [u8],
point: &RistrettoPoint,
) -> CompressedRistretto;
fn validate_and_append_point_var(
&mut self,
label: &'static [u8],
point: &CompressedRistretto,
) -> Result<(), ProofError>;
fn append_blinding_commitment(
&mut self,
label: &'static [u8],
point: &RistrettoPoint,
) -> CompressedRistretto;
fn validate_and_append_blinding_commitment(
&mut self,
label: &'static [u8],
point: &CompressedRistretto,
) -> Result<(), ProofError>;
fn get_challenge(&mut self, label: &'static [u8]) -> Scalar;
}
impl TranscriptProtocol for Transcript {
fn domain_sep(&mut self, label: &'static [u8]) {
self.append_message(b"dom-sep", b"schnorrzkp/1.0/ristretto255");
self.append_message(b"dom-sep", label);
}
fn append_scalar_var(&mut self, label: &'static [u8]) {
self.append_message(b"scvar", label);
}
fn append_point_var(
&mut self,
label: &'static [u8],
point: &RistrettoPoint,
) -> CompressedRistretto {
let encoding = point.compress();
self.append_message(b"ptvar", label);
self.append_message(b"val", encoding.as_bytes());
encoding
}
fn validate_and_append_point_var(
&mut self,
label: &'static [u8],
point: &CompressedRistretto,
) -> Result<(), ProofError> {
if point.is_identity() {
return Err(ProofError::VerificationFailure);
}
self.append_message(b"ptvar", label);
self.append_message(b"val", point.as_bytes());
Ok(())
}
fn append_blinding_commitment(
&mut self,
label: &'static [u8],
point: &RistrettoPoint,
) -> CompressedRistretto {
let encoding = point.compress();
self.append_message(b"blindcom", label);
self.append_message(b"val", encoding.as_bytes());
encoding
}
fn validate_and_append_blinding_commitment(
&mut self,
label: &'static [u8],
point: &CompressedRistretto,
) -> Result<(), ProofError> {
if point.is_identity() {
return Err(ProofError::VerificationFailure);
}
self.append_message(b"blindcom", label);
self.append_message(b"val", point.as_bytes());
Ok(())
}
fn get_challenge(&mut self, label: &'static [u8]) -> Scalar {
let mut bytes = [0; 64];
self.challenge_bytes(label, &mut bytes);
Scalar::from_bytes_mod_order_wide(&bytes)
}
}