Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use shanghai config instead of london #773

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions engine-tests/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn erc20_mint_out_of_gas() {

// not enough gas to cover intrinsic cost
let intrinsic_gas = test_utils::erc20::legacy_into_normalized_tx(mint_tx.clone())
.intrinsic_gas(&evm::Config::istanbul())
.intrinsic_gas(&evm::Config::shanghai())
.unwrap();
mint_tx.gas_limit = (intrinsic_gas - 1).into();
let error = runner
Expand Down Expand Up @@ -214,7 +214,7 @@ fn deploy_erc_20_out_of_gas() {

// not enough gas to cover intrinsic cost
let intrinsic_gas = test_utils::erc20::legacy_into_normalized_tx(deploy_transaction.clone())
.intrinsic_gas(&evm::Config::istanbul())
.intrinsic_gas(&evm::Config::shanghai())
.unwrap();
deploy_transaction.gas_limit = (intrinsic_gas - 1).into();
let error = runner
Expand Down
15 changes: 14 additions & 1 deletion engine-transactions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl NormalizedEthTransaction {
let is_contract_creation = self.to.is_none();

let base_gas = if is_contract_creation {
config.gas_transaction_create
config.gas_transaction_create + init_code_cost(config, &self.data)?
} else {
config.gas_transaction_call
};
Expand Down Expand Up @@ -185,6 +185,19 @@ impl NormalizedEthTransaction {
}
}

fn init_code_cost(config: &evm::Config, data: &[u8]) -> Result<u64, Error> {
// As per EIP-3860:
// > We define initcode_cost(initcode) to equal INITCODE_WORD_COST * ceil(len(initcode) / 32).
// where INITCODE_WORD_COST is 2.
let init_code_cost = if config.max_initcode_size.is_some() {
2 * ((u64::try_from(data.len()).map_err(|_| Error::IntegerConversion)? + 31) / 32)
} else {
0
};

Ok(init_code_cost)
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub enum Error {
Expand Down
2 changes: 1 addition & 1 deletion engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub struct Engine<'env, I: IO, E: Env, M = AuroraModExp> {
modexp_algorithm: PhantomData<M>,
}

pub(crate) const CONFIG: &Config = &Config::london();
pub(crate) const CONFIG: &Config = &Config::shanghai();

impl<'env, I: IO + Copy, E: Env, M: ModExpAlgorithm> Engine<'env, I, E, M> {
pub fn new(
Expand Down