From f3f7433c29a3e12db5d13ff1ff9f09c48b3ef441 Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:21:38 -0500 Subject: [PATCH] Some cleanup (#1498) --- evm/src/all_stark.rs | 2 - evm/src/byte_packing/byte_packing_stark.rs | 3 +- evm/src/byte_packing/columns.rs | 4 -- evm/src/cpu/contextops.rs | 11 ++- evm/src/cpu/cpu_stark.rs | 2 +- evm/src/cpu/decode.rs | 1 - evm/src/cpu/dup_swap.rs | 1 - evm/src/cpu/kernel/assembler.rs | 1 - evm/src/cpu/kernel/constants/mod.rs | 1 - evm/src/cpu/kernel/cost_estimator.rs | 1 - evm/src/cpu/kernel/interpreter.rs | 72 +------------------ evm/src/cpu/kernel/tests/account_code.rs | 6 +- evm/src/cpu/kernel/tests/add11.rs | 8 +-- evm/src/cpu/kernel/tests/balance.rs | 2 +- evm/src/cpu/kernel/tests/exp.rs | 2 +- .../cpu/kernel/tests/kernel_consistency.rs | 3 - evm/src/cpu/kernel/tests/mpt/delete.rs | 2 +- evm/src/cpu/kernel/tests/mpt/hash.rs | 2 +- evm/src/cpu/kernel/tests/mpt/insert.rs | 2 +- evm/src/cpu/kernel/tests/mpt/load.rs | 3 +- evm/src/cpu/kernel/tests/mpt/read.rs | 2 +- evm/src/cpu/kernel/tests/receipt.rs | 5 +- evm/src/cpu/syscalls_exceptions.rs | 3 +- evm/src/cross_table_lookup.rs | 19 ++--- evm/src/fixed_recursive_verifier.rs | 6 -- evm/src/generation/mod.rs | 11 +-- evm/src/generation/mpt.rs | 3 - evm/src/generation/prover_input.rs | 45 +----------- evm/src/generation/state.rs | 4 +- evm/src/lookup.rs | 13 +--- evm/src/memory/segments.rs | 1 - evm/src/proof.rs | 3 +- evm/src/prover.rs | 1 - evm/src/recursive_verifier.rs | 5 +- evm/src/stark.rs | 1 - evm/src/verifier.rs | 2 +- evm/src/witness/operation.rs | 2 +- evm/src/witness/transition.rs | 2 +- 38 files changed, 38 insertions(+), 219 deletions(-) diff --git a/evm/src/all_stark.rs b/evm/src/all_stark.rs index d69ff302cf..cd7a2d3c38 100644 --- a/evm/src/all_stark.rs +++ b/evm/src/all_stark.rs @@ -1,7 +1,5 @@ -use core::iter; use core::ops::Deref; -use itertools::Itertools; use plonky2::field::extension::Extendable; use plonky2::field::types::Field; use plonky2::hash::hash_types::RichField; diff --git a/evm/src/byte_packing/byte_packing_stark.rs b/evm/src/byte_packing/byte_packing_stark.rs index 6520b8f7ae..ff7a18c06d 100644 --- a/evm/src/byte_packing/byte_packing_stark.rs +++ b/evm/src/byte_packing/byte_packing_stark.rs @@ -38,7 +38,6 @@ use plonky2::timed; use plonky2::util::timing::TimingTree; use plonky2::util::transpose; -use super::columns::BYTE_VALUES_RANGE; use super::NUM_BYTES; use crate::byte_packing::columns::{ index_len, value_bytes, ADDR_CONTEXT, ADDR_SEGMENT, ADDR_VIRTUAL, IS_READ, LEN_INDICES_COLS, @@ -62,7 +61,7 @@ pub(crate) fn ctl_looked_data() -> Vec> { // obtain the corresponding limb. let outputs: Vec> = (0..8) .map(|i| { - let range = (value_bytes(i * 4)..value_bytes(i * 4) + 4); + let range = value_bytes(i * 4)..value_bytes(i * 4) + 4; Column::linear_combination( range .enumerate() diff --git a/evm/src/byte_packing/columns.rs b/evm/src/byte_packing/columns.rs index ae58afc440..cbed53de1d 100644 --- a/evm/src/byte_packing/columns.rs +++ b/evm/src/byte_packing/columns.rs @@ -33,10 +33,6 @@ pub(crate) const fn value_bytes(i: usize) -> usize { BYTES_VALUES_START + i } -/// Range of columns containing the bytes values. -pub(crate) const BYTE_VALUES_RANGE: Range = - BYTES_VALUES_START..BYTES_VALUES_START + NUM_BYTES; - /// The counter column (used for the range check) starts from 0 and increments. pub(crate) const RANGE_COUNTER: usize = BYTES_VALUES_START + NUM_BYTES; /// The frequencies column used in logUp. diff --git a/evm/src/cpu/contextops.rs b/evm/src/cpu/contextops.rs index 7f46d1418f..ec4e5e5e6e 100644 --- a/evm/src/cpu/contextops.rs +++ b/evm/src/cpu/contextops.rs @@ -8,12 +8,9 @@ use plonky2::plonk::circuit_builder::CircuitBuilder; use super::columns::ops::OpsColumnsView; use super::cpu_stark::{disable_unused_channels, disable_unused_channels_circuit}; -use super::membus::NUM_GP_CHANNELS; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::cpu::columns::CpuColumnsView; -use crate::cpu::kernel::constants::context_metadata::ContextMetadata; use crate::memory::segments::Segment; -use crate::memory::VALUE_LIMBS; // If true, the instruction will keep the current context for the next row. // If false, next row's context is handled manually. @@ -88,7 +85,7 @@ fn eval_packed_get( // Context is scaled by 2^64, hence stored in the 3rd limb. yield_constr.constraint(filter * (new_stack_top[2] - lv.context)); - for (i, &limb) in new_stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { + for (_, &limb) in new_stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { yield_constr.constraint(filter * limb); } @@ -119,7 +116,7 @@ fn eval_ext_circuit_get, const D: usize>( yield_constr.constraint(builder, constr); } - for (i, &limb) in new_stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { + for (_, &limb) in new_stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { let constr = builder.mul_extension(filter, limb); yield_constr.constraint(builder, constr); } @@ -151,7 +148,7 @@ fn eval_packed_set( // The next row's context is read from stack_top. yield_constr.constraint(filter * (stack_top[2] - nv.context)); - for (i, &limb) in stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { + for (_, &limb) in stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { yield_constr.constraint(filter * limb); } @@ -199,7 +196,7 @@ fn eval_ext_circuit_set, const D: usize>( let constr = builder.mul_extension(filter, diff); yield_constr.constraint(builder, constr); } - for (i, &limb) in stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { + for (_, &limb) in stack_top.iter().enumerate().filter(|(i, _)| *i != 2) { let constr = builder.mul_extension(filter, limb); yield_constr.constraint(builder, constr); } diff --git a/evm/src/cpu/cpu_stark.rs b/evm/src/cpu/cpu_stark.rs index 9b6cb32949..8bcada2f3b 100644 --- a/evm/src/cpu/cpu_stark.rs +++ b/evm/src/cpu/cpu_stark.rs @@ -22,7 +22,7 @@ use crate::cpu::{ }; use crate::cross_table_lookup::TableWithColumns; use crate::evaluation_frame::{StarkEvaluationFrame, StarkFrame}; -use crate::lookup::{Column, Filter, Lookup}; +use crate::lookup::{Column, Filter}; use crate::memory::segments::Segment; use crate::memory::{NUM_CHANNELS, VALUE_LIMBS}; use crate::stark::Stark; diff --git a/evm/src/cpu/decode.rs b/evm/src/cpu/decode.rs index 831f95ffaf..4c2c43221e 100644 --- a/evm/src/cpu/decode.rs +++ b/evm/src/cpu/decode.rs @@ -3,7 +3,6 @@ use plonky2::field::packed::PackedField; use plonky2::field::types::Field; use plonky2::hash::hash_types::RichField; use plonky2::iop::ext_target::ExtensionTarget; -use plonky2::plonk::circuit_builder::CircuitBuilder; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::cpu::columns::{CpuColumnsView, COL_MAP}; diff --git a/evm/src/cpu/dup_swap.rs b/evm/src/cpu/dup_swap.rs index 7b9d80f37c..1abec5fc61 100644 --- a/evm/src/cpu/dup_swap.rs +++ b/evm/src/cpu/dup_swap.rs @@ -6,7 +6,6 @@ use plonky2::hash::hash_types::RichField; use plonky2::iop::ext_target::ExtensionTarget; use plonky2::plonk::circuit_builder::CircuitBuilder; -use super::membus::NUM_GP_CHANNELS; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::cpu::columns::{CpuColumnsView, MemoryChannelView}; use crate::memory::segments::Segment; diff --git a/evm/src/cpu/kernel/assembler.rs b/evm/src/cpu/kernel/assembler.rs index 7a546e7703..2dc79d6111 100644 --- a/evm/src/cpu/kernel/assembler.rs +++ b/evm/src/cpu/kernel/assembler.rs @@ -431,7 +431,6 @@ fn push_target_size(target: &PushTarget) -> u8 { #[cfg(test)] mod tests { use super::*; - use crate::cpu::kernel::assembler::*; use crate::cpu::kernel::parser::parse; #[test] diff --git a/evm/src/cpu/kernel/constants/mod.rs b/evm/src/cpu/kernel/constants/mod.rs index f6f021db76..82c820f054 100644 --- a/evm/src/cpu/kernel/constants/mod.rs +++ b/evm/src/cpu/kernel/constants/mod.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use ethereum_types::U256; use hex_literal::hex; -use static_assertions::const_assert; use crate::cpu::kernel::constants::context_metadata::ContextMetadata; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; diff --git a/evm/src/cpu/kernel/cost_estimator.rs b/evm/src/cpu/kernel/cost_estimator.rs index fdfeee5603..70cc726772 100644 --- a/evm/src/cpu/kernel/cost_estimator.rs +++ b/evm/src/cpu/kernel/cost_estimator.rs @@ -1,4 +1,3 @@ -use super::opcodes::get_opcode; use crate::cpu::kernel::assembler::BYTES_PER_OFFSET; use crate::cpu::kernel::ast::Item; use crate::cpu::kernel::ast::Item::*; diff --git a/evm/src/cpu/kernel/interpreter.rs b/evm/src/cpu/kernel/interpreter.rs index 7ba5809fed..5a65ace3d5 100644 --- a/evm/src/cpu/kernel/interpreter.rs +++ b/evm/src/cpu/kernel/interpreter.rs @@ -2,7 +2,7 @@ use core::cmp::Ordering; use core::ops::Range; -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::{BTreeSet, HashMap}; use anyhow::bail; use eth_trie_utils::partial_trie::PartialTrie; @@ -11,7 +11,6 @@ use keccak_hash::keccak; use plonky2::field::goldilocks_field::GoldilocksField; use super::assembler::BYTES_PER_OFFSET; -use super::utils::u256_from_bool; use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::context_metadata::ContextMetadata; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; @@ -1393,70 +1392,6 @@ impl<'a> Interpreter<'a> { } } -// Computes the two's complement of the given integer. -fn two_complement(x: U256) -> U256 { - let flipped_bits = x ^ MINUS_ONE; - flipped_bits.overflowing_add(U256::one()).0 -} - -fn signed_cmp(x: U256, y: U256) -> Ordering { - let x_is_zero = x.is_zero(); - let y_is_zero = y.is_zero(); - - if x_is_zero && y_is_zero { - return Ordering::Equal; - } - - let x_is_pos = x.eq(&(x & SIGN_MASK)); - let y_is_pos = y.eq(&(y & SIGN_MASK)); - - if x_is_zero { - if y_is_pos { - return Ordering::Less; - } else { - return Ordering::Greater; - } - }; - - if y_is_zero { - if x_is_pos { - return Ordering::Greater; - } else { - return Ordering::Less; - } - }; - - match (x_is_pos, y_is_pos) { - (true, true) => x.cmp(&y), - (true, false) => Ordering::Greater, - (false, true) => Ordering::Less, - (false, false) => x.cmp(&y).reverse(), - } -} - -/// -1 in two's complement representation consists in all bits set to 1. -const MINUS_ONE: U256 = U256([ - 0xffffffffffffffff, - 0xffffffffffffffff, - 0xffffffffffffffff, - 0xffffffffffffffff, -]); - -/// -2^255 in two's complement representation consists in the MSB set to 1. -const MIN_VALUE: U256 = U256([ - 0x0000000000000000, - 0x0000000000000000, - 0x0000000000000000, - 0x8000000000000000, -]); - -const SIGN_MASK: U256 = U256([ - 0xffffffffffffffff, - 0xffffffffffffffff, - 0xffffffffffffffff, - 0x7fffffffffffffff, -]); - fn get_mnemonic(opcode: u8) -> &'static str { match opcode { 0x00 => "STOP", @@ -1651,7 +1586,6 @@ fn get_mnemonic(opcode: u8) -> &'static str { } } -#[macro_use] macro_rules! unpack_address { ($addr:ident) => {{ let offset = $addr.low_u32() as usize; @@ -1729,8 +1663,8 @@ mod tests { interpreter.run()?; // sys_stop returns `success` and `cum_gas_used`, that we need to pop. - interpreter.pop(); - interpreter.pop(); + interpreter.pop().expect("Stack should not be empty"); + interpreter.pop().expect("Stack should not be empty"); assert_eq!(interpreter.stack(), &[0xff.into(), 0xff00.into()]); assert_eq!( diff --git a/evm/src/cpu/kernel/tests/account_code.rs b/evm/src/cpu/kernel/tests/account_code.rs index 28b9ae7d97..5e2dddca9e 100644 --- a/evm/src/cpu/kernel/tests/account_code.rs +++ b/evm/src/cpu/kernel/tests/account_code.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use anyhow::{anyhow, Result}; +use anyhow::Result; use eth_trie_utils::nibbles::Nibbles; use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie}; use ethereum_types::{Address, BigEndianHash, H256, U256}; @@ -327,8 +327,8 @@ fn sstore() -> Result<()> { // The first two elements in the stack are `success` and `leftover_gas`, // returned by the `sys_stop` opcode. - interpreter.pop(); - interpreter.pop(); + interpreter.pop().expect("Stack should not be empty"); + interpreter.pop().expect("Stack should not be empty"); // The code should have added an element to the storage of `to_account`. We run // `mpt_hash_state_trie` to check that. diff --git a/evm/src/cpu/kernel/tests/add11.rs b/evm/src/cpu/kernel/tests/add11.rs index c2725488a6..c5eb29397e 100644 --- a/evm/src/cpu/kernel/tests/add11.rs +++ b/evm/src/cpu/kernel/tests/add11.rs @@ -1,24 +1,18 @@ use std::collections::HashMap; use std::str::FromStr; -use anyhow::{anyhow, Result}; use eth_trie_utils::nibbles::Nibbles; use eth_trie_utils::partial_trie::{HashedPartialTrie, Node, PartialTrie}; -use ethereum_types::{Address, BigEndianHash, H256, U256}; +use ethereum_types::{Address, BigEndianHash, H256}; use hex_literal::hex; use keccak_hash::keccak; use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::context_metadata::ContextMetadata; -use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; use crate::cpu::kernel::interpreter::Interpreter; -use crate::cpu::kernel::tests::account_code::initialize_mpts; use crate::generation::mpt::{AccountRlp, LegacyReceiptRlp}; -use crate::generation::rlp::all_rlp_prover_inputs_reversed; use crate::generation::TrieInputs; -use crate::memory::segments::Segment; use crate::proof::{BlockHashes, BlockMetadata, TrieRoots}; -use crate::util::h2u; use crate::GenerationInputs; #[test] diff --git a/evm/src/cpu/kernel/tests/balance.rs b/evm/src/cpu/kernel/tests/balance.rs index 22b484e779..b393c05cf5 100644 --- a/evm/src/cpu/kernel/tests/balance.rs +++ b/evm/src/cpu/kernel/tests/balance.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie}; use ethereum_types::{Address, BigEndianHash, H256, U256}; use keccak_hash::keccak; diff --git a/evm/src/cpu/kernel/tests/exp.rs b/evm/src/cpu/kernel/tests/exp.rs index 8fee16d97b..482c6b7216 100644 --- a/evm/src/cpu/kernel/tests/exp.rs +++ b/evm/src/cpu/kernel/tests/exp.rs @@ -3,7 +3,7 @@ use ethereum_types::U256; use rand::{thread_rng, Rng}; use crate::cpu::kernel::aggregator::KERNEL; -use crate::cpu::kernel::interpreter::{run, run_interpreter, Interpreter}; +use crate::cpu::kernel::interpreter::{run_interpreter, Interpreter}; #[test] fn test_exp() -> Result<()> { diff --git a/evm/src/cpu/kernel/tests/kernel_consistency.rs b/evm/src/cpu/kernel/tests/kernel_consistency.rs index ec9c649f0d..b02c11a234 100644 --- a/evm/src/cpu/kernel/tests/kernel_consistency.rs +++ b/evm/src/cpu/kernel/tests/kernel_consistency.rs @@ -1,9 +1,6 @@ use anyhow::Result; -use ethereum_types::U256; use crate::cpu::kernel::aggregator::{combined_kernel, KERNEL}; -use crate::cpu::kernel::interpreter::Interpreter; -use crate::memory::segments::Segment; #[test] fn test_kernel_code_hash_consistency() -> Result<()> { diff --git a/evm/src/cpu/kernel/tests/mpt/delete.rs b/evm/src/cpu/kernel/tests/mpt/delete.rs index 38342dc99c..0d4d5e71f7 100644 --- a/evm/src/cpu/kernel/tests/mpt/delete.rs +++ b/evm/src/cpu/kernel/tests/mpt/delete.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use eth_trie_utils::nibbles::Nibbles; use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie}; use ethereum_types::{BigEndianHash, H256, U512}; diff --git a/evm/src/cpu/kernel/tests/mpt/hash.rs b/evm/src/cpu/kernel/tests/mpt/hash.rs index f432144af2..a06dd2a0b5 100644 --- a/evm/src/cpu/kernel/tests/mpt/hash.rs +++ b/evm/src/cpu/kernel/tests/mpt/hash.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use eth_trie_utils::partial_trie::PartialTrie; use ethereum_types::{BigEndianHash, H256}; diff --git a/evm/src/cpu/kernel/tests/mpt/insert.rs b/evm/src/cpu/kernel/tests/mpt/insert.rs index 9c2fd50b24..19b82f74a2 100644 --- a/evm/src/cpu/kernel/tests/mpt/insert.rs +++ b/evm/src/cpu/kernel/tests/mpt/insert.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use eth_trie_utils::nibbles::Nibbles; use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie}; use ethereum_types::{BigEndianHash, H256}; diff --git a/evm/src/cpu/kernel/tests/mpt/load.rs b/evm/src/cpu/kernel/tests/mpt/load.rs index 68ba209d8d..bff1d8cb39 100644 --- a/evm/src/cpu/kernel/tests/mpt/load.rs +++ b/evm/src/cpu/kernel/tests/mpt/load.rs @@ -1,12 +1,11 @@ use std::str::FromStr; -use anyhow::{anyhow, Result}; +use anyhow::Result; use eth_trie_utils::nibbles::Nibbles; use eth_trie_utils::partial_trie::HashedPartialTrie; use ethereum_types::{BigEndianHash, H256, U256}; use hex_literal::hex; -use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; use crate::cpu::kernel::constants::trie_type::PartialTrieType; use crate::cpu::kernel::interpreter::Interpreter; diff --git a/evm/src/cpu/kernel/tests/mpt/read.rs b/evm/src/cpu/kernel/tests/mpt/read.rs index d5913f9867..16206d1390 100644 --- a/evm/src/cpu/kernel/tests/mpt/read.rs +++ b/evm/src/cpu/kernel/tests/mpt/read.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use ethereum_types::BigEndianHash; use crate::cpu::kernel::aggregator::KERNEL; diff --git a/evm/src/cpu/kernel/tests/receipt.rs b/evm/src/cpu/kernel/tests/receipt.rs index d185948b0a..7d00cb2746 100644 --- a/evm/src/cpu/kernel/tests/receipt.rs +++ b/evm/src/cpu/kernel/tests/receipt.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use ethereum_types::{Address, U256}; use hex_literal::hex; use keccak_hash::keccak; @@ -408,9 +408,6 @@ fn test_mpt_insert_receipt() -> Result<()> { receipt.push(num_logs.into()); // num_logs receipt.extend(logs_0.clone()); - // First, we load all mpts. - let initial_stack: Vec = vec![retdest]; - let mut interpreter = Interpreter::new_with_kernel(0, vec![]); initialize_mpts(&mut interpreter, &trie_inputs); diff --git a/evm/src/cpu/syscalls_exceptions.rs b/evm/src/cpu/syscalls_exceptions.rs index debae9dcd5..1dfdb8fa2c 100644 --- a/evm/src/cpu/syscalls_exceptions.rs +++ b/evm/src/cpu/syscalls_exceptions.rs @@ -7,7 +7,6 @@ use plonky2::field::packed::PackedField; use plonky2::field::types::Field; use plonky2::hash::hash_types::RichField; use plonky2::iop::ext_target::ExtensionTarget; -use static_assertions::const_assert; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::cpu::columns::CpuColumnsView; @@ -227,7 +226,7 @@ pub(crate) fn eval_ext_circuit, const D: usize>( { let diff_syscall = builder.sub_extension(jumpdest_channel.addr_virtual, opcode_handler_addr_start); - let constr = builder.mul_extension((filter_syscall), diff_syscall); + let constr = builder.mul_extension(filter_syscall, diff_syscall); yield_constr.constraint(builder, constr); } { diff --git a/evm/src/cross_table_lookup.rs b/evm/src/cross_table_lookup.rs index fe5bf035e1..359b5309e8 100644 --- a/evm/src/cross_table_lookup.rs +++ b/evm/src/cross_table_lookup.rs @@ -27,15 +27,11 @@ //! is similar, but we provide not only `local_values` but also `next_values` -- corresponding to //! the current and next row values -- when computing the linear combinations. -use core::borrow::Borrow; use core::cmp::min; use core::fmt::Debug; -use core::iter::repeat; use anyhow::{ensure, Result}; -use hashbrown::HashMap; use itertools::Itertools; -use plonky2::field::batch_util::{batch_add_inplace, batch_multiply_inplace}; use plonky2::field::extension::{Extendable, FieldExtension}; use plonky2::field::packed::PackedField; use plonky2::field::polynomial::PolynomialValues; @@ -46,13 +42,9 @@ use plonky2::iop::ext_target::ExtensionTarget; use plonky2::iop::target::Target; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::config::{AlgebraicHasher, GenericConfig, Hasher}; -use plonky2::plonk::plonk_common::{ - reduce_with_powers, reduce_with_powers_circuit, reduce_with_powers_ext_circuit, -}; use plonky2::util::ceil_div_usize; use plonky2::util::serialization::{Buffer, IoResult, Read, Write}; -use crate::all_stark::Table; use crate::config::StarkConfig; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::evaluation_frame::StarkEvaluationFrame; @@ -303,7 +295,7 @@ pub(crate) fn num_ctl_helper_columns_by_table( for (i, ctl) in ctls.iter().enumerate() { let CrossTableLookup { looking_tables, - looked_table, + looked_table: _, } = ctl; let mut num_by_table = [0; N]; @@ -349,7 +341,7 @@ pub(crate) fn cross_table_lookup_data<'a, F: RichField, const D: usize, const N: constraint_degree, ); - let mut z_looked = partial_sums( + let z_looked = partial_sums( &trace_poly_values[looked_table.table], &[(&looked_table.columns, &looked_table.filter)], challenge, @@ -412,7 +404,6 @@ fn ctl_helper_zs_cols( grouped_lookups .into_iter() .map(|(table, group)| { - let degree = all_stark_traces[table][0].len(); let columns_filters = group .map(|table| (&table.columns[..], &table.filter)) .collect::], &Option>)>>(); @@ -517,7 +508,7 @@ impl<'a, F: RichField + Extendable, const D: usize> } // Get all cross-table lookup polynomial openings for each STARK proof. - let mut ctl_zs = proofs + let ctl_zs = proofs .iter() .zip(num_lookup_columns) .map(|(p, &num_lookup)| { @@ -551,7 +542,7 @@ impl<'a, F: RichField + Extendable, const D: usize> } } - for (i, &table) in filtered_looking_tables.iter().enumerate() { + for &table in filtered_looking_tables.iter() { // We have first all the helper polynomials, then all the z polynomials. let (looking_z, looking_z_next) = ctl_zs[table][total_num_helper_cols_by_table[table] + z_indices[table]]; @@ -736,7 +727,7 @@ impl<'a, F: Field, const D: usize> CtlCheckVarsTarget { num_helper_ctl_columns: &[usize], ) -> Vec { // Get all cross-table lookup polynomial openings for each STARK proof. - let mut ctl_zs = { + let ctl_zs = { let openings = &proof.openings; let ctl_zs = openings.auxiliary_polys.iter().skip(num_lookup_columns); let ctl_zs_next = openings diff --git a/evm/src/fixed_recursive_verifier.rs b/evm/src/fixed_recursive_verifier.rs index 2e57ea3026..2df85b03de 100644 --- a/evm/src/fixed_recursive_verifier.rs +++ b/evm/src/fixed_recursive_verifier.rs @@ -1,7 +1,6 @@ use core::mem::{self, MaybeUninit}; use core::ops::Range; use std::collections::BTreeMap; -use std::path::Path; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -25,7 +24,6 @@ use plonky2::plonk::config::{AlgebraicHasher, GenericConfig}; use plonky2::plonk::proof::{ProofWithPublicInputs, ProofWithPublicInputsTarget}; use plonky2::recursion::cyclic_recursion::check_cyclic_proof_verifier_data; use plonky2::recursion::dummy_circuit::cyclic_base_proof; -use plonky2::util::serialization::gate_serialization::default; use plonky2::util::serialization::{ Buffer, GateSerializer, IoResult, Read, WitnessGeneratorSerializer, Write, }; @@ -1100,11 +1098,8 @@ where /// ``` pub fn prove_root_after_initial_stark( &self, - all_stark: &AllStark, - config: &StarkConfig, all_proof: AllProof, table_circuits: &[(RecursiveCircuitsForTableSize, u8); NUM_TABLES], - timing: &mut TimingTree, abort_signal: Option>, ) -> anyhow::Result<(ProofWithPublicInputs, PublicValues)> { let mut root_inputs = PartialWitness::new(); @@ -1113,7 +1108,6 @@ where let (table_circuit, index_verifier_data) = &table_circuits[table]; let stark_proof = &all_proof.stark_proofs[table]; - let original_degree_bits = stark_proof.proof.recover_degree_bits(config); let shrunk_proof = table_circuit.shrink(stark_proof, &all_proof.ctl_challenges)?; root_inputs.set_target( diff --git a/evm/src/generation/mod.rs b/evm/src/generation/mod.rs index eeaafa800b..b63f48a1c7 100644 --- a/evm/src/generation/mod.rs +++ b/evm/src/generation/mod.rs @@ -1,11 +1,8 @@ use std::collections::{BTreeSet, HashMap}; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; use anyhow::anyhow; use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie}; use ethereum_types::{Address, BigEndianHash, H256, U256}; -use itertools::enumerate; use plonky2::field::extension::Extendable; use plonky2::field::polynomial::PolynomialValues; use plonky2::field::types::Field; @@ -22,16 +19,12 @@ use crate::all_stark::{AllStark, NUM_TABLES}; use crate::config::StarkConfig; use crate::cpu::columns::CpuColumnsView; use crate::cpu::kernel::aggregator::KERNEL; -use crate::cpu::kernel::assembler::Kernel; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; -use crate::cpu::kernel::opcodes::get_opcode; use crate::generation::state::GenerationState; use crate::generation::trie_extractor::{get_receipt_trie, get_state_trie, get_txn_trie}; use crate::memory::segments::Segment; use crate::proof::{BlockHashes, BlockMetadata, ExtraBlockData, PublicValues, TrieRoots}; -use crate::prover::check_abort_signal; use crate::util::{h2u, u256_to_u8, u256_to_usize}; -use crate::witness::errors::{ProgramError, ProverInputError}; use crate::witness::memory::{MemoryAddress, MemoryChannel}; use crate::witness::transition::transition; @@ -41,7 +34,6 @@ pub(crate) mod rlp; pub(crate) mod state; mod trie_extractor; -use self::mpt::{load_all_mpts, TrieRootPtrs}; use crate::witness::util::{mem_write_log, stack_peek}; /// Inputs needed for trace generation. @@ -282,7 +274,6 @@ pub fn generate_traces, const D: usize>( let gas_used_after = read_metadata(GlobalMetadata::BlockGasUsedAfter); let txn_number_after = read_metadata(GlobalMetadata::TxnNumberAfter); - let trie_root_ptrs = state.trie_root_ptrs; let extra_block_data = ExtraBlockData { checkpoint_state_trie_root: inputs.checkpoint_state_trie_root, txn_number_before: inputs.txn_number_before, @@ -372,7 +363,7 @@ fn simulate_cpu_between_labels_and_get_user_jumps( } let pc = state.registers.program_counter; let context = state.registers.context; - let mut halt = state.registers.is_kernel + let halt = state.registers.is_kernel && pc == halt_pc && state.registers.context == initial_context; let Ok(opcode) = u256_to_u8(state.memory.get(MemoryAddress::new( diff --git a/evm/src/generation/mpt.rs b/evm/src/generation/mpt.rs index 71976bc012..ee530ddef5 100644 --- a/evm/src/generation/mpt.rs +++ b/evm/src/generation/mpt.rs @@ -9,13 +9,10 @@ use keccak_hash::keccak; use rlp::{Decodable, DecoderError, Encodable, PayloadInfo, Rlp, RlpStream}; use rlp_derive::{RlpDecodable, RlpEncodable}; -use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; use crate::cpu::kernel::constants::trie_type::PartialTrieType; use crate::generation::TrieInputs; -use crate::memory::segments::Segment; use crate::util::h2u; use crate::witness::errors::{ProgramError, ProverInputError}; -use crate::witness::memory::MemoryAddress; use crate::Node; #[derive(RlpEncodable, RlpDecodable, Debug)] diff --git a/evm/src/generation/prover_input.rs b/evm/src/generation/prover_input.rs index 5c0aba1a4f..9662d6b6b7 100644 --- a/evm/src/generation/prover_input.rs +++ b/evm/src/generation/prover_input.rs @@ -1,20 +1,15 @@ -use core::cmp::min; use core::mem::transmute; use std::collections::{BTreeSet, HashMap}; use std::str::FromStr; use anyhow::{bail, Error}; use ethereum_types::{BigEndianHash, H256, U256, U512}; -use itertools::{enumerate, Itertools}; +use itertools::Itertools; use num_bigint::BigUint; -use plonky2::field::extension::Extendable; use plonky2::field::types::Field; -use plonky2::hash::hash_types::RichField; use serde::{Deserialize, Serialize}; -use crate::cpu::kernel::aggregator::KERNEL; use crate::cpu::kernel::constants::context_metadata::ContextMetadata; -use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; use crate::extension_tower::{FieldExt, Fp12, BLS381, BN254}; use crate::generation::prover_input::EvmField::{ Bls381Base, Bls381Scalar, Bn254Base, Bn254Scalar, Secp256k1Base, Secp256k1Scalar, @@ -252,7 +247,6 @@ impl GenerationState { /// Returns the next used jump address. fn run_next_jumpdest_table_address(&mut self) -> Result { let context = u256_to_usize(stack_peek(self, 0)? >> CONTEXT_SCALING_FACTOR)?; - let code_len = u256_to_usize(self.get_current_code_len()?.into()); if self.jumpdest_table.is_none() { self.generate_jumpdest_table()?; @@ -300,10 +294,6 @@ impl GenerationState { let checkpoint = self.checkpoint(); let memory = self.memory.clone(); - let code = self.get_current_code()?; - // We need to set the simulated jumpdest bits to one as otherwise - // the simulation will fail. - // Simulate the user's code and (unnecessarily) part of the kernel code, skipping the validate table call let Some(jumpdest_table) = simulate_cpu_between_labels_and_get_user_jumps( "jumpdest_analysis_end", @@ -343,10 +333,6 @@ impl GenerationState { ))); } - fn get_current_code(&self) -> Result, ProgramError> { - self.get_code(self.registers.context) - } - fn get_code(&self, context: usize) -> Result, ProgramError> { let code_len = self.get_code_len(context)?; let code = (0..code_len) @@ -360,17 +346,6 @@ impl GenerationState { Ok(code) } - fn set_code_len(&mut self, len: usize) { - self.memory.set( - MemoryAddress::new( - self.registers.context, - Segment::ContextMetadata, - ContextMetadata::CodeSize.unscale(), - ), - len.into(), - ) - } - fn get_code_len(&self, context: usize) -> Result { let code_len = u256_to_usize(self.memory.get(MemoryAddress::new( context, @@ -379,22 +354,6 @@ impl GenerationState { )))?; Ok(code_len) } - - fn get_current_code_len(&self) -> Result { - self.get_code_len(self.registers.context) - } - - fn set_jumpdest_bits(&mut self, code: &[u8]) { - const JUMPDEST_OPCODE: u8 = 0x5b; - for (pos, opcode) in CodeIterator::new(code) { - if opcode == JUMPDEST_OPCODE { - self.memory.set( - MemoryAddress::new(self.registers.context, Segment::JumpdestBits, pos), - U256::one(), - ); - } - } - } } /// For all address in `jumpdest_table`, each bounded by `largest_address`, @@ -411,7 +370,7 @@ fn get_proofs_and_jumpdests( const PUSH32_OPCODE: u8 = 0x7f; let (proofs, _) = CodeIterator::until(code, largest_address + 1).fold( (vec![], 0), - |(mut proofs, acc), (pos, opcode)| { + |(mut proofs, acc), (pos, _opcode)| { let has_prefix = if let Some(prefix_start) = pos.checked_sub(32) { code[prefix_start..pos] .iter() diff --git a/evm/src/generation/state.rs b/evm/src/generation/state.rs index 7f52eda7e4..a6df4b3331 100644 --- a/evm/src/generation/state.rs +++ b/evm/src/generation/state.rs @@ -1,10 +1,8 @@ -use std::collections::{BTreeSet, HashMap}; +use std::collections::HashMap; use ethereum_types::{Address, BigEndianHash, H160, H256, U256}; use keccak_hash::keccak; -use plonky2::field::extension::Extendable; use plonky2::field::types::Field; -use plonky2::hash::hash_types::RichField; use super::mpt::{load_all_mpts, TrieRootPtrs}; use super::TrieInputs; diff --git a/evm/src/lookup.rs b/evm/src/lookup.rs index b16706ae0a..f98814f9a1 100644 --- a/evm/src/lookup.rs +++ b/evm/src/lookup.rs @@ -4,7 +4,7 @@ use core::iter::repeat; use itertools::Itertools; use num_bigint::BigUint; -use plonky2::field::batch_util::{batch_add_inplace, batch_multiply_inplace}; +use plonky2::field::batch_util::batch_add_inplace; use plonky2::field::extension::{Extendable, FieldExtension}; use plonky2::field::packed::PackedField; use plonky2::field::polynomial::PolynomialValues; @@ -108,14 +108,6 @@ impl Filter { .map(|col| col.eval_table(table, row)) .sum() } - - pub(crate) fn eval_all_rows(&self, table: &[PolynomialValues]) -> Vec { - let length = table[0].len(); - - (0..length) - .map(|row| self.eval_table(table, row)) - .collect::>() - } } /// Represent two linear combination of columns, corresponding to the current and next row values. @@ -480,7 +472,6 @@ pub(crate) fn lookup_helper_columns( assert!(BigUint::from(num_total_logup_entries) < F::characteristic()); let num_helper_columns = lookup.num_helper_columns(constraint_degree); - let mut helper_columns: Vec> = Vec::with_capacity(num_helper_columns); let looking_cols = lookup .columns @@ -672,7 +663,6 @@ pub(crate) fn get_helper_cols( let mut helper_columns = Vec::with_capacity(num_helper_columns); - let mut filter_index = 0; for mut cols_filts in &columns_filters.iter().chunks(constraint_degree - 1) { let (first_col, first_filter) = cols_filts.next().unwrap(); @@ -843,7 +833,6 @@ pub(crate) fn eval_ext_lookups_circuit< lookup_vars: LookupCheckVarsTarget, yield_constr: &mut RecursiveConstraintConsumer, ) { - let one = builder.one_extension(); let degree = stark.constraint_degree(); let lookups = stark.lookups(); diff --git a/evm/src/memory/segments.rs b/evm/src/memory/segments.rs index 6177d9962e..1b4bcbfbf7 100644 --- a/evm/src/memory/segments.rs +++ b/evm/src/memory/segments.rs @@ -1,5 +1,4 @@ use ethereum_types::U256; -use num::traits::AsPrimitive; pub(crate) const SEGMENT_SCALING_FACTOR: usize = 32; diff --git a/evm/src/proof.rs b/evm/src/proof.rs index 4cc1867738..33640458d6 100644 --- a/evm/src/proof.rs +++ b/evm/src/proof.rs @@ -1,4 +1,4 @@ -use ethereum_types::{Address, H160, H256, U256}; +use ethereum_types::{Address, H256, U256}; use itertools::Itertools; use plonky2::field::extension::{Extendable, FieldExtension}; use plonky2::fri::oracle::PolynomialBatch; @@ -19,7 +19,6 @@ use serde::{Deserialize, Serialize}; use crate::all_stark::NUM_TABLES; use crate::config::StarkConfig; use crate::cross_table_lookup::GrandProductChallengeSet; -use crate::generation::mpt::TrieRootPtrs; use crate::util::{get_h160, get_h256, h2u}; /// A STARK proof for each table, plus some metadata used to create recursive wrapper proofs. diff --git a/evm/src/prover.rs b/evm/src/prover.rs index 8ca00d7659..faef64a033 100644 --- a/evm/src/prover.rs +++ b/evm/src/prover.rs @@ -35,7 +35,6 @@ use crate::lookup::{lookup_helper_columns, Lookup, LookupCheckVars}; use crate::proof::{AllProof, PublicValues, StarkOpeningSet, StarkProof, StarkProofWithMetadata}; use crate::stark::Stark; use crate::vanishing_poly::eval_vanishing_poly; -use crate::witness::errors::ProgramError; #[cfg(test)] use crate::{ cross_table_lookup::testutils::check_ctls, verifier::testutils::get_memory_extra_looking_values, diff --git a/evm/src/recursive_verifier.rs b/evm/src/recursive_verifier.rs index c62e967e9c..5220ba32a7 100644 --- a/evm/src/recursive_verifier.rs +++ b/evm/src/recursive_verifier.rs @@ -2,7 +2,7 @@ use core::array::from_fn; use core::fmt::Debug; use anyhow::Result; -use ethereum_types::{BigEndianHash, H256, U256}; +use ethereum_types::{BigEndianHash, U256}; use plonky2::field::extension::Extendable; use plonky2::field::types::Field; use plonky2::fri::witness_util::set_fri_proof_target; @@ -43,7 +43,7 @@ use crate::proof::{ TrieRootsTarget, }; use crate::stark::Stark; -use crate::util::{h256_limbs, h2u, u256_limbs, u256_to_u32, u256_to_u64}; +use crate::util::{h256_limbs, u256_limbs, u256_to_u32, u256_to_u64}; use crate::vanishing_poly::eval_vanishing_poly_circuit; use crate::witness::errors::ProgramError; @@ -348,7 +348,6 @@ fn verify_stark_proof_with_challenges_circuit< .iter() .map(|ctl| ctl.helper_columns.len()) .sum::(); - let num_ctl_z_polys = ctl_vars.len(); let StarkOpeningSetTarget { local_values, diff --git a/evm/src/stark.rs b/evm/src/stark.rs index 6ee26f585a..5ff578f9fc 100644 --- a/evm/src/stark.rs +++ b/evm/src/stark.rs @@ -111,7 +111,6 @@ pub trait Stark, const D: usize>: Sync { let auxiliary_polys_info = FriPolynomialInfo::from_range(AUXILIARY_ORACLE_INDEX, 0..num_auxiliary_polys); - let mut start_index = num_lookup_columns; let ctl_zs_info = FriPolynomialInfo::from_range( AUXILIARY_ORACLE_INDEX, num_lookup_columns + num_ctl_helpers..num_auxiliary_polys, diff --git a/evm/src/verifier.rs b/evm/src/verifier.rs index bb18f5434e..3e284c7fc4 100644 --- a/evm/src/verifier.rs +++ b/evm/src/verifier.rs @@ -318,7 +318,7 @@ pub(crate) fn verify_stark_proof_with_challenges< next_values, auxiliary_polys, auxiliary_polys_next, - ctl_zs_first, + ctl_zs_first: _, quotient_polys, } = &proof.openings; let vars = S::EvaluationFrame::from_values(local_values, next_values); diff --git a/evm/src/witness/operation.rs b/evm/src/witness/operation.rs index e87c1465e1..8c09fa00a2 100644 --- a/evm/src/witness/operation.rs +++ b/evm/src/witness/operation.rs @@ -928,7 +928,7 @@ pub(crate) fn generate_exception( row.general.stack_mut().stack_inv_aux = F::ONE; } - fill_stack_fields(state, &mut row); + fill_stack_fields(state, &mut row)?; row.general.exception_mut().exc_code_bits = [ F::from_bool(exc_code & 1 != 0), diff --git a/evm/src/witness/transition.rs b/evm/src/witness/transition.rs index 835ff59372..aed6ff5397 100644 --- a/evm/src/witness/transition.rs +++ b/evm/src/witness/transition.rs @@ -400,7 +400,7 @@ fn try_perform_instruction( fill_op_flag(op, &mut row); - fill_stack_fields(state, &mut row); + fill_stack_fields(state, &mut row)?; // Might write in general CPU columns when it shouldn't, but the correct values will // overwrite these ones during the op generation.