mirror of
https://github.com/vacp2p/research.git
synced 2025-02-22 11:18:15 +00:00
replicate circom output in ark-circom
This commit is contained in:
parent
09fa667858
commit
28942e9551
2713
circom-tests/ark-circom/poseidon/Cargo.lock
generated
Normal file
2713
circom-tests/ark-circom/poseidon/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
circom-tests/ark-circom/poseidon/Cargo.toml
Normal file
31
circom-tests/ark-circom/poseidon/Cargo.toml
Normal file
@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "poseidon"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
num-bigint = { version = "0.4", default-features = false, features = ["rand"] }
|
||||
|
||||
# ZKP Generation
|
||||
ark-ec = { version = "0.3.0", default-features = false, features = ["parallel"] }
|
||||
ark-std = { version = "0.3.0", default-features = false, features = ["parallel"] }
|
||||
ark-bn254 = { version = "0.3.0" }
|
||||
ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", features = ["parallel"] }
|
||||
ark-relations = { version = "0.3.0", default-features = false, features = [ "std" ] }
|
||||
ark-serialize = { version = "0.3.0", default-features = false }
|
||||
|
||||
ark-circom = { git = "https://github.com/gakonst/ark-circom", features = ["circom-2"] }
|
||||
|
||||
# error handling
|
||||
color-eyre = "0.5"
|
||||
|
||||
# decoding of data
|
||||
|
||||
# tracing
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.2"
|
||||
|
||||
# json
|
||||
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
|
||||
serde_json = "1.0.48"
|
BIN
circom-tests/ark-circom/poseidon/circuit/poseidon.r1cs
Normal file
BIN
circom-tests/ark-circom/poseidon/circuit/poseidon.r1cs
Normal file
Binary file not shown.
BIN
circom-tests/ark-circom/poseidon/circuit/poseidon.wasm
Normal file
BIN
circom-tests/ark-circom/poseidon/circuit/poseidon.wasm
Normal file
Binary file not shown.
1
circom-tests/ark-circom/poseidon/inputs/input.json
Normal file
1
circom-tests/ark-circom/poseidon/inputs/input.json
Normal file
@ -0,0 +1 @@
|
||||
{"inputs": ["0","1","2"]}
|
85
circom-tests/ark-circom/poseidon/src/main.rs
Normal file
85
circom-tests/ark-circom/poseidon/src/main.rs
Normal file
@ -0,0 +1,85 @@
|
||||
use ark_circom::{CircomBuilder, CircomConfig};
|
||||
use ark_std::rand::thread_rng;
|
||||
use color_eyre::Result;
|
||||
|
||||
use ark_bn254::Bn254;
|
||||
use ark_groth16::{
|
||||
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
|
||||
};
|
||||
|
||||
use std::fs;
|
||||
use num_bigint::BigInt;
|
||||
use num_bigint::BigUint;
|
||||
|
||||
// JSON
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WitnessInput {
|
||||
inputs: Vec<String>,
|
||||
}
|
||||
|
||||
fn test() -> Result<()> {
|
||||
|
||||
// Load JSON input
|
||||
let file = fs::File::open("./inputs/input.json").expect("file should open read only");
|
||||
let witness_input: WitnessInput = serde_json::from_reader(file).expect("file should be proper JSON");
|
||||
|
||||
println!("JSON Witness input: {:?}", witness_input);
|
||||
|
||||
// Load the WASM and R1CS for witness and proof generation
|
||||
let cfg = CircomConfig::<Bn254>::new(
|
||||
"./circuit/poseidon.wasm",
|
||||
"./circuit/poseidon.r1cs",
|
||||
)?;
|
||||
|
||||
// Insert our public inputs as (key,value) pairs
|
||||
let mut builder = CircomBuilder::new(cfg);
|
||||
|
||||
println!("Witness inputs: ");
|
||||
for v in witness_input.inputs.iter() {
|
||||
builder.push_input(
|
||||
"inputs",
|
||||
BigInt::parse_bytes(v.as_bytes(), 10).unwrap(),
|
||||
);
|
||||
println!("{:?}", BigInt::parse_bytes(v.as_bytes(), 10).unwrap());
|
||||
}
|
||||
|
||||
// Create an empty instance for setting it up
|
||||
let circom = builder.setup();
|
||||
|
||||
// Run a trusted setup
|
||||
let mut rng = thread_rng();
|
||||
let params = generate_random_parameters::<Bn254, _, _>(circom, &mut rng)?;
|
||||
|
||||
// Get the populated instance of the circuit with the witness
|
||||
let circom = builder.build()?;
|
||||
|
||||
let inputs = circom.get_public_inputs().unwrap();
|
||||
|
||||
println!("Public circuit inputs/outputs: ");
|
||||
for i in 0..inputs.len() {
|
||||
let x: BigUint = inputs[i].into();
|
||||
println!("{:#?}", x);
|
||||
}
|
||||
|
||||
// Generate the proof
|
||||
let proof = create_random_proof(circom, ¶ms, &mut rng)?;
|
||||
|
||||
// Check that the proof is valid
|
||||
let pvk = prepare_verifying_key(¶ms.vk);
|
||||
let verified = verify_proof(&pvk, &proof, &inputs)?;
|
||||
assert!(verified);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("testing ark-circom poseidon hash");
|
||||
|
||||
match test() {
|
||||
Ok(_) => println!("Success"),
|
||||
Err(_) => println!("Error"),
|
||||
}
|
||||
}
|
BIN
circom-tests/circom2/poseidon/keys/poseidon_0000.zkey
Normal file
BIN
circom-tests/circom2/poseidon/keys/poseidon_0000.zkey
Normal file
Binary file not shown.
BIN
circom-tests/circom2/poseidon/keys/poseidon_0001.zkey
Normal file
BIN
circom-tests/circom2/poseidon/keys/poseidon_0001.zkey
Normal file
Binary file not shown.
94
circom-tests/circom2/poseidon/keys/verification_key.json
Normal file
94
circom-tests/circom2/poseidon/keys/verification_key.json
Normal file
@ -0,0 +1,94 @@
|
||||
{
|
||||
"protocol": "groth16",
|
||||
"curve": "bn128",
|
||||
"nPublic": 1,
|
||||
"vk_alpha_1": [
|
||||
"17811426811026775423715949773346611361519959036438295168310256963720849611409",
|
||||
"8991431919645034503700165103946696346396348963629432784760193813032507792385",
|
||||
"1"
|
||||
],
|
||||
"vk_beta_2": [
|
||||
[
|
||||
"18342976191124269924428707527373222632343107149273361084873250036969334041735",
|
||||
"14922646947233114294058733819261214633087217985825814126948014889496001804788"
|
||||
],
|
||||
[
|
||||
"13705359878704837903844862646254280197293118260300251925865115460161424306511",
|
||||
"6756480820738800434504084341601892140901645987556168293663713574781828414190"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_gamma_2": [
|
||||
[
|
||||
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
||||
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
||||
],
|
||||
[
|
||||
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
||||
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_delta_2": [
|
||||
[
|
||||
"19788911690291458458055872402905506007046321339877415645760160032900462649089",
|
||||
"9510564762410525749755734729616094215748197077009195132689117304902272565739"
|
||||
],
|
||||
[
|
||||
"8476955023752111976216321167114838317230975351962177801256667012672815517651",
|
||||
"9433794121641785571198196716635274627745284205726928902541289634341989517881"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"vk_alphabeta_12": [
|
||||
[
|
||||
[
|
||||
"21803740754664560729381979833292855202244236500204965035241527022237295589969",
|
||||
"21812411968965361846244950088325492519422614044668578697570796542536386752830"
|
||||
],
|
||||
[
|
||||
"17421861008034102317679707969167217773719035213670950469051161061885566828021",
|
||||
"14668236179771817880278407454802833615250360689091276939420941390048701529290"
|
||||
],
|
||||
[
|
||||
"9281745680282082492951609350545571554199646767964541565726811883576451091167",
|
||||
"10916645933712737155646546773735961200105293264479402575017770739772518748092"
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
"21310508109588986934975528988854373096462996028019738122966306306963523026259",
|
||||
"19996895506411754446673957147741506758334338802649384569385285142789405444348"
|
||||
],
|
||||
[
|
||||
"2977379213730304334431770366152326805862398482889965408795752667920290410648",
|
||||
"4796010009168029028873404369433192215528688152151943409938741255898575615860"
|
||||
],
|
||||
[
|
||||
"3466988024786871178240705070637117356831811192126597419357093413024298305407",
|
||||
"21887162264774839370902933000963252776777739390813867130264831196127341298143"
|
||||
]
|
||||
]
|
||||
],
|
||||
"IC": [
|
||||
[
|
||||
"20414479658143290498518873484929403818046076922384305151436363190685559691545",
|
||||
"7827830757359088403023667970038934359871055885997612583308160079966473229553",
|
||||
"1"
|
||||
],
|
||||
[
|
||||
"2829018055723971937912822145171100268144273147454736695248990880772360877527",
|
||||
"18309478345694185036882841014578788787127726647956322557350102685305043855118",
|
||||
"1"
|
||||
]
|
||||
]
|
||||
}
|
28
circom-tests/circom2/poseidon/proofs/proof.json
Normal file
28
circom-tests/circom2/poseidon/proofs/proof.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"pi_a": [
|
||||
"20087426381607271022709811935591273847144833933965636990870961356420380597616",
|
||||
"20902004658683431003530106956603668749123054231071644294970085786947151405598",
|
||||
"1"
|
||||
],
|
||||
"pi_b": [
|
||||
[
|
||||
"13320240991478777816318339827737371318072375399356636194518968837939562203060",
|
||||
"12666429435967008891419130067768080196611416229945419962020924108156365022700"
|
||||
],
|
||||
[
|
||||
"16831722698586584557358932052624891377928696356459599378744277552453399310060",
|
||||
"9057823443142227941219683413234540385278893432556720402286113306935179480604"
|
||||
],
|
||||
[
|
||||
"1",
|
||||
"0"
|
||||
]
|
||||
],
|
||||
"pi_c": [
|
||||
"2074756419519965818063948242929124536827167770011217262320448858340815066376",
|
||||
"534516276540688833257870681772794936200255395048670109034114195715924206325",
|
||||
"1"
|
||||
],
|
||||
"protocol": "groth16",
|
||||
"curve": "bn128"
|
||||
}
|
3
circom-tests/circom2/poseidon/proofs/public.json
Normal file
3
circom-tests/circom2/poseidon/proofs/public.json
Normal file
@ -0,0 +1,3 @@
|
||||
[
|
||||
"8599452571108419911675042369134657596129797276905188988960674134744449929238"
|
||||
]
|
BIN
circom-tests/circom2/poseidon/witness/witness.wtns
Normal file
BIN
circom-tests/circom2/poseidon/witness/witness.wtns
Normal file
Binary file not shown.
@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
CIRCOM_BASE=~/circom2
|
||||
CIRCOM_BASE=./
|
||||
rm -rf $CIRCOM_BASE/powersoftau
|
||||
mkdir -p $CIRCOM_BASE/powersoftau
|
||||
cd $CIRCOM_BASE/powersoftau
|
||||
snarkjs powersoftau new bn128 12 pot12_0000.ptau
|
||||
openssl rand -base64 64 > rand.input
|
||||
snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" < rand.input
|
||||
rm rand.input
|
||||
rm rand.input
|
Loading…
x
Reference in New Issue
Block a user