Skip to content

Commit

Permalink
refactor: mv Field from eth-types to zkevm-circuits (#1240)
Browse files Browse the repository at this point in the history
* move CodeDB and StateDB

* update execute_precompiled

* fix precompile

* fix doc

* add revm primitives conversion

* update zktrie

* clean deps

* done

---------

Co-authored-by: lightsing <light.tsing@gmail.com>
Co-authored-by: Akase Haruka <lightsing@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 29, 2024
1 parent 5dd697b commit 209f4eb
Show file tree
Hide file tree
Showing 185 changed files with 399 additions and 375 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions circuit-benchmarks/src/bytecode_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
mod tests {
use ark_std::{end_timer, start_timer};
use bus_mapping::evm::OpcodeId;
use eth_types::{evm_types::MAX_CODE_SIZE, Field};
use eth_types::evm_types::MAX_CODE_SIZE;
use halo2_proofs::{
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::{create_proof, keygen_pk, keygen_vk, verify_proof},
Expand All @@ -28,7 +28,7 @@ mod tests {
bytecode_unroller::{unroll, UnrolledBytecode},
TestBytecodeCircuit,
},
util::SubCircuit,
util::{Field, SubCircuit},
};

#[cfg_attr(not(feature = "benches"), ignore)]
Expand Down
1 change: 0 additions & 1 deletion eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ ethers-core.workspace = true
ethers-signers.workspace = true
hex.workspace = true
halo2_proofs.workspace = true
halo2-base.workspace = true
log.workspace = true
regex.workspace = true
serde.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub use ethers_core::{
Address, Block, Bytes, Signature, H160, H256, H64, U256, U64,
},
};
use halo2_base::utils::ScalarField;
use halo2_proofs::halo2curves::{bn256::Fr, group::ff::PrimeField};
use serde::{de, Deserialize, Deserializer, Serialize};
use std::{
Expand Down Expand Up @@ -89,7 +88,7 @@ pub mod base64 {
/// Trait used to reduce verbosity with the declaration of the [`Field`]
/// trait and its repr.
pub trait Field:
PrimeField<Repr = [u8; 32]> + hash_circuit::hash::Hashable + std::convert::From<Fr> + ScalarField
PrimeField<Repr = [u8; 32]> + hash_circuit::hash::Hashable + std::convert::From<Fr>
{
/// Re-expose zero element as a function
fn zero() -> Self {
Expand Down
7 changes: 5 additions & 2 deletions zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{table::BytecodeFieldTag, util::get_push_size};
use eth_types::{state_db::CodeDB, Field, ToWord, Word, U256};
use crate::{
table::BytecodeFieldTag,
util::{get_push_size, Field},
};
use eth_types::{state_db::CodeDB, ToWord, Word, U256};
use std::vec;

/// Public data for the bytecode
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/bytecode_circuit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use crate::{
not, or, rlc, select,
},
table::{BytecodeFieldTag, BytecodeTable, KeccakTable, LookupTable},
util::{get_push_size, Challenges, Expr, SubCircuit, SubCircuitConfig},
util::{get_push_size, Challenges, Expr, Field, SubCircuit, SubCircuitConfig},
witness,
};
use eth_types::{
state_db::EMPTY_CODE_HASH_LE, Field, ToLittleEndian, ToScalar, ToWord, POSEIDON_CODE_HASH_EMPTY,
state_db::EMPTY_CODE_HASH_LE, ToLittleEndian, ToScalar, ToWord, POSEIDON_CODE_HASH_EMPTY,
};
use gadgets::is_zero::{IsZeroChip, IsZeroConfig, IsZeroInstruction};
use halo2_proofs::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use crate::{
not, or, select,
},
table::{BytecodeFieldTag, KeccakTable, PoseidonTable},
util::{Challenges, Expr, SubCircuitConfig},
util::{Challenges, Expr, Field, SubCircuitConfig},
};
use bus_mapping::util::POSEIDON_CODE_HASH_EMPTY;
use eth_types::{Field, ToScalar, ToWord};
use eth_types::{ToScalar, ToWord};
use gadgets::is_zero::IsZeroChip;
use halo2_proofs::{
circuit::{Layouter, Region, Value},
Expand Down
3 changes: 1 addition & 2 deletions zkevm-circuits/src/bytecode_circuit/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ pub use super::circuit::BytecodeCircuit;
use crate::{
bytecode_circuit::circuit::BytecodeCircuitConfigArgs,
table::{BytecodeTable, KeccakTable},
util::{Challenges, SubCircuit, SubCircuitConfig},
util::{Challenges, Field, SubCircuit, SubCircuitConfig},
};
use eth_types::Field;
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner},
plonk::{Circuit, ConstraintSystem, Error},
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/bytecode_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use crate::{
bytecode_circuit::{bytecode_unroller::*, circuit::BytecodeCircuit},
table::BytecodeFieldTag,
util::{is_push_with_data, keccak, unusable_rows, Challenges, SubCircuit},
util::{is_push_with_data, keccak, unusable_rows, Challenges, Field, SubCircuit},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{state_db::CodeDB, Bytecode, Field, ToWord, Word};
use eth_types::{state_db::CodeDB, Bytecode, ToWord, Word};
use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr};
use log::error;

Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/copy_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ mod test;
#[cfg(any(feature = "test", test, feature = "test-circuits"))]
pub use dev::CopyCircuit as TestCopyCircuit;

use crate::util::Field;
use array_init::array_init;
use bus_mapping::circuit_input_builder::{CopyDataType, CopyEvent};
use eth_types::{Field, Word};
use eth_types::Word;
use gadgets::{
binary_number::BinaryNumberChip,
is_equal::{IsEqualChip, IsEqualConfig, IsEqualInstruction},
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/copy_circuit/copy_gadgets.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{CURRENT, NEXT_ROW, NEXT_STEP};
use crate::util::Field;
use bus_mapping::circuit_input_builder::CopyDataType;
use eth_types::Field;
use gadgets::{
binary_number::BinaryNumberConfig,
is_equal::IsEqualConfig,
Expand Down
3 changes: 1 addition & 2 deletions zkevm-circuits/src/copy_circuit/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ pub use super::CopyCircuit;
use crate::{
copy_circuit::{CopyCircuitConfig, CopyCircuitConfigArgs},
table::{BytecodeTable, CopyTable, RwTable, TxTable},
util::{Challenges, SubCircuit, SubCircuitConfig},
util::{Challenges, Field, SubCircuit, SubCircuitConfig},
};
use eth_types::Field;
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner},
plonk::{Challenge, Circuit, ConstraintSystem, Error},
Expand Down
3 changes: 1 addition & 2 deletions zkevm-circuits/src/copy_circuit/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::evm_circuit::util::rlc;
use crate::{evm_circuit::util::rlc, util::Field};
use bus_mapping::circuit_input_builder::NumberOrHash;
use eth_types::Field;
use halo2_proofs::circuit::Value;

/// Encode the type `NumberOrHash` into a field element
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/ecc_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

use std::{iter, marker::PhantomData};

use crate::util::Field;
use bus_mapping::{
circuit_input_builder::{EcAddOp, EcMulOp, EcPairingOp, N_BYTES_PER_PAIR, N_PAIRING_PER_OP},
precompile::PrecompileCalls,
};
use eth_types::{Field, ToLittleEndian, ToScalar, U256};
use eth_types::{ToLittleEndian, ToScalar, U256};
use halo2_base::{
gates::{GateInstructions, RangeInstructions},
utils::{decompose_bigint_option, fe_to_biguint, modulus},
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/ecc_circuit/dev.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eth_types::Field;
use crate::util::Field;
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner},
plonk::{Challenge, Circuit, ConstraintSystem, Error},
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/ecc_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::{
ops::{Add, Mul, Neg},
};

use crate::util::Field;
use bus_mapping::circuit_input_builder::{
EcAddOp, EcMulOp, EcPairingOp, EcPairingPair, PrecompileEcParams,
};
use eth_types::{Field, U256};
use eth_types::U256;
use halo2_proofs::{
arithmetic::Field as ArithmeticField,
dev::MockProver,
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/ecc_circuit/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eth_types::Field;
use crate::util::Field;
use halo2_base::{AssignedValue, QuantumCell};
use halo2_ecc::{bigint::CRTInteger, ecc::EcPoint, fields::FieldExtPoint};

Expand Down
3 changes: 1 addition & 2 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ use crate::{
BlockTable, BytecodeTable, CopyTable, EccTable, ExpTable, KeccakTable, LookupTable,
ModExpTable, PowOfRandTable, RwTable, SHA256Table, SigTable, TxTable,
},
util::{SubCircuit, SubCircuitConfig},
util::{Field, SubCircuit, SubCircuitConfig},
};
use bus_mapping::evm::OpcodeId;
use eth_types::Field;
use execution::ExecutionConfig;
use itertools::Itertools;
use strum::IntoEnumIterator;
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::{LookupTable, RwTableTag, TxReceiptFieldTag},
util::{query_expression, Challenges, Expr},
util::{query_expression, Challenges, Expr, Field},
};
use bus_mapping::util::read_env_var;
use eth_types::{Field, ToLittleEndian};
use eth_types::ToLittleEndian;
use gadgets::util::not;
use halo2_proofs::{
circuit::{Layouter, Region, Value},
Expand Down
3 changes: 1 addition & 2 deletions zkevm-circuits/src/evm_circuit/execution/add_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ use crate::{
},
witness::{Block, Call, ExecStep, Transaction},
},
util::Expr,
util::{Expr, Field},
};
use bus_mapping::evm::OpcodeId;
use eth_types::Field;
use halo2_proofs::plonk::Error;

// AddGadget verifies ADD and SUB at the same time by an extra swap flag,
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/addmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use crate::{
util::Expr,
};

use crate::util::Field;
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToLittleEndian, U256, U512};
use eth_types::{ToLittleEndian, U256, U512};
use halo2_proofs::plonk::Error;

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::CallContextFieldTag,
util::Expr,
util::{Expr, Field},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToAddress, ToLittleEndian};
use eth_types::{ToAddress, ToLittleEndian};
use halo2_proofs::plonk::Error;
use std::convert::TryInto;

Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::{AccountFieldTag, CallContextFieldTag},
util::Expr,
util::{Expr, Field},
};
use eth_types::{evm_types::GasCost, Field, ToLittleEndian};
use eth_types::{evm_types::GasCost, ToLittleEndian};
use halo2_proofs::{circuit::Value, plonk::Error};

#[derive(Clone, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ use crate::{
AccountFieldTag, BlockContextFieldTag, CallContextFieldTag, RwTableTag,
TxFieldTag as TxContextFieldTag,
},
util::Field,
};
use array_init::array_init;
use bus_mapping::{circuit_input_builder::CopyDataType, precompile::PrecompileCalls};
use eth_types::{utils::is_precompiled, Address, Field, ToLittleEndian, ToScalar, U256};
use eth_types::{utils::is_precompiled, Address, ToLittleEndian, ToScalar, U256};
use ethers_core::utils::{get_contract_address, keccak256, rlp::RlpStream};
use gadgets::util::{expr_from_bytes, not, select, Expr};
use halo2_proofs::{circuit::Value, plonk::Error};
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::{
},
witness::{Block, Call, ExecStep, Transaction},
},
util::Expr,
util::{Expr, Field},
};
use eth_types::{evm_types::OpcodeId, Field, ToLittleEndian};
use eth_types::{evm_types::OpcodeId, ToLittleEndian};
use halo2_proofs::plonk::Error;

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/block_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::BlockContextFieldTag,
util::Expr,
util::{Expr, Field},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToLittleEndian};
use eth_types::ToLittleEndian;
use halo2_proofs::plonk::Error;

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/blockhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::BlockContextFieldTag,
util::Expr,
util::{Expr, Field},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{
evm_types::block_utils::{is_valid_block_number, NUM_PREV_BLOCK_ALLOWED},
Field, ToScalar,
ToScalar,
};
use gadgets::util::not;
use halo2_proofs::{circuit::Value, plonk::Error};
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use crate::{
},
witness::{Block, Call, ExecStep, Transaction},
},
util::Expr,
util::{Expr, Field},
};
use array_init::array_init;
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToLittleEndian};
use eth_types::ToLittleEndian;
use halo2_proofs::plonk::Error;

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::CallContextFieldTag,
util::Expr,
util::{Expr, Field},
};
use bus_mapping::{circuit_input_builder::CopyDataType, evm::OpcodeId};
use eth_types::{evm_types::GasCost, Field, ToScalar};
use eth_types::{evm_types::GasCost, ToScalar};
use halo2_proofs::{circuit::Value, plonk::Error};

#[derive(Clone, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/calldataload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::util::Field;
use array_init::array_init;
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToLittleEndian};
use eth_types::ToLittleEndian;
use halo2_proofs::{
circuit::Value,
plonk::{Error, Expression},
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/calldatasize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::CallContextFieldTag,
util::Expr,
util::{Expr, Field},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToLittleEndian};
use eth_types::ToLittleEndian;
use halo2_proofs::plonk::Error;

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::CallContextFieldTag,
util::Expr,
util::{Expr, Field},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToLittleEndian};
use eth_types::ToLittleEndian;
use halo2_proofs::plonk::Error;

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::{AccountFieldTag, CallContextFieldTag},
util::Expr,
util::{Expr, Field},
};
use bus_mapping::{
circuit_input_builder::CopyDataType, evm::OpcodeId, precompile::PrecompileCalls,
};
use eth_types::{
evm_types::{memory::MemoryWordRange, GAS_STIPEND_CALL_WITH_VALUE},
utils::is_precompiled,
Field, ToAddress, ToBigEndian, ToLittleEndian, ToScalar, U256,
ToAddress, ToBigEndian, ToLittleEndian, ToScalar, U256,
};
use halo2_proofs::{circuit::Value, plonk::Error};
use log::trace;
Expand Down
Loading

0 comments on commit 209f4eb

Please sign in to comment.