Skip to content

Commit

Permalink
eth/tracers/logger: remove unnecessary comparisons in accessList.equal (
Browse files Browse the repository at this point in the history
ethereum#24663)

This change removes extraneous/unnecessary checks for equality
when comparing 2 accessList values A and B. Given that we validate that
their lengths of A and B are equal, if so and if every element in A is
in B, reflexively every element in B is already in A. If that weren't
the case and an element g existed in A but not in B, that would mean
that there is an extra element and hence a mathematical contradiction.

Fixes ethereum#24658
  • Loading branch information
Emmanuel T Odeke authored and gzliudan committed Oct 17, 2024
1 parent daf93a4 commit c795281
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions core/vm/access_list_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,28 @@ func (al accessList) equal(other accessList) bool {
if len(al) != len(other) {
return false
}
// Given that len(al) == len(other), we only need to check that
// all the items from al are in other.
for addr := range al {
if _, ok := other[addr]; !ok {
return false
}
}
for addr := range other {
if _, ok := al[addr]; !ok {
return false
}
}

// Accounts match, cross reference the storage slots too
for addr, slots := range al {
otherslots := other[addr]

if len(slots) != len(otherslots) {
return false
}
// Given that len(slots) == len(otherslots), we only need to check that
// all the items from slots are in otherslots.
for hash := range slots {
if _, ok := otherslots[hash]; !ok {
return false
}
}
for hash := range otherslots {
if _, ok := slots[hash]; !ok {
return false
}
}
}
return true
}
Expand Down

0 comments on commit c795281

Please sign in to comment.