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

evm: refactor bailout option handling #2668

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand why we are subtracting different values depending on the bailout on/off. This still feels quite a hack.

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
Loading