ziesha-network / school Goto Github PK
View Code? Open in Web Editor NEWSchool of Zero-Knowledge cryptography!
License: MIT License
School of Zero-Knowledge cryptography!
License: MIT License
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.