mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
working cradle!
This commit is contained in:
@@ -179,6 +179,22 @@ class Contract:
|
||||
self.params = params
|
||||
self.program = program
|
||||
|
||||
def _includes(self):
|
||||
return \
|
||||
r"""use bellman::{
|
||||
gadgets::{
|
||||
boolean,
|
||||
boolean::{AllocatedBit, Boolean},
|
||||
multipack,
|
||||
},
|
||||
groth16, Circuit, ConstraintSystem, SynthesisError,
|
||||
};
|
||||
use bls12_381::Bls12;
|
||||
use ff::{PrimeField, Field};
|
||||
use group::Curve;
|
||||
use zcash_proofs::circuit::ecc;
|
||||
"""
|
||||
|
||||
def _compile_header(self):
|
||||
code = "pub struct %s {\n" % to_initial_caps(self.name)
|
||||
for param_name, param_type in self.params.items():
|
||||
@@ -293,7 +309,7 @@ r"""let %s = ecc::fixed_base_multiplication(
|
||||
cs.namespace(|| "%s"),
|
||||
&%s,
|
||||
&%s,
|
||||
)?;""" % (out, line, fr, base)
|
||||
)?;""" % (out, line, base, fr)
|
||||
elif command == "emit_ec":
|
||||
point = args[0]
|
||||
return '%s.inputize(cs.namespace(|| "%s"))?;' % (point, line)
|
||||
@@ -323,6 +339,8 @@ r"""let %s = ecc::fixed_base_multiplication(
|
||||
self.constants = constants
|
||||
code = ""
|
||||
|
||||
code += self._includes()
|
||||
|
||||
self.rename_consts = {}
|
||||
if "constants" in aux:
|
||||
for const_name, value in aux["constants"].items():
|
||||
@@ -353,7 +371,9 @@ r"""impl Circuit<bls12_381::Scalar> for %s {
|
||||
if (body := self._compile_body()) is None:
|
||||
return None
|
||||
code += body
|
||||
code += "Ok(())\n"
|
||||
|
||||
code += " }\n"
|
||||
code += "}\n"
|
||||
|
||||
return code
|
||||
|
||||
@@ -7,54 +7,30 @@ use bellman::{
|
||||
groth16, Circuit, ConstraintSystem, SynthesisError,
|
||||
};
|
||||
use bls12_381::Bls12;
|
||||
use ff::{PrimeField, Field};
|
||||
use ff::{Field, PrimeField};
|
||||
use group::Curve;
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use zcash_proofs::constants::{
|
||||
SPENDING_KEY_GENERATOR
|
||||
};
|
||||
|
||||
//pub const CRH_IVK_PERSONALIZATION: &[u8; 8] = b"Zcashivk";
|
||||
|
||||
struct MyCircuit {
|
||||
secret: Option<jubjub::Fr>
|
||||
}
|
||||
|
||||
impl Circuit<bls12_381::Scalar> for MyCircuit {
|
||||
fn synthesize<CS: ConstraintSystem<bls12_381::Scalar>>(
|
||||
self, cs: &mut CS) -> Result<(), SynthesisError> {
|
||||
|
||||
let secret = boolean::field_into_boolean_vec_le(cs.namespace(|| "secret"), self.secret)?;
|
||||
|
||||
let public = zcash_proofs::circuit::ecc::fixed_base_multiplication(
|
||||
cs.namespace(|| "public"),
|
||||
&SPENDING_KEY_GENERATOR,
|
||||
&secret,
|
||||
)?;
|
||||
|
||||
public.inputize(cs.namespace(|| "public"))
|
||||
}
|
||||
}
|
||||
mod simple_circuit;
|
||||
use simple_circuit::InputSpend;
|
||||
|
||||
fn main() {
|
||||
use jubjub::*;
|
||||
use jubjub::SubgroupPoint;
|
||||
use core::ops::{MulAssign, Mul};
|
||||
use core::ops::{Mul, MulAssign};
|
||||
use ff::PrimeField;
|
||||
use group::{Group, GroupEncoding};
|
||||
use jubjub::SubgroupPoint;
|
||||
use jubjub::*;
|
||||
use rand::rngs::OsRng;
|
||||
//let ak = jubjub::SubgroupPoint::random(&mut OsRng);
|
||||
|
||||
let secret: jubjub::Fr = jubjub::Fr::random(&mut OsRng);
|
||||
let public = zcash_primitives::constants::SPENDING_KEY_GENERATOR * secret;
|
||||
|
||||
let params = {
|
||||
let c = MyCircuit { secret: None };
|
||||
let c = InputSpend { secret: None };
|
||||
groth16::generate_random_parameters::<Bls12, _, _>(c, &mut OsRng).unwrap()
|
||||
};
|
||||
let pvk = groth16::prepare_verifying_key(¶ms.vk);
|
||||
|
||||
let c = MyCircuit {
|
||||
let c = InputSpend {
|
||||
secret: Some(secret),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user