Skip to content

Commit

Permalink
add prestate panic prevention (NativeAssetCall)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Sep 25, 2024
1 parent d1f471d commit fc0ab6d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ func (t *prestateTracer) lookupAccount(addr common.Address) {
// it to the prestate of the given contract. It assumes `lookupAccount`
// has been performed on the contract before.
func (t *prestateTracer) lookupStorage(addr common.Address, key common.Hash) {
// TODO: Refactor coreth test outside of eth/tracers/internal
// See https://github.com/ava-labs/coreth/pull/286 for context.
// lookupStorage assumes that lookupAccount has already been called.
// This assumption is violated for some historical blocks by the NativeAssetCall
// precompile. To fix this, we perform an extra call to lookupAccount here to ensure
// that the pre-state account is populated before attempting to read from the Storage
// map. When the invariant is maintained properly (since de-activation of the precompile),
// lookupAccount is a no-op. When the invariant is broken by the precompile, this avoids
// the panic and correctly captures the account prestate before the next opcode is executed.
t.lookupAccount(addr)
if _, ok := t.pre[addr].Storage[key]; ok {
return
}
Expand Down

0 comments on commit fc0ab6d

Please sign in to comment.