style: cargo fmt

This commit is contained in:
Oskar Thoren 2022-03-16 14:18:54 +08:00
parent 6717a24c07
commit 292ece2945
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
8 changed files with 28 additions and 50 deletions

View File

@ -39,10 +39,7 @@ pub extern "C" fn new_circuit(ctx: *mut *mut Multiplier) -> bool {
}
#[no_mangle]
pub extern "C" fn prove(
ctx: *const Multiplier,
output_buffer: *mut Buffer
) -> bool {
pub extern "C" fn prove(ctx: *const Multiplier, output_buffer: *mut Buffer) -> bool {
println!("multiplier ffi: prove");
let mul = unsafe { &*ctx };
let mut output_data: Vec<u8> = Vec::new();

View File

@ -39,10 +39,7 @@ pub extern "C" fn new_circuit(ctx: *mut *mut Multiplier) -> bool {
}
#[no_mangle]
pub extern "C" fn prove(
ctx: *const Multiplier,
output_buffer: *mut Buffer
) -> bool {
pub extern "C" fn prove(ctx: *const Multiplier, output_buffer: *mut Buffer) -> bool {
println!("multiplier ffi: prove");
let mul = unsafe { &*ctx };
let mut output_data: Vec<u8> = Vec::new();

View File

@ -10,8 +10,8 @@ use ark_groth16::{
use num_bigint::BigInt;
// Tracing
use tracing::{span, event, Level};
use ark_relations::r1cs::{ConstraintTrace, ConstraintLayer, ConstraintSystem, TracingMode};
use ark_relations::r1cs::{ConstraintLayer, ConstraintSystem, ConstraintTrace, TracingMode};
use tracing::{event, span, Level};
use tracing_subscriber::layer::SubscriberExt;
// JSON
@ -34,7 +34,6 @@ struct WitnessInput {
// Poseidon-tornado
fn groth16_proof_example() -> Result<()> {
// Tracing to help with debugging
let mut layer = ConstraintLayer::default();
layer.mode = TracingMode::OnlyConstraints;
@ -44,10 +43,7 @@ fn groth16_proof_example() -> Result<()> {
let trace = ConstraintTrace::capture();
println!("Trace is: {:?}", trace);
let cfg = CircomConfig::<Bn254>::new(
"./resources/withdraw.wasm",
"./resources/withdraw.r1cs",
)?;
let cfg = CircomConfig::<Bn254>::new("./resources/withdraw.wasm", "./resources/withdraw.r1cs")?;
// Test
let trace = ConstraintTrace::capture();
@ -89,7 +85,8 @@ fn groth16_proof_example() -> Result<()> {
"pathIndices": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}
"#;
let witness_input : WitnessInput = serde_json::from_str(input_json_str).expect("JSON was not well-formatted");
let witness_input: WitnessInput =
serde_json::from_str(input_json_str).expect("JSON was not well-formatted");
println!("Witness input JSON: {:?}", witness_input);
@ -122,20 +119,19 @@ fn groth16_proof_example() -> Result<()> {
// XXX
builder.push_input(
"fee",
witness_input.fee
//BigInt::parse_bytes(witness_input.fee.as_bytes(), 10).unwrap(),
witness_input.fee, //BigInt::parse_bytes(witness_input.fee.as_bytes(), 10).unwrap(),
);
builder.push_input(
builder.push_input(
"nullifier",
BigInt::parse_bytes(witness_input.nullifier.as_bytes(), 10).unwrap(),
);
for v in witness_input.path_elements.iter() {
builder.push_input(
"pathElements",
BigInt::parse_bytes(v.as_bytes(), 10).unwrap(),
);
builder.push_input(
"pathElements",
BigInt::parse_bytes(v.as_bytes(), 10).unwrap(),
);
}
for v in witness_input.path_indices.iter() {
@ -144,7 +140,7 @@ fn groth16_proof_example() -> Result<()> {
println!("Builder input:\n {:#?}", builder.inputs);
// create an empty instance for setting it up
// create an empty instance for setting it up
let circom = builder.setup();
let mut rng = thread_rng();

View File

@ -41,10 +41,7 @@ pub extern "C" fn new_circuit(ctx: *mut *mut RLN) -> bool {
#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[no_mangle]
pub extern "C" fn prove(
ctx: *const RLN,
output_buffer: *mut Buffer
) -> bool {
pub extern "C" fn prove(ctx: *const RLN, output_buffer: *mut Buffer) -> bool {
println!("RLN ffi: prove");
let mul = unsafe { &*ctx };
let mut output_data: Vec<u8> = Vec::new();

View File

@ -12,7 +12,7 @@ static POSEIDON: Lazy<Poseidon> = Lazy::new(Poseidon::new);
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Identity {
pub trapdoor: BigInt,
pub trapdoor: BigInt,
pub nullifier: BigInt,
}
@ -78,6 +78,5 @@ pub mod test {
let x = BigInt::from_str(s).unwrap();
assert!(id.commitment() == x);
}
}

View File

@ -1,4 +1,4 @@
pub mod ffi;
pub mod public;
pub mod identity;
pub mod public;
pub mod util;

View File

@ -10,8 +10,8 @@ use ark_groth16::{
use num_bigint::BigInt;
// Tracing
use tracing::{span, event, Level};
use ark_relations::r1cs::{ConstraintTrace, ConstraintLayer, ConstraintSystem, TracingMode};
use ark_relations::r1cs::{ConstraintLayer, ConstraintSystem, ConstraintTrace, TracingMode};
use tracing::{event, span, Level};
use tracing_subscriber::layer::SubscriberExt;
// JSON
@ -31,7 +31,6 @@ struct WitnessInput {
// RLN
fn groth16_proof_example() -> Result<()> {
// Tracing to help with debugging
let mut layer = ConstraintLayer::default();
layer.mode = TracingMode::OnlyConstraints;
@ -41,10 +40,7 @@ fn groth16_proof_example() -> Result<()> {
let trace = ConstraintTrace::capture();
println!("Trace is: {:?}", trace);
let cfg = CircomConfig::<Bn254>::new(
"./resources/rln.wasm",
"./resources/rln.r1cs",
)?;
let cfg = CircomConfig::<Bn254>::new("./resources/rln.wasm", "./resources/rln.r1cs")?;
// Test
let trace = ConstraintTrace::capture();
@ -95,7 +91,8 @@ fn groth16_proof_example() -> Result<()> {
}
"#;
let witness_input : WitnessInput = serde_json::from_str(input_json_str).expect("JSON was not well-formatted");
let witness_input: WitnessInput =
serde_json::from_str(input_json_str).expect("JSON was not well-formatted");
println!("Witness input JSON: {:?}", witness_input);
@ -117,7 +114,6 @@ fn groth16_proof_example() -> Result<()> {
builder.push_input("identity_path_index", BigInt::from(*v));
}
builder.push_input(
"x",
BigInt::parse_bytes(witness_input.x.as_bytes(), 10).unwrap(),
@ -139,7 +135,7 @@ fn groth16_proof_example() -> Result<()> {
println!("Builder input:\n {:#?}", builder.inputs);
// create an empty instance for setting it up
// create an empty instance for setting it up
let circom = builder.setup();
let mut rng = thread_rng();

View File

@ -17,8 +17,6 @@ use num_bigint::BigInt;
use serde::Deserialize;
use serde_json;
pub struct RLN {
circom: CircomCircuit<Bn254>,
params: ProvingKey<Bn254>,
@ -38,10 +36,8 @@ struct WitnessInput {
impl RLN {
// TODO Break this apart here
pub fn new() -> RLN {
let cfg = CircomConfig::<Bn254>::new(
"./resources/rln.wasm",
"./resources/rln.r1cs",
).unwrap();
let cfg =
CircomConfig::<Bn254>::new("./resources/rln.wasm", "./resources/rln.r1cs").unwrap();
// TODO Refactor
// From rln JSON witness
@ -89,7 +85,8 @@ impl RLN {
}
"#;
let witness_input : WitnessInput = serde_json::from_str(input_json_str).expect("JSON was not well-formatted");
let witness_input: WitnessInput =
serde_json::from_str(input_json_str).expect("JSON was not well-formatted");
println!("Witness input JSON: {:?}", witness_input);
@ -111,7 +108,6 @@ impl RLN {
builder.push_input("identity_path_index", BigInt::from(*v));
}
builder.push_input(
"x",
BigInt::parse_bytes(witness_input.x.as_bytes(), 10).unwrap(),
@ -123,7 +119,7 @@ impl RLN {
witness_input.epoch.strip_prefix("0x").unwrap().as_bytes(),
16,
)
.unwrap(),
.unwrap(),
);
builder.push_input(