You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Keyvan, I tried to do that task by this way but when I run this code it panicks so I wanted to ask for your help
use bellman::groth16::{
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
};
use bellman::{Circuit, ConstraintSystem, SynthesisError};
use bls12_381::{Bls12, Scalar};
use ff::PrimeField;
use rand::thread_rng;
#[derive(Debug, Default, Clone)]
pub struct NotPrime<S: PrimeField> {
pub witness_p: Option<S>, // Secret ;)
pub witness_q: Option<S>, // Secret ;)
pub input_n: Option<S>, // Public :D
}
impl<S: PrimeField> Circuit<S> for NotPrime<S> {
fn synthesize<CS: ConstraintSystem<S>>(self, cs: &mut CS) -> Result<(), SynthesisError> {
let n = cs.alloc_input(
|| "n",
|| self.input_n.ok_or(SynthesisError::AssignmentMissing),
)?;
let p = cs.alloc(
|| "p",
|| self.witness_p.ok_or(SynthesisError::AssignmentMissing),
)?;
let q = cs.alloc(
|| "q",
|| self.witness_q.ok_or(SynthesisError::AssignmentMissing),
)?;
cs.enforce(|| "p * q == N", |lc| lc + p, |lc| lc + q, |lc| lc + n);
let pq_sum = cs.alloc(
|| "p + q",
|| {
let p = self.witness_p.unwrap();
let q = self.witness_q.unwrap();
Ok(p + q)
},
)?;
cs.enforce(
|| "p + q = pq_sum",
|lc| lc + p + q,
|lc| lc + CS::one(),
|lc| lc + pq_sum,
);
let pq_product = cs.alloc(
|| "p * q",
|| {
let p = self.witness_p.unwrap();
let q = self.witness_q.unwrap();
Ok(p * q)
},
)?;
cs.enforce(
|| "p * q = pq_product",
|lc| lc + p,
|lc| lc + q,
|lc| lc + pq_product,
);
cs.enforce(
|| "pq_product > pq_sum",
|lc| lc + pq_product,
|lc| lc + CS::one(),
|lc| lc + pq_sum,
);
Ok(())
}
}
fn main() {
let mut rng = thread_rng();
let params = {
let c = NotPrime {
witness_p: None,
witness_q: None,
input_n: None,
};
generate_random_parameters::<Bls12, _, _>(c, &mut rng).unwrap()
};
let pvk = prepare_verifying_key(¶ms.vk);
let c = NotPrime {
witness_p: Some(Scalar::from(123)),
witness_q: Some(Scalar::from(3)),
input_n: Some(Scalar::from(369)),
};
let proof = create_random_proof(c, ¶ms, &mut rng).unwrap();
let inputs = [Scalar::from(369)];
assert!(verify_proof(&pvk, &proof, &inputs).is_ok());
}
and the error is:
thread 'main' panicked at 'assertion failed: verify_proof(&pvk, &proof, &inputs).is_ok()', src/main.rs:97:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The text was updated successfully, but these errors were encountered:
Hi Keyvan, I tried to do that task by this way but when I run this code it panicks so I wanted to ask for your help
and the error is:
The text was updated successfully, but these errors were encountered: