Skip to content
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/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
- name: 'Tar debug files'
if: failure()
run: tar cfz debug_files.tar.gz -C /tmp/pytest-of-runner .
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: failure()
with:
name: debug-files
Expand Down
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ linters:
- misspell
- nakedret
- prealloc
- exportloopref
- staticcheck
- stylecheck
- typecheck
Expand All @@ -30,7 +29,6 @@ linters:
- unused
- nolintlint
- asciicheck
- exportloopref
- gofumpt
- gomodguard
- whitespace
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (ante) [#560](https://github.com/crypto-org-chain/ethermint/pull/560) Check gasWanted only in checkTx mode.
* (rpc) [#562](https://github.com/crypto-org-chain/ethermint/pull/562) Fix nil pointer panic with legacy transaction format.
* (evm) [#567](https://github.com/crypto-org-chain/ethermint/pull/567) Fix nonce management in batch transaction.
* (rpc) [#574](https://github.com/crypto-org-chain/ethermint/pull/574) Fix incorrect spendable balance when debug trace tx.

### Improvements

Expand Down
19 changes: 19 additions & 0 deletions tests/integration_tests/hardhat/contracts/SelfDestruct.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SelfDestruct {
address payable recipient = payable(0x0F0cb39319129BA867227e5Aae1abe9e7dd5f861);
address payable owner;

constructor() {
owner = payable(msg.sender);
}

receive() external payable {}

function execute() public payable {
require(msg.sender == owner, string(abi.encodePacked("Unauthorized caller: ", msg.sender, " Owner: ", owner)));
payable(recipient).transfer(msg.value);
selfdestruct(owner);
}
}
52 changes: 52 additions & 0 deletions tests/integration_tests/test_tracers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from concurrent.futures import ThreadPoolExecutor, as_completed

import pytest
from web3 import Web3

from .expected_constants import (
Expand All @@ -24,6 +25,7 @@
send_txs,
sign_transaction,
w3_wait_for_new_blocks,
wait_for_fn,
)


Expand Down Expand Up @@ -191,6 +193,56 @@ def test_trace_tx_reverse_transfer(ethermint):
print(tx_res)


@pytest.mark.flaky(max_runs=10)
def test_destruct(ethermint):
method = "debug_traceTransaction"
tracer = {"tracer": "callTracer"}
receiver = "0x0F0cb39319129BA867227e5Aae1abe9e7dd5f861"
acc = derive_new_account(11) # ethm13c2n7geavjfsqcan290mq74kajjlxehyzhly4p
w3 = ethermint.w3
fund_acc(w3, acc, fund=3077735635376769427)
sender = acc.address
raw_transactions = []
contracts = []
total = 3
for _ in range(total):
contract, _ = deploy_contract(w3, CONTRACTS["SelfDestruct"], key=acc.key)
contracts.append(contract)

nonce = w3.eth.get_transaction_count(sender)

for i in range(total):
tx = (
contracts[i]
.functions.execute()
.build_transaction(
{
"from": sender,
"nonce": nonce,
"gas": 167115,
"gasPrice": 5050000000000,
"value": 353434350000000000,
}
)
)
raw_transactions.append(sign_transaction(w3, tx, acc.key).rawTransaction)
nonce += 1
sended_hash_set = send_raw_transactions(w3, raw_transactions)

def wait_balance():
return w3.eth.get_balance(receiver) > 0

wait_for_fn("wait_balance", wait_balance)
for h in sended_hash_set:
tx_hash = h.hex()
res = w3.provider.make_request(
method,
[tx_hash, tracer],
)
print(tx_hash, res)
assert "insufficient funds" not in res, res


def test_tracecall_insufficient_funds(ethermint, geth):
method = "debug_traceCall"
acc = derive_random_account()
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"Random": "Random.sol",
"TestBlockTxProperties": "TestBlockTxProperties.sol",
"FeeCollector": "FeeCollector.sol",
"SelfDestruct": "SelfDestruct.sol",
}


Expand Down
26 changes: 16 additions & 10 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@
leftoverGas := msg.GasLimit
sender := vm.AccountRef(msg.From)
tracer := cfg.GetTracer()
debugFn := func() {
if tracer != nil && cfg.DebugTrace {
stateDB.AddBalance(sender.Address(), new(big.Int).Mul(msg.GasPrice, new(big.Int).SetUint64(leftoverGas)))
}
}
if tracer != nil {
if cfg.DebugTrace {
amount := new(big.Int).Mul(msg.GasPrice, new(big.Int).SetUint64(msg.GasLimit))
Expand All @@ -337,9 +342,7 @@
}
tracer.CaptureTxStart(leftoverGas)
defer func() {
if cfg.DebugTrace {
stateDB.AddBalance(sender.Address(), new(big.Int).Mul(msg.GasPrice, new(big.Int).SetUint64(leftoverGas)))
}
debugFn()
tracer.CaptureTxEnd(leftoverGas)
}()
}
Expand Down Expand Up @@ -404,13 +407,6 @@
vmError = vmErr.Error()
}

// The dirty states in `StateDB` is either committed or discarded after return
if commit {
if err := stateDB.Commit(); err != nil {
return nil, errorsmod.Wrap(err, "failed to commit stateDB")
}
}

// calculate a minimum amount of gas to be charged to sender if GasLimit
// is considerably higher than GasUsed to stay more aligned with Tendermint gas mechanics
// for more info https://github.com/evmos/ethermint/issues/1085
Expand Down Expand Up @@ -438,6 +434,16 @@
// reset leftoverGas, to be used by the tracer
leftoverGas = msg.GasLimit - gasUsed

debugFn()
debugFn = func() {}

// The dirty states in `StateDB` is either committed or discarded after return
if commit {
if err := stateDB.Commit(); err != nil {
return nil, errorsmod.Wrap(err, "failed to commit stateDB")
}

Check warning on line 444 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L443-L444

Added lines #L443 - L444 were not covered by tests
}

return &types.MsgEthereumTxResponse{
GasUsed: gasUsed,
VmError: vmError,
Expand Down
Loading