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

core, rpcdaemon: gas bailout in EVM #2031

Merged
merged 3 commits into from
May 22, 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
2 changes: 1 addition & 1 deletion .github/workflows/rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Checkout RPC Tests Repository & Install Requirements
run: |
rm -rf ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.19.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.21.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
cd ${{runner.workspace}}/rpc-tests
pip3 install -r requirements.txt

Expand Down
7 changes: 4 additions & 3 deletions silkworm/core/execution/evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ class DelegatingTracer : public evmone::Tracer {
IntraBlockState& intra_block_state_;
};

EVM::EVM(const Block& block, IntraBlockState& state, const ChainConfig& config) noexcept
EVM::EVM(const Block& block, IntraBlockState& state, const ChainConfig& config, bool gas_bailout) noexcept
: beneficiary{block.header.beneficiary},
block_{block},
state_{state},
config_{config},
gas_bailout_{gas_bailout},
evm1_{static_cast<evmone::VM*>(evmc_create_evmone())} // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
{}

Expand Down Expand Up @@ -99,7 +100,7 @@ evmc::Result EVM::create(const evmc_message& message) noexcept {
evmc::Result res{EVMC_SUCCESS, message.gas, 0};

auto value{intx::be::load<intx::uint256>(message.value)};
if (state_.get_balance(message.sender) < value) {
if (!gas_bailout_ && state_.get_balance(message.sender) < value) {
res.status_code = EVMC_INSUFFICIENT_BALANCE;

for (auto tracer : tracers_) {
Expand Down Expand Up @@ -203,7 +204,7 @@ evmc::Result EVM::call(const evmc_message& message) noexcept {
evmc::Result res{EVMC_SUCCESS, message.gas};

const auto value{intx::be::load<intx::uint256>(message.value)};
if (message.kind != EVMC_DELEGATECALL && state_.get_balance(message.sender) < value) {
if (!gas_bailout_ && message.kind != EVMC_DELEGATECALL && state_.get_balance(message.sender) < value) {
res.status_code = EVMC_INSUFFICIENT_BALANCE;
return res;
}
Sixtysixter marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 2 additions & 1 deletion silkworm/core/execution/evm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class EVM {
EVM(const EVM&) = delete;
EVM& operator=(const EVM&) = delete;

EVM(const Block& block, IntraBlockState& state, const ChainConfig& config) noexcept;
EVM(const Block& block, IntraBlockState& state, const ChainConfig& config, bool gas_bailout = false) noexcept;

~EVM();

Expand Down Expand Up @@ -122,6 +122,7 @@ class EVM {
const Block& block_;
IntraBlockState& state_;
const ChainConfig& config_;
bool gas_bailout_;
const Transaction* txn_{nullptr};
std::vector<evmc::bytes32> block_hashes_{};
EvmTracers tracers_;
Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/evm_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ ExecutionResult EVMExecutor::call(
SILK_DEBUG << "EVMExecutor::call: transaction: " << rpc::Transaction{txn};

auto& svc = use_service<AnalysisCacheService>(workers_);
EVM evm{block, ibs_state_, config_};
EVM evm{block, ibs_state_, config_, gas_bailout};
evm.analysis_cache = svc.get_analysis_cache();
evm.state_pool = svc.get_object_pool();
evm.beneficiary = rule_set_->get_beneficiary(block.header);
Expand Down
Loading