mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-04 06:43:09 +00:00
keccak plonky2 implementation from polygon zk_evm
This commit is contained in:
parent
658faf232e
commit
86daf7b08d
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -16,3 +16,6 @@
|
|||||||
[submodule "hash/risc0/external/risc0"]
|
[submodule "hash/risc0/external/risc0"]
|
||||||
path = hash/risc0/external/risc0
|
path = hash/risc0/external/risc0
|
||||||
url = https://github.com/risc0/risc0.git
|
url = https://github.com/risc0/risc0.git
|
||||||
|
[submodule "hash/plonky2/external/zk_evm"]
|
||||||
|
path = hash/plonky2/external/zk_evm
|
||||||
|
url = https://github.com/hashcloak/zk_evm.git
|
||||||
|
|||||||
@ -8,14 +8,14 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
# TODO: This can be later changed to original github
|
# TODO: This can be later changed to original github
|
||||||
plonky2_u32 ={ git = "https://github.com/man2706kum/plonky2-u32.git"}
|
plonky2_u32 ={ git = "https://github.com/hashcloak/plonky2-u32.git"}
|
||||||
plonky2 = "0.2.2"
|
plonky2 = "0.2.2"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
tiny-keccak={version="2.0.2", features=["keccak"]}
|
tiny-keccak={version="2.0.2", features=["keccak"]}
|
||||||
hex="0.4.3"
|
hex="0.4.3"
|
||||||
evm_arithmetization ={ git = "https://github.com/0xPolygonZero/zk_evm.git", rev = "a5b92b2b2bcc7bbf8725190aaa0fba7007e51a6a"}
|
evm_arithmetization ={ path = "../external/zk_evm/evm_arithmetization" }
|
||||||
starky ={ git = "https://github.com/0xPolygonZero/plonky2.git", rev = "0e363e16a37a2eacd3349946bd071a460485ad26"}
|
starky = "0.4.0"
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11.3"
|
||||||
log = "0.4.21"
|
log = "0.4.21"
|
||||||
|
|||||||
@ -1,93 +1,101 @@
|
|||||||
use evm_arithmetization::keccak::keccak_stark::KeccakStark;
|
use evm_arithmetization::keccak::keccak_stark::KeccakStark;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
|
||||||
use plonky2::field::types::PrimeField64;
|
|
||||||
use plonky2::fri::oracle::PolynomialBatch;
|
use plonky2::fri::oracle::PolynomialBatch;
|
||||||
use plonky2::iop::challenger::Challenger;
|
use plonky2::iop::challenger::Challenger;
|
||||||
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||||
use starky::config::StarkConfig;
|
|
||||||
use starky::cross_table_lookup::{CtlData, CtlZData};
|
use starky::cross_table_lookup::{CtlData, CtlZData};
|
||||||
use starky::lookup::{GrandProductChallenge, GrandProductChallengeSet};
|
use starky::lookup::{GrandProductChallenge, GrandProductChallengeSet};
|
||||||
use starky::stark_testing::{test_stark_circuit_constraints, test_stark_low_degree};
|
|
||||||
use tiny_keccak::keccakf;
|
|
||||||
use plonky2::field::polynomial::PolynomialValues;
|
use plonky2::field::polynomial::PolynomialValues;
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
use plonky2::timed;
|
use plonky2::timed;
|
||||||
use evm_arithmetization::testing_utils::init_logger;
|
// use evm_arithmetization::testing_utils::init_logger;
|
||||||
use plonky2::util::timing::TimingTree;
|
use plonky2::util::timing::TimingTree;
|
||||||
use evm_arithmetization::prover::prove_single_table;
|
use evm_arithmetization::prover::prove_single_table;
|
||||||
use starky::lookup::Filter;
|
use starky::lookup::Filter;
|
||||||
use starky::lookup::Column;
|
use starky::lookup::Column;
|
||||||
use rand::random;
|
use evm_arithmetization::StarkConfig;
|
||||||
const NUM_INPUTS: usize = 84;
|
// use starky::verifier::verify_stark_proof;
|
||||||
|
// use starky::prover::prove;
|
||||||
|
use env_logger::DEFAULT_FILTER_ENV;
|
||||||
|
use env_logger::Env;
|
||||||
|
use env_logger::try_init_from_env;
|
||||||
|
|
||||||
pub fn keccak_polygon_bench() -> Result<()> {
|
// use evm_arithmetization::prover::prove;
|
||||||
|
// use evm_arithmetization::generation::generate_traces;
|
||||||
|
// use evm_arithmetization::AllStark;
|
||||||
|
|
||||||
const NUM_PERMS: usize = 85;
|
const NUM_INPUTS: usize = 25;
|
||||||
const D: usize = 2;
|
|
||||||
type C = PoseidonGoldilocksConfig;
|
|
||||||
type F = <C as GenericConfig<D>>::F;
|
|
||||||
type S = KeccakStark<F, D>;
|
|
||||||
let stark = S::default();
|
|
||||||
let config = StarkConfig::standard_fast_config();
|
|
||||||
|
|
||||||
init_logger();
|
pub fn keccak_polygon_bench(num_perms: usize) -> Result<()> {
|
||||||
|
|
||||||
let input: Vec<([u64; NUM_INPUTS], usize)> =
|
const D: usize = 2;
|
||||||
(0..NUM_PERMS).map(|_| (rand::random(), 0)).collect();
|
type C = PoseidonGoldilocksConfig;
|
||||||
|
type F = <C as GenericConfig<D>>::F;
|
||||||
|
type S = KeccakStark<F, D>;
|
||||||
|
let stark = S::default();
|
||||||
|
let config = StarkConfig::standard_fast_config();
|
||||||
|
|
||||||
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
init_logger();
|
||||||
let trace_poly_values = timed!(
|
|
||||||
timing,
|
|
||||||
"generate trace",
|
|
||||||
stark.generate_trace(input, 8, &mut timing)
|
|
||||||
);
|
|
||||||
|
|
||||||
let cloned_trace_poly_values = timed!(timing, "clone", trace_poly_values.clone());
|
let input: Vec<([u64; NUM_INPUTS], usize)> =
|
||||||
|
(0..num_perms).map(|_| (rand::random(), 0)).collect();
|
||||||
|
|
||||||
let trace_commitments = timed!(
|
let mut timing = TimingTree::new("prove", log::Level::Debug);
|
||||||
timing,
|
let trace_poly_values = timed!(
|
||||||
"compute trace commitment",
|
timing,
|
||||||
PolynomialBatch::<F, C, D>::from_values(
|
"generate trace",
|
||||||
cloned_trace_poly_values,
|
stark.generate_trace(input, 8, &mut timing)
|
||||||
config.fri_config.rate_bits,
|
);
|
||||||
false,
|
|
||||||
config.fri_config.cap_height,
|
|
||||||
&mut timing,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
let degree = 1 << trace_commitments.degree_log;
|
|
||||||
|
|
||||||
// Fake CTL data.
|
let cloned_trace_poly_values = timed!(timing, "clone", trace_poly_values.clone());
|
||||||
let ctl_z_data = CtlZData::new(
|
|
||||||
vec![PolynomialValues::zero(degree)],
|
|
||||||
PolynomialValues::zero(degree),
|
|
||||||
GrandProductChallenge {
|
|
||||||
beta: F::ZERO,
|
|
||||||
gamma: F::ZERO,
|
|
||||||
},
|
|
||||||
vec![],
|
|
||||||
vec![Filter::new_simple(Column::constant(F::ZERO))],
|
|
||||||
);
|
|
||||||
let ctl_data = CtlData {
|
|
||||||
zs_columns: vec![ctl_z_data.clone(); config.num_challenges],
|
|
||||||
};
|
|
||||||
|
|
||||||
prove_single_table(
|
let trace_commitments = timed!(
|
||||||
&stark,
|
timing,
|
||||||
&config,
|
"compute trace commitment",
|
||||||
&trace_poly_values,
|
PolynomialBatch::<F, C, D>::from_values(
|
||||||
&trace_commitments,
|
cloned_trace_poly_values,
|
||||||
&ctl_data,
|
config.fri_config.rate_bits,
|
||||||
&GrandProductChallengeSet {
|
false,
|
||||||
challenges: vec![ctl_z_data.challenge; config.num_challenges],
|
config.fri_config.cap_height,
|
||||||
},
|
|
||||||
&mut Challenger::new(),
|
|
||||||
&mut timing,
|
&mut timing,
|
||||||
None,
|
None,
|
||||||
)?;
|
)
|
||||||
|
);
|
||||||
|
let degree = 1 << trace_commitments.degree_log;
|
||||||
|
|
||||||
timing.print();
|
// Fake CTL data.
|
||||||
Ok(())
|
let ctl_z_data = CtlZData::new(
|
||||||
|
vec![PolynomialValues::zero(degree)],
|
||||||
|
PolynomialValues::zero(degree),
|
||||||
|
GrandProductChallenge {
|
||||||
|
beta: F::ZERO,
|
||||||
|
gamma: F::ZERO,
|
||||||
|
},
|
||||||
|
vec![],
|
||||||
|
vec![Filter::new_simple(Column::constant(F::ZERO))],
|
||||||
|
);
|
||||||
|
let ctl_data = CtlData {
|
||||||
|
zs_columns: vec![ctl_z_data.clone(); config.num_challenges],
|
||||||
|
};
|
||||||
|
|
||||||
|
prove_single_table(
|
||||||
|
&stark,
|
||||||
|
&config,
|
||||||
|
&trace_poly_values,
|
||||||
|
&trace_commitments,
|
||||||
|
&ctl_data,
|
||||||
|
&GrandProductChallengeSet {
|
||||||
|
challenges: vec![ctl_z_data.challenge; config.num_challenges],
|
||||||
|
},
|
||||||
|
&mut Challenger::new(),
|
||||||
|
&mut timing,
|
||||||
|
None,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
timing.print();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_logger() {
|
||||||
|
let _ = try_init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "debug"));
|
||||||
}
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
use std::process;
|
use std::process;
|
||||||
mod bench{
|
mod bench{
|
||||||
pub mod poseidon;
|
pub mod poseidon;
|
||||||
@ -13,7 +14,7 @@ mod bench{
|
|||||||
|
|
||||||
pub mod keccak256{
|
pub mod keccak256{
|
||||||
pub mod keccak;
|
pub mod keccak;
|
||||||
// pub mod keccak_polygon;
|
pub mod keccak_polygon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +27,8 @@ mod arithmetic {
|
|||||||
use bench::poseidon::poseidon_bench;
|
use bench::poseidon::poseidon_bench;
|
||||||
use bench::keccak256::keccak::keccak_bench;
|
use bench::keccak256::keccak::keccak_bench;
|
||||||
use bench::sha256::sha::sha256_bench;
|
use bench::sha256::sha::sha256_bench;
|
||||||
|
use bench::keccak256::keccak_polygon::keccak_polygon_bench;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
@ -53,6 +56,13 @@ fn main() {
|
|||||||
let _ = keccak_bench(size);
|
let _ = keccak_bench(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"keccak-polygon" => {
|
||||||
|
println!("Running keccak of plolygon zk_evm: ");
|
||||||
|
eprintln!("number of permutation: {:?}", size);
|
||||||
|
let _ = keccak_polygon_bench(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
"sha256" => {
|
"sha256" => {
|
||||||
println!("Running sha256: ");
|
println!("Running sha256: ");
|
||||||
let _ = sha256_bench(size);
|
let _ = sha256_bench(size);
|
||||||
|
|||||||
1
hash/plonky2/external/zk_evm
vendored
Submodule
1
hash/plonky2/external/zk_evm
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 29f8620338f2b3bb8be62def5666a2d9d7ba5331
|
||||||
Loading…
x
Reference in New Issue
Block a user