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

rpcdaemon: if gas bailout subtract only if there is enough balance #2178

Merged
merged 4 commits into from
Jul 15, 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.29.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.30.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
cd ${{runner.workspace}}/rpc-tests
pip3 install -r requirements.txt

Expand Down
14 changes: 10 additions & 4 deletions silkworm/core/execution/evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ 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 (!gas_bailout_ && state_.get_balance(message.sender) < value) {
const auto have = state_.get_balance(message.sender);
if (!gas_bailout_ && have < value) {
res.status_code = EVMC_INSUFFICIENT_BALANCE;

for (auto tracer : tracers_) {
Expand Down Expand Up @@ -149,7 +150,9 @@ evmc::Result EVM::create(const evmc_message& message) noexcept {
state_.set_nonce(contract_addr, 1);
}

state_.subtract_from_balance(message.sender, value);
if (!gas_bailout_ || have >= value) {
state_.subtract_from_balance(message.sender, value);
}
state_.add_to_balance(contract_addr, value);

const evmc_message deploy_message{
Expand Down Expand Up @@ -204,7 +207,8 @@ 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 (!gas_bailout_ && message.kind != EVMC_DELEGATECALL && state_.get_balance(message.sender) < value) {
const auto have = state_.get_balance(message.sender);
if (!gas_bailout_ && message.kind != EVMC_DELEGATECALL && have < value) {
res.status_code = EVMC_INSUFFICIENT_BALANCE;
return res;
}
Expand All @@ -217,7 +221,9 @@ evmc::Result EVM::call(const evmc_message& message) noexcept {
// https://github.com/ethereum/go-ethereum/blob/v1.9.25/core/vm/evm.go#L391
state_.touch(message.recipient);
} else {
state_.subtract_from_balance(message.sender, value);
if (!gas_bailout_ || have >= value) {
state_.subtract_from_balance(message.sender, value);
}
state_.add_to_balance(message.recipient, value);
}
}
Expand Down
4 changes: 2 additions & 2 deletions silkworm/rpc/core/evm_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ TEST_CASE_METHOD(EVMExecutorTest, "EVMExecutor") {
}

SECTION("doesn't fail if transaction cost greater user amount && gasBailout == true") {
EXPECT_CALL(transaction, get(_, _)).Times(7).WillRepeatedly(InvokeWithoutArgs([]() -> Task<KeyValue> { co_return KeyValue{}; }));
EXPECT_CALL(transaction, get_one(_, _)).Times(7).WillRepeatedly(InvokeWithoutArgs([]() -> Task<Bytes> { co_return Bytes{}; }));
EXPECT_CALL(transaction, get(_, _)).Times(8).WillRepeatedly(InvokeWithoutArgs([]() -> Task<KeyValue> { co_return KeyValue{}; }));
EXPECT_CALL(transaction, get_one(_, _)).Times(8).WillRepeatedly(InvokeWithoutArgs([]() -> Task<Bytes> { co_return Bytes{}; }));

silkworm::Block block{};
block.header.base_fee_per_gas = 0x1;
Expand Down
Loading