Skip to content

Commit 6e652eb

Browse files
author
Darioush Jalali
committed
add prestate panic prevention (NativeAssetCall)
1 parent 778e3ab commit 6e652eb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

eth/tracers/native/prestate.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ func (t *prestateTracer) lookupAccount(addr common.Address) {
290290
// it to the prestate of the given contract. It assumes `lookupAccount`
291291
// has been performed on the contract before.
292292
func (t *prestateTracer) lookupStorage(addr common.Address, key common.Hash) {
293+
// TODO: Refactor coreth test outside of eth/tracers/internal
294+
// See https://github.com/ava-labs/coreth/pull/286 for context.
295+
// lookupStorage assumes that lookupAccount has already been called.
296+
// This assumption is violated for some historical blocks by the NativeAssetCall
297+
// precompile. To fix this, we perform an extra call to lookupAccount here to ensure
298+
// that the pre-state account is populated before attempting to read from the Storage
299+
// map. When the invariant is maintained properly (since de-activation of the precompile),
300+
// lookupAccount is a no-op. When the invariant is broken by the precompile, this avoids
301+
// the panic and correctly captures the account prestate before the next opcode is executed.
302+
t.lookupAccount(addr)
293303
if _, ok := t.pre[addr].Storage[key]; ok {
294304
return
295305
}

0 commit comments

Comments
 (0)