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(eof): eofcreate code deploy gas #1540

Merged
merged 2 commits into from
Jun 18, 2024
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
5 changes: 5 additions & 0 deletions crates/interpreter/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ impl Gas {
self.remaining
}

/// Return remaining gas after subtracting 63/64 parts.
pub const fn remaining_63_of_64_parts(&self) -> u64 {
self.remaining - self.remaining / 64
}

/// Erases a gas cost from the totals.
#[inline]
pub fn erase_cost(&mut self, returned: u64) {
Expand Down
4 changes: 1 addition & 3 deletions crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ pub fn eofcreate<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &mut H)
.target_address
.create2(salt.to_be_bytes(), keccak256(sub_container));

let gas_reduce = max(interpreter.gas.remaining() / 64, 5000);
let gas_limit = interpreter.gas().remaining().saturating_sub(gas_reduce);
let gas_limit = interpreter.gas().remaining_63_of_64_parts();
gas!(interpreter, gas_limit);

// Send container for execution container is preverified.
interpreter.instruction_result = InstructionResult::CallOrCreate;
interpreter.next_action = InterpreterAction::EOFCreate {
Expand Down
6 changes: 4 additions & 2 deletions crates/interpreter/src/instructions/contract/call_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ pub fn calc_call_gas<SPEC: Spec>(

// EIP-150: Gas cost changes for IO-heavy operations
let gas_limit = if SPEC::enabled(TANGERINE) {
let gas = interpreter.gas().remaining();
// take l64 part of gas_limit
min(gas - gas / 64, local_gas_limit)
min(
interpreter.gas().remaining_63_of_64_parts(),
local_gas_limit,
)
} else {
local_gas_limit
};
Expand Down
8 changes: 8 additions & 0 deletions crates/revm/src/context/inner_evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ impl<DB: Database> InnerEvmContext<DB> {
return;
}

// deduct gas for code deployment.
let gas_for_code = interpreter_result.output.len() as u64 * gas::CODEDEPOSIT;
if !interpreter_result.gas.record_cost(gas_for_code) {
self.journaled_state.checkpoint_revert(journal_checkpoint);
interpreter_result.result = InstructionResult::OutOfGas;
return;
}

// commit changes reduces depth by -1.
self.journaled_state.checkpoint_commit();

Expand Down
Loading