Skip to content

Commit

Permalink
Cleanup and bring back deadcode lint (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored May 23, 2024
1 parent abf919d commit aa36464
Show file tree
Hide file tree
Showing 25 changed files with 246 additions and 292 deletions.
1 change: 0 additions & 1 deletion evm_arithmetization/src/arithmetic/addcy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ pub(crate) fn eval_packed_generic<P: PackedField>(
eval_packed_generic_addcy(yield_constr, is_gt, in0, aux, in1, out, false);
}

#[allow(clippy::needless_collect)]
pub(crate) fn eval_ext_circuit_addcy<F: RichField + Extendable<D>, const D: usize>(
builder: &mut CircuitBuilder<F, D>,
yield_constr: &mut RecursiveConstraintConsumer<F, D>,
Expand Down
1 change: 0 additions & 1 deletion evm_arithmetization/src/cpu/columns/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ impl<T: Copy> CpuGeneralColumnsView<T> {
}

impl<T: Copy + PartialEq> PartialEq<Self> for CpuGeneralColumnsView<T> {
#[allow(clippy::unconditional_recursion)] // false positive
fn eq(&self, other: &Self) -> bool {
let self_arr: &[T; NUM_SHARED_COLUMNS] = self.borrow();
let other_arr: &[T; NUM_SHARED_COLUMNS] = other.borrow();
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/constants/txn_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::memory::segments::Segment;
///
/// Each value is directly scaled by the corresponding `Segment::TxnFields`
/// value for faster memory access in the kernel.
#[allow(dead_code)]
#[allow(clippy::enum_clike_unportable_variant)]
#[repr(usize)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Debug)]
Expand Down Expand Up @@ -41,6 +40,7 @@ impl NormalizedTxnField {
pub(crate) const COUNT: usize = 17;

/// Unscales this virtual offset by their respective `Segment` value.
#[cfg(test)]
pub(crate) const fn unscale(&self) -> usize {
*self as usize - Segment::TxnFields as usize
}
Expand Down
2 changes: 2 additions & 0 deletions evm_arithmetization/src/cpu/kernel/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub(crate) struct Interpreter<F: Field> {
/// halt_context
pub(crate) halt_context: Option<usize>,
/// Counts the number of appearances of each opcode. For debugging purposes.
#[allow(unused)]
pub(crate) opcode_count: [usize; 0x100],
jumpdest_table: HashMap<usize, BTreeSet<usize>>,
/// `true` if the we are currently carrying out a jumpdest analysis.
Expand Down Expand Up @@ -616,6 +617,7 @@ impl<F: Field> Transition<F> for Interpreter<F> {
}
}

#[cfg(debug_assertions)]
fn get_mnemonic(opcode: u8) -> &'static str {
match opcode {
0x00 => "STOP",
Expand Down
1 change: 1 addition & 0 deletions evm_arithmetization/src/cpu/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod utils;
pub(crate) mod interpreter;

pub use constants::cancun_constants;
pub use constants::global_exit_root;

#[cfg(test)]
mod tests;
Expand Down
2 changes: 0 additions & 2 deletions evm_arithmetization/src/cpu/kernel/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::empty_docs)]

use std::str::FromStr;

use ethereum_types::U256;
Expand Down
20 changes: 13 additions & 7 deletions evm_arithmetization/src/cpu/kernel/tests/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn prepare_interpreter<F: Field>(
);
let hash = H256::from_uint(&interpreter.stack()[1]);

state_trie.insert(k, rlp::encode(account).to_vec());
state_trie.insert(k, rlp::encode(account).to_vec())?;
let expected_state_trie_hash = state_trie.hash();
assert_eq!(hash, expected_state_trie_hash);

Expand Down Expand Up @@ -201,7 +201,9 @@ fn test_extcodecopy() -> Result<()> {
// Pre-initialize the accessed addresses list.
let init_accessed_addresses = KERNEL.global_labels["init_access_lists"];
interpreter.generation_state.registers.program_counter = init_accessed_addresses;
interpreter.push(0xdeadbeefu32.into());
interpreter
.push(0xdeadbeefu32.into())
.expect("The stack should not overflow");
interpreter.run()?;

let extcodecopy = KERNEL.global_labels["sys_extcodecopy"];
Expand Down Expand Up @@ -321,7 +323,7 @@ fn sstore() -> Result<()> {

let mut state_trie_before = HashedPartialTrie::from(Node::Empty);

state_trie_before.insert(addr_nibbles, rlp::encode(&account_before).to_vec());
state_trie_before.insert(addr_nibbles, rlp::encode(&account_before).to_vec())?;

let trie_inputs = TrieInputs {
state_trie: state_trie_before.clone(),
Expand All @@ -336,7 +338,9 @@ fn sstore() -> Result<()> {
// Pre-initialize the accessed addresses list.
let init_accessed_addresses = KERNEL.global_labels["init_access_lists"];
interpreter.generation_state.registers.program_counter = init_accessed_addresses;
interpreter.push(0xdeadbeefu32.into());
interpreter
.push(0xdeadbeefu32.into())
.expect("The stack should not overflow");
interpreter.run()?;

// Prepare the interpreter by inserting the account in the state trie.
Expand Down Expand Up @@ -384,7 +388,7 @@ fn sstore() -> Result<()> {
let hash = H256::from_uint(&interpreter.stack()[1]);

let mut expected_state_trie_after = HashedPartialTrie::from(Node::Empty);
expected_state_trie_after.insert(addr_nibbles, rlp::encode(&account_after).to_vec());
expected_state_trie_after.insert(addr_nibbles, rlp::encode(&account_after).to_vec())?;

let expected_state_trie_hash = expected_state_trie_after.hash();
assert_eq!(hash, expected_state_trie_hash);
Expand Down Expand Up @@ -417,7 +421,7 @@ fn sload() -> Result<()> {

let mut state_trie_before = HashedPartialTrie::from(Node::Empty);

state_trie_before.insert(addr_nibbles, rlp::encode(&account_before).to_vec());
state_trie_before.insert(addr_nibbles, rlp::encode(&account_before).to_vec())?;

let trie_inputs = TrieInputs {
state_trie: state_trie_before.clone(),
Expand All @@ -432,7 +436,9 @@ fn sload() -> Result<()> {
// Pre-initialize the accessed addresses list.
let init_accessed_addresses = KERNEL.global_labels["init_access_lists"];
interpreter.generation_state.registers.program_counter = init_accessed_addresses;
interpreter.push(0xdeadbeefu32.into());
interpreter
.push(0xdeadbeefu32.into())
.expect("The stack should not overflow");
interpreter.run()?;

// Prepare the interpreter by inserting the account in the state trie.
Expand Down
100 changes: 62 additions & 38 deletions evm_arithmetization/src/cpu/kernel/tests/add11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,36 @@ fn test_add11_yml() {
&mut beacon_roots_account_storage,
block_metadata.block_timestamp,
block_metadata.parent_beacon_block_root,
);
)
.unwrap();
let beacon_roots_account =
beacon_roots_contract_from_storage(&beacon_roots_account_storage);

let mut expected_state_trie_after = HashedPartialTrie::from(Node::Empty);
expected_state_trie_after.insert(
beneficiary_nibbles,
rlp::encode(&beneficiary_account_after).to_vec(),
);
expected_state_trie_after
.insert(sender_nibbles, rlp::encode(&sender_account_after).to_vec());
expected_state_trie_after.insert(to_nibbles, rlp::encode(&to_account_after).to_vec());
expected_state_trie_after.insert(
beacon_roots_account_nibbles(),
rlp::encode(&beacon_roots_account).to_vec(),
);
expected_state_trie_after.insert(
ger_account_nibbles(),
rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(),
);
.insert(
beneficiary_nibbles,
rlp::encode(&beneficiary_account_after).to_vec(),
)
.unwrap();
expected_state_trie_after
.insert(sender_nibbles, rlp::encode(&sender_account_after).to_vec())
.unwrap();
expected_state_trie_after
.insert(to_nibbles, rlp::encode(&to_account_after).to_vec())
.unwrap();
expected_state_trie_after
.insert(
beacon_roots_account_nibbles(),
rlp::encode(&beacon_roots_account).to_vec(),
)
.unwrap();
expected_state_trie_after
.insert(
ger_account_nibbles(),
rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(),
)
.unwrap();
expected_state_trie_after
};
let receipt_0 = LegacyReceiptRlp {
Expand All @@ -151,10 +161,12 @@ fn test_add11_yml() {
logs: vec![],
};
let mut receipts_trie = HashedPartialTrie::from(Node::Empty);
receipts_trie.insert(
Nibbles::from_str("0x80").unwrap(),
rlp::encode(&receipt_0).to_vec(),
);
receipts_trie
.insert(
Nibbles::from_str("0x80").unwrap(),
rlp::encode(&receipt_0).to_vec(),
)
.unwrap();
let transactions_trie: HashedPartialTrie = Node::Leaf {
nibbles: Nibbles::from_str("0x80").unwrap(),
value: txn.to_vec(),
Expand Down Expand Up @@ -290,26 +302,36 @@ fn test_add11_yml_with_exception() {
&mut beacon_roots_account_storage,
block_metadata.block_timestamp,
block_metadata.parent_beacon_block_root,
);
)
.unwrap();
let beacon_roots_account =
beacon_roots_contract_from_storage(&beacon_roots_account_storage);

let mut expected_state_trie_after = HashedPartialTrie::from(Node::Empty);
expected_state_trie_after.insert(
beneficiary_nibbles,
rlp::encode(&beneficiary_account_after).to_vec(),
);
expected_state_trie_after
.insert(sender_nibbles, rlp::encode(&sender_account_after).to_vec());
expected_state_trie_after.insert(to_nibbles, rlp::encode(&to_account_after).to_vec());
expected_state_trie_after.insert(
beacon_roots_account_nibbles(),
rlp::encode(&beacon_roots_account).to_vec(),
);
expected_state_trie_after.insert(
ger_account_nibbles(),
rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(),
);
.insert(
beneficiary_nibbles,
rlp::encode(&beneficiary_account_after).to_vec(),
)
.unwrap();
expected_state_trie_after
.insert(sender_nibbles, rlp::encode(&sender_account_after).to_vec())
.unwrap();
expected_state_trie_after
.insert(to_nibbles, rlp::encode(&to_account_after).to_vec())
.unwrap();
expected_state_trie_after
.insert(
beacon_roots_account_nibbles(),
rlp::encode(&beacon_roots_account).to_vec(),
)
.unwrap();
expected_state_trie_after
.insert(
ger_account_nibbles(),
rlp::encode(&GLOBAL_EXIT_ROOT_ACCOUNT).to_vec(),
)
.unwrap();
expected_state_trie_after
};

Expand All @@ -320,10 +342,12 @@ fn test_add11_yml_with_exception() {
logs: vec![],
};
let mut receipts_trie = HashedPartialTrie::from(Node::Empty);
receipts_trie.insert(
Nibbles::from_str("0x80").unwrap(),
rlp::encode(&receipt_0).to_vec(),
);
receipts_trie
.insert(
Nibbles::from_str("0x80").unwrap(),
rlp::encode(&receipt_0).to_vec(),
)
.unwrap();
let transactions_trie: HashedPartialTrie = Node::Leaf {
nibbles: Nibbles::from_str("0x80").unwrap(),
value: txn.to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/tests/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn prepare_interpreter<F: Field>(
);
let hash = H256::from_uint(&interpreter.stack()[1]);

state_trie.insert(k, rlp::encode(account).to_vec());
state_trie.insert(k, rlp::encode(account).to_vec())?;
let expected_state_trie_hash = state_trie.hash();
assert_eq!(hash, expected_state_trie_hash);

Expand Down
16 changes: 12 additions & 4 deletions evm_arithmetization/src/cpu/kernel/tests/blobhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ fn test_valid_blobhash() -> Result<()> {

interpreter.set_context_metadata_field(1, GasLimit, U256::from(1000000000000u64));

interpreter.push(index.into()); // target hash index
interpreter.push(retdest); // kexit_info
interpreter
.push(index.into())
.expect("The stack should not overflow"); // target hash index
interpreter
.push(retdest)
.expect("The stack should not overflow"); // kexit_info

interpreter.run()?;

Expand Down Expand Up @@ -68,8 +72,12 @@ fn test_invalid_blobhash() -> Result<()> {

interpreter.set_context_metadata_field(1, GasLimit, U256::from(1000000000000u64));

interpreter.push(index.into()); // target hash index
interpreter.push(retdest); // kexit_info
interpreter
.push(index.into())
.expect("The stack should not overflow"); // target hash index
interpreter
.push(retdest)
.expect("The stack should not overflow"); // kexit_info

interpreter.run()?;

Expand Down
5 changes: 1 addition & 4 deletions evm_arithmetization/src/cpu/kernel/tests/bls381.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
use anyhow::Result;
use ethereum_types::U256;
use hex_literal::hex;
use keccak_hash::keccak;
use plonky2::field::goldilocks_field::GoldilocksField as F;
use rand::Rng;

use super::{run_interpreter_with_memory, InterpreterMemoryInitialization};
use crate::cpu::kernel::aggregator::KERNEL;
use crate::cpu::kernel::cancun_constants::POINT_EVALUATION_PRECOMPILE_RETURN_VALUE;
use crate::cpu::kernel::constants::cancun_constants::KZG_VERSIONED_HASH;
use crate::cpu::kernel::constants::context_metadata::ContextMetadata;
use crate::cpu::kernel::interpreter::Interpreter;
use crate::extension_tower::{Fp2, Stack, BLS381};
use crate::memory::segments::Segment::{self, KernelGeneral};
use crate::memory::segments::Segment::KernelGeneral;
use crate::util::sha2;
use crate::witness::errors::ProgramError;

#[test]
fn test_bls_fp2_mul() -> Result<()> {
Expand Down
Loading

0 comments on commit aa36464

Please sign in to comment.