Skip to content

Commit

Permalink
Remove account read and write if the tx is created and then reverted
Browse files Browse the repository at this point in the history
Checking if the live set contains the address is sufficient, because if the account isn't created within this tx, it would still show up in live set even if the tx got reverted.
  • Loading branch information
cffls committed Mar 26, 2024
1 parent 49c252a commit b62bf09
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions eth/tracers/native/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func (t *zeroTracer) CaptureTxEnd(restGas uint64) {

for addr := range t.tx.Traces {
trace := t.tx.Traces[addr]
hasLiveAccount := t.env.IntraBlockState().HasLiveAccount(addr)
newBalance := t.env.IntraBlockState().GetBalance(addr)
newNonce := uint256.NewInt(t.env.IntraBlockState().GetNonce(addr))
codeHash := t.env.IntraBlockState().GetCodeHash(addr)
Expand All @@ -223,7 +224,7 @@ func (t *zeroTracer) CaptureTxEnd(restGas uint64) {
trace.Nonce = nil
}

if len(trace.StorageReadMap) > 0 {
if len(trace.StorageReadMap) > 0 && hasLiveAccount {
trace.StorageRead = make([]libcommon.Hash, 0, len(trace.StorageReadMap))
for k := range trace.StorageReadMap {
trace.StorageRead = append(trace.StorageRead, k)
Expand All @@ -232,7 +233,7 @@ func (t *zeroTracer) CaptureTxEnd(restGas uint64) {
trace.StorageRead = nil
}

if len(trace.StorageWritten) == 0 {
if len(trace.StorageWritten) == 0 || !hasLiveAccount {
trace.StorageWritten = nil
} else {
// A slot write could be reverted if the transaction is reverted. We will need to read the value from the statedb again to get the correct value.
Expand Down

0 comments on commit b62bf09

Please sign in to comment.