mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-05 07:13:08 +00:00
initial commit for hash benchmarking using plonky2
This commit is contained in:
parent
09bfd1b8c0
commit
b1061b8daa
10
hash/plonky2/Cargo.toml
Normal file
10
hash/plonky2/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "plonky2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.79"
|
||||
plonky2 = "0.1.4"
|
||||
47
hash/plonky2/src/main.rs
Normal file
47
hash/plonky2/src/main.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use anyhow::Result;
|
||||
use plonky2::field::types::Field;
|
||||
use plonky2::hash::hash_types::RichField;
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
use plonky2::hash::keccak;
|
||||
use plonky2::hash::keccak::KeccakHash;
|
||||
use plonky2::hash::poseidon::PoseidonHash;
|
||||
use plonky2::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
||||
use plonky2::plonk::circuit_data::CircuitConfig;
|
||||
use plonky2::plonk::config::{AlgebraicHasher, GenericConfig, PoseidonGoldilocksConfig};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
// The arithmetic circuit.
|
||||
let initial = builder.add_virtual_target();
|
||||
let hash = builder.hash_or_noop::<PoseidonHash>(vec![initial]);
|
||||
|
||||
// Public inputs are the initial value (provided below) and the result (which is generated).
|
||||
builder.register_public_input(initial);
|
||||
builder.register_public_input(hash.elements[0]);
|
||||
builder.register_public_input(hash.elements[1]);
|
||||
builder.register_public_input(hash.elements[2]);
|
||||
builder.register_public_input(hash.elements[3]);
|
||||
|
||||
// Provide initial values.
|
||||
let mut pw = PartialWitness::new();
|
||||
pw.set_target(initial, F::ONE);
|
||||
|
||||
|
||||
let data = builder.build::<C>();
|
||||
let proof = data.prove(pw)?;
|
||||
|
||||
println!(
|
||||
"hash of {} is: {}",
|
||||
proof.public_inputs[0], proof.public_inputs[1]
|
||||
);
|
||||
|
||||
data.verify(proof)
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user