Skip to content

Commit

Permalink
chore(cfg): convert chain_id from u256 to u64 (bluealloy#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb authored and Evalir committed Sep 14, 2023
1 parent 92f17e8 commit 9343bf7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bins/revme/src/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn execute_test_suite(
}
let mut env = Env::default();
// cfg env. SpecId is set down the road
env.cfg.chain_id = U256::from(1); // for mainnet
env.cfg.chain_id = 1; // for mainnet

// block env
env.block.number = unit.env.current_number;
Expand Down
4 changes: 3 additions & 1 deletion crates/interpreter/src/instructions/host_env.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use revm_primitives::U256;

use crate::{
gas, interpreter::Interpreter, primitives::Spec, primitives::SpecId::*, Host, InstructionResult,
};
Expand All @@ -6,7 +8,7 @@ pub fn chainid<SPEC: Spec>(interpreter: &mut Interpreter, host: &mut dyn Host) {
// EIP-1344: ChainID opcode
check!(interpreter, SPEC::enabled(ISTANBUL));
gas!(interpreter, gas::BASE);
push!(interpreter, host.env().cfg.chain_id);
push!(interpreter, U256::from(host.env().cfg.chain_id));
}

pub fn coinbase(interpreter: &mut Interpreter, host: &mut dyn Host) {
Expand Down
6 changes: 3 additions & 3 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub enum CreateScheme {
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub struct CfgEnv {
pub chain_id: U256,
pub chain_id: u64,
pub spec_id: SpecId,
/// Bytecode that is created with CREATE/CREATE2 is by default analysed and jumptable is created.
/// This is very beneficial for testing and speeds up execution of that bytecode if called multiple times.
Expand Down Expand Up @@ -187,7 +187,7 @@ pub enum AnalysisKind {
impl Default for CfgEnv {
fn default() -> CfgEnv {
CfgEnv {
chain_id: U256::from(1),
chain_id: 1,
spec_id: SpecId::LATEST,
perf_analyse_created_bytecodes: Default::default(),
limit_contract_code_size: None,
Expand Down Expand Up @@ -307,7 +307,7 @@ impl Env {

// Check if the transaction's chain id is correct
if let Some(tx_chain_id) = self.tx.chain_id {
if U256::from(tx_chain_id) != self.cfg.chain_id {
if tx_chain_id != self.cfg.chain_id {
return Err(InvalidTransaction::InvalidChainId);
}
}
Expand Down

0 comments on commit 9343bf7

Please sign in to comment.