Skip to content

Commit

Permalink
evm: refactor bailout option handling
Browse files Browse the repository at this point in the history
Implement the bailout option by pure state modification before
the transaction validation and execution.
  • Loading branch information
chfast committed Jan 21, 2025
1 parent 1590ab6 commit 987d04c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions silkworm/core/execution/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ CallResult ExecutionProcessor::call(const Transaction& txn, const std::vector<st

SILKWORM_ASSERT(protocol::validate_call_precheck(txn, evm_) == ValidationResult::kOk);

if (!evm().bailout) {
SILKWORM_ASSERT(protocol::validate_call_funds(txn, evm_, state_.get_balance(*txn.sender())) == ValidationResult::kOk);
}

const BlockHeader& header{evm_.block().header};
const intx::uint256 base_fee_per_gas{header.base_fee_per_gas.value_or(0)};

Expand All @@ -284,10 +280,15 @@ CallResult ExecutionProcessor::call(const Transaction& txn, const std::vector<st
state_.set_nonce(*sender, state_.get_nonce(*txn.sender()) + 1);
}

if (!evm().bailout) {
const intx::uint256 required_funds = protocol::compute_call_cost(txn, effective_gas_price, evm_);
state_.subtract_from_balance(*txn.sender(), required_funds);
const intx::uint256 required_funds = protocol::compute_call_cost(txn, effective_gas_price, evm_);
if (evm().bailout) {
// If the bailout option is on, add the required funds to the sender's balance
// so that after the transaction costs are deducted, the sender's balance is unchanged.
state_.add_to_balance(*txn.sender(), required_funds);
}

SILKWORM_ASSERT(protocol::validate_call_funds(txn, evm_, state_.get_balance(*txn.sender())) == ValidationResult::kOk);
state_.subtract_from_balance(*txn.sender(), required_funds);
const intx::uint128 g0{protocol::intrinsic_gas(txn, evm_.revision())};
const auto result = evm_.execute(txn, txn.gas_limit - static_cast<uint64_t>(g0));

Expand Down

0 comments on commit 987d04c

Please sign in to comment.