Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Rm deadcode of EVM circuit #1525

Merged
merged 27 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
738cbc2
clean up feature flags
ChihChengLiang Jul 6, 2023
b008a56
rm dead code to a degree that still build
ChihChengLiang Jul 6, 2023
be33f67
some more dead code
ChihChengLiang Jul 6, 2023
f33f1e2
bytecode circuit params
ChihChengLiang Jul 6, 2023
967ce0a
rm more to a degree no break
ChihChengLiang Jul 6, 2023
c412ee6
some delicate one
ChihChengLiang Jul 6, 2023
91c1fde
rm more
ChihChengLiang Jul 6, 2023
9d3f5c8
rm more
ChihChengLiang Jul 6, 2023
36ca1ed
rm more
ChihChengLiang Jul 6, 2023
477208b
move test aggregation circuit to dev
ChihChengLiang Jul 6, 2023
14f8a6b
max degree can go
ChihChengLiang Jul 6, 2023
0abc7e4
use dash instead of allow dead code
ChihChengLiang Jul 6, 2023
edd9d0e
fmt
ChihChengLiang Jul 6, 2023
14c3701
comment
ChihChengLiang Jul 6, 2023
2a101e8
wave goodbye to batched is zero
ChihChengLiang Jul 6, 2023
611f0c0
minimize impact on features flag
ChihChengLiang Jul 6, 2023
478da29
super circuit test has no exports
ChihChengLiang Jul 7, 2023
65df70a
update test features
ChihChengLiang Jul 7, 2023
ac7f2fd
dummy cols are required in test circuits
ChihChengLiang Jul 7, 2023
438c617
rm StepLast
ChihChengLiang Jul 7, 2023
26b3527
typo fix 'remainder'
ChihChengLiang Jul 10, 2023
2868dbe
remove pub(crate) for unused variables
ChihChengLiang Jul 10, 2023
6d229b1
uX tables are dead code now
ChihChengLiang Jul 10, 2023
8740aeb
rm keccak dead code
ChihChengLiang Jul 10, 2023
9710114
allow dead_code with reasons
ChihChengLiang Jul 10, 2023
bf11d68
state circuit lookup fix
ChihChengLiang Jul 10, 2023
b2df2f9
fix remainder
ChihChengLiang Jul 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
- zkevm-circuits
feature:
- default
- test
- test-circuits
- test-util
- warn-unimplemented
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
ark-std = { version = "0.3", features = ["print-trace"] }
zkevm-circuits = { path = "../zkevm-circuits", features = ["test"]}
zkevm-circuits = { path = "../zkevm-circuits", features = ["test-circuits"] }
bus-mapping = { path = "../bus-mapping", features = ["test"] }
rand_xorshift = "0.3"
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ serde_json = "1.0.66"
serde = { version = "1.0.130", features = ["derive"] }
bus-mapping = { path = "../bus-mapping" , features = ["test"] }
eth-types = { path = "../eth-types" }
zkevm-circuits = { path = "../zkevm-circuits", features = ["test"] }
zkevm-circuits = { path = "../zkevm-circuits", features = ["test-circuits"] }
tokio = { version = "1.13", features = ["macros", "rt-multi-thread"] }
url = "2.2.2"
pretty_assertions = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion testool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ strum_macros = "0.24"
thiserror = "1.0"
toml = "0.5"
yaml-rust = "0.4.5"
zkevm-circuits = { path="../zkevm-circuits", features=["test"] }
zkevm-circuits = { path="../zkevm-circuits", features=["test-util"] }
rand_chacha = "0.3"
rand = "0.8"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
Expand Down
4 changes: 3 additions & 1 deletion zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ serde_json = "1.0.78"

[features]
default = []
test = ["ethers-signers", "mock", "bus-mapping/test"]
# We export some test circuits for other crates to consume
test-circuits = []
# Test utilities for testool crate to consume
test-util = ["dep:mock"]
warn-unimplemented = ["eth-types/warn-unimplemented"]
stats = ["warn-unimplemented", "dep:cli-table"]

Expand Down
7 changes: 3 additions & 4 deletions zkevm-circuits/src/bytecode_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
pub mod bytecode_unroller;
/// Bytecode circuit
pub mod circuit;
pub(crate) mod param;

#[cfg(any(feature = "test", test, feature = "test-circuits"))]
#[cfg(any(test, feature = "test-circuits"))]
mod dev;
/// Bytecode circuit tester
#[cfg(any(feature = "test", test))]
#[cfg(test)]
mod test;
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
#[cfg(feature = "test-circuits")]
pub use dev::BytecodeCircuit as TestBytecodeCircuit;
7 changes: 3 additions & 4 deletions zkevm-circuits/src/bytecode_circuit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ use halo2_proofs::{
use log::trace;
use std::vec;

use super::{
bytecode_unroller::{unroll, UnrolledBytecode},
param::PUSH_TABLE_WIDTH,
};
use super::bytecode_unroller::{unroll, UnrolledBytecode};

const PUSH_TABLE_WIDTH: usize = 2;

#[derive(Debug, Clone, Default)]
/// Row for assignment
Expand Down
3 changes: 0 additions & 3 deletions zkevm-circuits/src/bytecode_circuit/param.rs

This file was deleted.

3 changes: 1 addition & 2 deletions zkevm-circuits/src/bytecode_circuit/test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![allow(unused_imports)]
use crate::{
bytecode_circuit::{bytecode_unroller::*, circuit::BytecodeCircuit},
table::BytecodeFieldTag,
util::{is_push, keccak, unusable_rows, Challenges, SubCircuit},
util::{is_push, keccak, unusable_rows, SubCircuit},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{Bytecode, Field, Word};
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! etc.
pub(crate) mod util;

#[cfg(any(feature = "test", test, feature = "test-circuits"))]
#[cfg(any(test, feature = "test-circuits"))]
mod dev;
#[cfg(test)]
mod test;
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
#[cfg(feature = "test-circuits")]
pub use dev::CopyCircuit as TestCopyCircuit;

use bus_mapping::{
Expand Down
9 changes: 5 additions & 4 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub mod step;
pub mod table;
pub(crate) mod util;

#[cfg(any(feature = "test", test))]
#[cfg(test)]
pub(crate) mod test;
use self::step::HasExecutionState;
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
#[cfg(feature = "test-circuits")]
pub use self::EvmCircuit as TestEvmCircuit;

pub use crate::witness;
Expand Down Expand Up @@ -184,7 +184,8 @@ impl<F: Field> EvmCircuit<F> {
}
}

pub fn new_dev(block: Block<F>, fixed_table_tags: Vec<FixedTableTag>) -> Self {
pub fn get_test_cicuit_from_block(block: Block<F>) -> Self {
let fixed_table_tags = detect_fixed_table_tags(&block);
Self {
block: Some(block),
fixed_table_tags,
Expand Down Expand Up @@ -290,7 +291,7 @@ pub(crate) fn detect_fixed_table_tags<F: Field>(block: &Block<F>) -> Vec<FixedTa
.collect()
}

#[cfg(any(feature = "test", test))]
#[cfg(any(feature = "test-util", test))]
pub(crate) mod cached {
use super::*;
use halo2_proofs::halo2curves::bn256::Fr;
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ pub struct ExecutionConfig<F> {
error_oog_code_store: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorOutOfGasCodeStore }>>,
error_invalid_jump: Box<ErrorInvalidJumpGadget<F>>,
error_invalid_opcode: Box<ErrorInvalidOpcodeGadget<F>>,
error_depth: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorDepth }>>,
error_contract_address_collision:
_error_depth: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorDepth }>>,
hero78119 marked this conversation as resolved.
Show resolved Hide resolved
_error_contract_address_collision:
Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorContractAddressCollision }>>,
error_invalid_creation_code: Box<ErrorInvalidCreationCodeGadget<F>>,
error_return_data_out_of_bound: Box<ErrorReturnDataOutOfBoundGadget<F>>,
Expand Down Expand Up @@ -574,8 +574,8 @@ impl<F: Field> ExecutionConfig<F> {
error_invalid_jump: configure_gadget!(),
error_invalid_opcode: configure_gadget!(),
error_write_protection: configure_gadget!(),
error_depth: configure_gadget!(),
error_contract_address_collision: configure_gadget!(),
_error_depth: configure_gadget!(),
_error_contract_address_collision: configure_gadget!(),
error_invalid_creation_code: configure_gadget!(),
error_return_data_out_of_bound: configure_gadget!(),
// step and presets
Expand Down
2 changes: 0 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub(crate) struct BeginTxGadget<F> {
tx_callee_address: WordCell<F>,
call_callee_address: AccountAddress<F>,
tx_is_create: Cell<F>,
tx_value: Word32Cell<F>,
tx_call_data_length: Cell<F>,
tx_call_data_gas_cost: Cell<F>,
tx_call_data_word_length: ConstantDivisionGadget<F, N_BYTES_U64>,
Expand Down Expand Up @@ -480,7 +479,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
tx_callee_address,
call_callee_address,
tx_is_create,
tx_value,
tx_call_data_length,
tx_call_data_gas_cost,
tx_call_data_word_length,
Expand Down
1 change: 0 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ mod test {
use lazy_static::lazy_static;
use mock::{eth, TestContext};

const CALLEE_ADDRESS: Address = Address::repeat_byte(0xff);
lazy_static! {
static ref CALLER_ADDRESS: Address = address!("0x00bbccddee000000000000000000000000002400");
}
Expand Down
2 changes: 0 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/end_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub(crate) struct EndBlockGadget<F> {
max_txs: Cell<F>,
}

const EMPTY_BLOCK_N_RWS: u64 = 0;

impl<F: Field> ExecutionGadget<F> for EndBlockGadget<F> {
const NAME: &'static str = "EndBlock";

Expand Down
57 changes: 0 additions & 57 deletions zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ mod test {
.run();
}

// internal call test
struct Stack {
gas: u64,
value: Word,
cd_offset: u64,
cd_length: u64,
rd_offset: u64,
rd_length: u64,
}

fn callee(code: Bytecode) -> Account {
let code = code.to_vec();
let is_empty = code.is_empty();
Expand All @@ -265,53 +255,6 @@ mod test {
}
}

fn caller(opcode: OpcodeId, stack: Stack, caller_is_success: bool) -> Account {
let is_call = opcode == OpcodeId::CALL;
let terminator = if caller_is_success {
OpcodeId::RETURN
} else {
OpcodeId::REVERT
};

// Call twice for testing both cold and warm access
let mut bytecode = bytecode! {
PUSH32(Word::from(stack.rd_length))
PUSH32(Word::from(stack.rd_offset))
PUSH32(Word::from(stack.cd_length))
PUSH32(Word::from(stack.cd_offset))
};
if is_call {
bytecode.push(32, stack.value);
}
bytecode.append(&bytecode! {
PUSH32(Address::repeat_byte(0xff).to_word())
PUSH32(Word::from(stack.gas))
.write_op(opcode)
PUSH32(Word::from(stack.rd_length))
PUSH32(Word::from(stack.rd_offset))
PUSH32(Word::from(stack.cd_length))
PUSH32(Word::from(stack.cd_offset))
});
if is_call {
bytecode.push(32, stack.value);
}
bytecode.append(&bytecode! {
PUSH32(Address::repeat_byte(0xff).to_word())
PUSH32(Word::from(stack.gas))
.write_op(opcode)
PUSH1(0)
PUSH1(0)
.write_op(terminator)
});

Account {
address: Address::repeat_byte(0xfe),
balance: Word::from(10).pow(20.into()),
code: bytecode.to_vec().into(),
..Default::default()
}
}

// jump or jumpi error happen in internal call
fn test_internal_jump_error(is_jumpi: bool) {
let mut caller_bytecode = bytecode! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ mod test {
#[derive(Default)]
struct TestingData {
key: U256,
value: U256,
value_prev: U256,
original_value: U256,
is_warm: bool,
gas_cost: u64,
bytecode: Bytecode,
}
Expand Down Expand Up @@ -443,10 +440,7 @@ mod test {

Self {
key,
value,
value_prev,
original_value,
is_warm,
gas_cost,
bytecode,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
},
};
use eth_types::{evm_types::OpcodeId, Field, ToLittleEndian};
use halo2_proofs::plonk::Error;
use halo2_proofs::{circuit::Value, plonk::Error};

#[derive(Clone, Debug)]
pub(crate) struct ErrorOOGStaticMemoryGadget<F> {
Expand Down Expand Up @@ -99,6 +99,8 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGStaticMemoryGadget<F> {
step: &ExecStep,
) -> Result<(), Error> {
let opcode = step.opcode().unwrap();
self.opcode
.assign(region, offset, Value::known(F::from(opcode.as_u64())))?;

// Inputs/Outputs
let address = block.get_rws(step, 0).stack_value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,10 @@ impl<F: Field> ExecutionGadget<F> for ErrorWriteProtectionGadget<F> {
mod test {
use crate::test_util::CircuitTestBuilder;
use eth_types::{
address, bytecode, bytecode::Bytecode, evm_types::OpcodeId, geth_types::Account, Address,
ToWord, Word, U64,
address, bytecode, bytecode::Bytecode, geth_types::Account, Address, ToWord, Word, U64,
};
use mock::TestContext;

// internal call test
struct Stack {
gas: u64,
value: Word,
cd_offset: u64,
cd_length: u64,
rd_offset: u64,
rd_length: u64,
}

fn callee(code: Bytecode) -> Account {
let code = code.to_vec();
let is_empty = code.is_empty();
Expand All @@ -172,52 +161,6 @@ mod test {
}
}

fn caller(opcode: OpcodeId, stack: Stack, caller_is_success: bool) -> Account {
let is_call = opcode == OpcodeId::CALL;
let terminator = if caller_is_success {
OpcodeId::RETURN
} else {
OpcodeId::REVERT
};

let mut bytecode = bytecode! {
PUSH32(Word::from(stack.rd_length))
PUSH32(Word::from(stack.rd_offset))
PUSH32(Word::from(stack.cd_length))
PUSH32(Word::from(stack.cd_offset))
};
if is_call {
bytecode.push(32, stack.value);
}
bytecode.append(&bytecode! {
PUSH32(Address::repeat_byte(0xff).to_word())
PUSH32(Word::from(stack.gas))
.write_op(opcode)
PUSH32(Word::from(stack.rd_length))
PUSH32(Word::from(stack.rd_offset))
PUSH32(Word::from(stack.cd_length))
PUSH32(Word::from(stack.cd_offset))
});
if is_call {
bytecode.push(32, stack.value);
}
bytecode.append(&bytecode! {
PUSH32(Address::repeat_byte(0xff).to_word())
PUSH32(Word::from(stack.gas))
.write_op(opcode)
PUSH1(0)
PUSH1(0)
.write_op(terminator)
});

Account {
address: Address::repeat_byte(0xfe),
balance: Word::from(10).pow(20.into()),
code: bytecode.to_vec().into(),
..Default::default()
}
}

#[test]
fn test_write_protection() {
// test sstore with write protection error
Expand Down
5 changes: 5 additions & 0 deletions zkevm-circuits/src/evm_circuit/execution/jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ mod test {
test_ok(rand_range(34..1 << 11));
}

#[test]
fn invalid_jump_err() {
test_invalid_jump(34);
}

#[test]
#[ignore]
fn jump_gadget_rand_huge_bytecode() {
Expand Down
Loading
Loading