Remove cs from proof api
This commit is contained in:
parent
fc1bdf2148
commit
ab33ff017b
@ -50,8 +50,8 @@ mod tests {
|
||||
assert!(!cs.test(&[10.into()], &[6.into(), 2.into()]));
|
||||
|
||||
let kp = Keypair::new(&cs);
|
||||
let proof = Proof::new(&kp, &cs, &[10.into()], &[5.into(), 2.into()]);
|
||||
assert!(proof.verify(&kp, &cs, &[10.into()]));
|
||||
let proof = Proof::new(&kp, &[10.into()], &[5.into(), 2.into()]);
|
||||
assert!(proof.verify(&kp, &[10.into()]));
|
||||
}
|
||||
{
|
||||
let mut cs = ConstraintSystem::new(0, 1);
|
||||
@ -66,8 +66,8 @@ mod tests {
|
||||
assert!(!cs.test(&[], &[2.into()]));
|
||||
|
||||
let kp = Keypair::new(&cs);
|
||||
let proof = Proof::new(&kp, &cs, &[], &[1.into()]);
|
||||
assert!(proof.verify(&kp, &cs, &[]));
|
||||
let proof = Proof::new(&kp, &[], &[1.into()]);
|
||||
assert!(proof.verify(&kp, &[]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +75,17 @@ impl ConstraintSystem {
|
||||
struct R1CSKeypair;
|
||||
|
||||
pub struct Keypair {
|
||||
kp: *mut R1CSKeypair
|
||||
kp: *mut R1CSKeypair,
|
||||
primary_size: usize,
|
||||
aux_size: usize
|
||||
}
|
||||
|
||||
impl Keypair {
|
||||
pub fn new(constraint_system: &ConstraintSystem) -> Keypair {
|
||||
Keypair {
|
||||
kp: unsafe { tinysnark_gen_keypair(constraint_system.cs) }
|
||||
kp: unsafe { tinysnark_gen_keypair(constraint_system.cs) },
|
||||
primary_size: constraint_system.primary_size,
|
||||
aux_size: constraint_system.aux_size
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,22 +109,24 @@ pub struct Proof {
|
||||
}
|
||||
|
||||
impl Proof {
|
||||
pub fn new(keypair: &Keypair, constraint_system: &ConstraintSystem, primary: &[FieldT], aux: &[FieldT])
|
||||
pub fn new(keypair: &Keypair, primary: &[FieldT], aux: &[FieldT])
|
||||
-> Proof
|
||||
{
|
||||
assert_eq!(primary.len(), constraint_system.primary_size);
|
||||
assert_eq!(aux.len(), constraint_system.aux_size);
|
||||
assert_eq!(primary.len(), keypair.primary_size);
|
||||
assert_eq!(aux.len(), keypair.aux_size);
|
||||
|
||||
unsafe {
|
||||
Proof {
|
||||
proof: tinysnark_gen_proof(keypair.kp, constraint_system.cs, primary.get_unchecked(0), aux.get_unchecked(0))
|
||||
proof: tinysnark_gen_proof(keypair.kp, primary.get_unchecked(0), aux.get_unchecked(0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify(&self, keypair: &Keypair, constraint_system: &ConstraintSystem, primary: &[FieldT]) -> bool {
|
||||
pub fn verify(&self, keypair: &Keypair, primary: &[FieldT]) -> bool {
|
||||
assert_eq!(primary.len(), keypair.primary_size);
|
||||
|
||||
unsafe {
|
||||
tinysnark_verify_proof(self.proof, keypair.kp, constraint_system.cs, primary.get_unchecked(0))
|
||||
tinysnark_verify_proof(self.proof, keypair.kp, primary.get_unchecked(0))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -133,12 +139,10 @@ impl Drop for Proof {
|
||||
|
||||
extern "C" {
|
||||
fn tinysnark_gen_proof(keypair: *mut R1CSKeypair,
|
||||
cs: *mut R1ConstraintSystem,
|
||||
primary: *const FieldT,
|
||||
aux: *const FieldT) -> *mut R1CSProof;
|
||||
fn tinysnark_verify_proof(proof: *mut R1CSProof,
|
||||
keypair: *mut R1CSKeypair,
|
||||
cs: *mut R1ConstraintSystem,
|
||||
primary: *const FieldT) -> bool;
|
||||
fn tinysnark_drop_proof(proof: *mut R1CSProof);
|
||||
}
|
@ -18,12 +18,11 @@ struct tinysnark_linear_term {
|
||||
size_t index;
|
||||
};
|
||||
|
||||
extern "C" void * tinysnark_gen_proof(void * kp, void * ics, FieldT* primary, FieldT* aux) {
|
||||
r1cs_constraint_system<FieldT>* cs = static_cast<r1cs_constraint_system<FieldT>*>(ics);
|
||||
extern "C" void * tinysnark_gen_proof(void * kp, FieldT* primary, FieldT* aux) {
|
||||
r1cs_ppzksnark_keypair<default_r1cs_ppzksnark_pp>* keypair = static_cast<r1cs_ppzksnark_keypair<default_r1cs_ppzksnark_pp>*>(kp);
|
||||
|
||||
r1cs_primary_input<FieldT> primary_input(primary, primary+(cs->primary_input_size));
|
||||
r1cs_auxiliary_input<FieldT> aux_input(aux, aux+(cs->auxiliary_input_size));
|
||||
r1cs_primary_input<FieldT> primary_input(primary, primary+(keypair->pk.constraint_system.primary_input_size));
|
||||
r1cs_auxiliary_input<FieldT> aux_input(aux, aux+(keypair->pk.constraint_system.auxiliary_input_size));
|
||||
|
||||
auto proof = new r1cs_ppzksnark_proof<default_r1cs_ppzksnark_pp>(
|
||||
r1cs_ppzksnark_prover<default_r1cs_ppzksnark_pp>(keypair->pk, primary_input, aux_input)
|
||||
@ -32,12 +31,11 @@ extern "C" void * tinysnark_gen_proof(void * kp, void * ics, FieldT* primary, Fi
|
||||
return static_cast<void*>(std::move(proof));
|
||||
}
|
||||
|
||||
extern "C" bool tinysnark_verify_proof(void * iproof, void * kp, void * ics, FieldT* primary) {
|
||||
extern "C" bool tinysnark_verify_proof(void * iproof, void * kp, FieldT* primary) {
|
||||
r1cs_ppzksnark_proof<default_r1cs_ppzksnark_pp>* proof = static_cast<r1cs_ppzksnark_proof<default_r1cs_ppzksnark_pp>*>(iproof);
|
||||
r1cs_constraint_system<FieldT>* cs = static_cast<r1cs_constraint_system<FieldT>*>(ics);
|
||||
r1cs_ppzksnark_keypair<default_r1cs_ppzksnark_pp>* keypair = static_cast<r1cs_ppzksnark_keypair<default_r1cs_ppzksnark_pp>*>(kp);
|
||||
|
||||
r1cs_primary_input<FieldT> primary_input(primary, primary+(cs->primary_input_size));
|
||||
r1cs_primary_input<FieldT> primary_input(primary, primary+(keypair->pk.constraint_system.primary_input_size));
|
||||
|
||||
return r1cs_ppzksnark_verifier_strong_IC<default_r1cs_ppzksnark_pp>(keypair->vk, primary_input, *proof);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user