From 2dd5d4244e24347865901a1aeb0232c30f4bd904 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Mon, 12 Aug 2024 11:10:51 -0400 Subject: [PATCH] Bump plonky2 --- Cargo.lock | 14 ++++---- Cargo.toml | 6 ++-- evm_arithmetization/src/all_stark.rs | 5 +++ .../src/fixed_recursive_verifier.rs | 32 +++++++++++-------- evm_arithmetization/src/verifier.rs | 8 +++-- 5 files changed, 39 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85268325c..8c1ab44e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3620,7 +3620,7 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "plonky2" version = "0.2.2" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=dc77c77f2b06500e16ad4d7f1c2b057903602eed#dc77c77f2b06500e16ad4d7f1c2b057903602eed" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=349beae1431ecffc1bf8c044d6c00e2bf194b74a#349beae1431ecffc1bf8c044d6c00e2bf194b74a" dependencies = [ "ahash", "anyhow", @@ -3631,7 +3631,7 @@ dependencies = [ "log", "num", "plonky2_field", - "plonky2_maybe_rayon 0.2.0 (git+https://github.com/0xPolygonZero/plonky2.git?rev=dc77c77f2b06500e16ad4d7f1c2b057903602eed)", + "plonky2_maybe_rayon 0.2.0 (git+https://github.com/0xPolygonZero/plonky2.git?rev=349beae1431ecffc1bf8c044d6c00e2bf194b74a)", "plonky2_util", "rand", "rand_chacha", @@ -3644,7 +3644,7 @@ dependencies = [ [[package]] name = "plonky2_field" version = "0.2.2" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=dc77c77f2b06500e16ad4d7f1c2b057903602eed#dc77c77f2b06500e16ad4d7f1c2b057903602eed" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=349beae1431ecffc1bf8c044d6c00e2bf194b74a#349beae1431ecffc1bf8c044d6c00e2bf194b74a" dependencies = [ "anyhow", "itertools 0.11.0", @@ -3668,7 +3668,7 @@ dependencies = [ [[package]] name = "plonky2_maybe_rayon" version = "0.2.0" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=dc77c77f2b06500e16ad4d7f1c2b057903602eed#dc77c77f2b06500e16ad4d7f1c2b057903602eed" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=349beae1431ecffc1bf8c044d6c00e2bf194b74a#349beae1431ecffc1bf8c044d6c00e2bf194b74a" dependencies = [ "rayon", ] @@ -3676,7 +3676,7 @@ dependencies = [ [[package]] name = "plonky2_util" version = "0.2.0" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=dc77c77f2b06500e16ad4d7f1c2b057903602eed#dc77c77f2b06500e16ad4d7f1c2b057903602eed" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=349beae1431ecffc1bf8c044d6c00e2bf194b74a#349beae1431ecffc1bf8c044d6c00e2bf194b74a" [[package]] name = "plotters" @@ -4695,7 +4695,7 @@ checksum = "8acdd7dbfcfb5dd6e46c63512508bf71c2043f70b8f143813ad75cb5e8a589f2" [[package]] name = "starky" version = "0.4.0" -source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=dc77c77f2b06500e16ad4d7f1c2b057903602eed#dc77c77f2b06500e16ad4d7f1c2b057903602eed" +source = "git+https://github.com/0xPolygonZero/plonky2.git?rev=349beae1431ecffc1bf8c044d6c00e2bf194b74a#349beae1431ecffc1bf8c044d6c00e2bf194b74a" dependencies = [ "ahash", "anyhow", @@ -4704,7 +4704,7 @@ dependencies = [ "log", "num-bigint", "plonky2", - "plonky2_maybe_rayon 0.2.0 (git+https://github.com/0xPolygonZero/plonky2.git?rev=dc77c77f2b06500e16ad4d7f1c2b057903602eed)", + "plonky2_maybe_rayon 0.2.0 (git+https://github.com/0xPolygonZero/plonky2.git?rev=349beae1431ecffc1bf8c044d6c00e2bf194b74a)", "plonky2_util", ] diff --git a/Cargo.toml b/Cargo.toml index 9628a345c..5203fbc02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -126,10 +126,10 @@ rpc = { path = "zero_bin/rpc", default-features = false } zero_bin_common = { path = "zero_bin/common", default-features = false } # plonky2-related dependencies -plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" } +plonky2 = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "349beae1431ecffc1bf8c044d6c00e2bf194b74a" } plonky2_maybe_rayon = "0.2.0" -plonky2_util = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" } -starky = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "dc77c77f2b06500e16ad4d7f1c2b057903602eed" } +plonky2_util = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "349beae1431ecffc1bf8c044d6c00e2bf194b74a" } +starky = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "349beae1431ecffc1bf8c044d6c00e2bf194b74a" } # proc macro related dependencies proc-macro2 = "1.0" diff --git a/evm_arithmetization/src/all_stark.rs b/evm_arithmetization/src/all_stark.rs index f37021897..2993c85e7 100644 --- a/evm_arithmetization/src/all_stark.rs +++ b/evm_arithmetization/src/all_stark.rs @@ -145,6 +145,11 @@ impl Table { } } +/// The total number of CTLs used by the zkEVM. +pub(crate) const NUM_CTLS: usize = if cfg!(feature = "cdk_erigon") { 13 } else { 10 }; +/// The position of the Memory CTL within all CTLs of the zkEVM. +pub(crate) const MEMORY_CTL_IDX: usize = 6; + /// Returns all the `CrossTableLookups` used for proving the EVM. pub(crate) fn all_cross_table_lookups() -> Vec> { vec![ diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index be9a3daeb..bb9317e8d 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -35,7 +35,9 @@ use starky::lookup::{get_grand_product_challenge_set_target, GrandProductChallen use starky::proof::StarkProofWithMetadata; use starky::stark::Stark; -use crate::all_stark::{all_cross_table_lookups, AllStark, Table, NUM_TABLES}; +use crate::all_stark::{ + all_cross_table_lookups, AllStark, Table, MEMORY_CTL_IDX, NUM_CTLS, NUM_TABLES, +}; use crate::cpu::kernel::aggregator::KERNEL; use crate::generation::segments::{GenerationSegmentData, SegmentDataIterator, SegmentError}; use crate::generation::{GenerationInputs, TrimmedGenerationInputs}; @@ -885,26 +887,30 @@ where // Extra sums to add to the looked last value. // Only necessary for the Memory values. - let mut extra_looking_sums = - vec![vec![builder.zero(); stark_config.num_challenges]; NUM_TABLES]; + let mut extra_looking_sums = HashMap::from_iter( + (0..NUM_CTLS).map(|i| (i, vec![builder.zero(); stark_config.num_challenges])), + ); // Memory - extra_looking_sums[*Table::Memory] = (0..stark_config.num_challenges) - .map(|c| { - get_memory_extra_looking_sum_circuit( - &mut builder, - &public_values, - ctl_challenges.challenges[c], - ) - }) - .collect_vec(); + extra_looking_sums.insert( + MEMORY_CTL_IDX, + (0..stark_config.num_challenges) + .map(|c| { + get_memory_extra_looking_sum_circuit( + &mut builder, + &public_values, + ctl_challenges.challenges[c], + ) + }) + .collect_vec(), + ); // Verify the CTL checks. verify_cross_table_lookups_circuit::( &mut builder, all_cross_table_lookups(), pis.map(|p| p.ctl_zs_first), - Some(&extra_looking_sums), + &extra_looking_sums, stark_config, ); diff --git a/evm_arithmetization/src/verifier.rs b/evm_arithmetization/src/verifier.rs index 89220b607..b213f2aae 100644 --- a/evm_arithmetization/src/verifier.rs +++ b/evm_arithmetization/src/verifier.rs @@ -1,5 +1,6 @@ use anyhow::{ensure, Result}; use ethereum_types::{BigEndianHash, U256}; +use hashbrown::HashMap; use itertools::Itertools; use plonky2::field::extension::Extendable; use plonky2::field::polynomial::PolynomialValues; @@ -15,7 +16,7 @@ use starky::lookup::GrandProductChallenge; use starky::stark::Stark; use starky::verifier::verify_stark_proof_with_challenges; -use crate::all_stark::{AllStark, Table, NUM_TABLES}; +use crate::all_stark::{AllStark, Table, MEMORY_CTL_IDX, NUM_CTLS, NUM_TABLES}; use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; use crate::memory::segments::Segment; @@ -248,7 +249,8 @@ fn verify_proof, C: GenericConfig, const // Extra sums to add to the looked last value. // Only necessary for the Memory values. - let mut extra_looking_sums = vec![vec![F::ZERO; config.num_challenges]; NUM_TABLES]; + let mut extra_looking_sums = + HashMap::from_iter((0..NUM_CTLS).map(|i| (i, vec![F::ZERO; config.num_challenges]))); // Memory extra_looking_sums[*Table::Memory] = (0..config.num_challenges) @@ -261,7 +263,7 @@ fn verify_proof, C: GenericConfig, const .multi_proof .stark_proofs .map(|p| p.proof.openings.ctl_zs_first.unwrap()), - Some(&extra_looking_sums), + &extra_looking_sums, config, ) }