eth/tracers: prestate lookup EIP7702 delegation account (#32080)
Some checks are pending
/ Linux Build (arm) (push) Waiting to run
/ Docker Image (push) Waiting to run
/ Linux Build (push) Waiting to run

Implement https://github.com/ethereum/go-ethereum/issues/32078 
Parse and lookup the delegation account if EIP7702 is enabled.

---------

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
Delweng 2025-06-24 13:52:18 +08:00 committed by GitHub
parent b62c0c67fa
commit 0b21c4a633
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 169 additions and 14 deletions

File diff suppressed because one or more lines are too long

View file

@ -81,6 +81,10 @@
"0x0000000000000000000000000000000000000000": {
"balance": "0x272e0528"
},
"0x000000000000000000000000000000000000bbbb": {
"balance": "0x0",
"code": "0x6042604255"
},
"0x703c4b2bd70c169f5717101caee543299fc946c7": {
"balance": "0xde0b6b3a7640000",
"storage": {

View file

@ -61,15 +61,16 @@ type accountMarshaling struct {
}
type prestateTracer struct {
env *tracing.VMContext
pre stateMap
post stateMap
to common.Address
config prestateTracerConfig
interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
created map[common.Address]bool
deleted map[common.Address]bool
env *tracing.VMContext
pre stateMap
post stateMap
to common.Address
config prestateTracerConfig
chainConfig *params.ChainConfig
interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
created map[common.Address]bool
deleted map[common.Address]bool
}
type prestateTracerConfig struct {
@ -90,11 +91,12 @@ func newPrestateTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *p
return nil, errors.New("cannot use diffMode with includeEmpty")
}
t := &prestateTracer{
pre: stateMap{},
post: stateMap{},
config: config,
created: make(map[common.Address]bool),
deleted: make(map[common.Address]bool),
pre: stateMap{},
post: stateMap{},
config: config,
chainConfig: chainConfig,
created: make(map[common.Address]bool),
deleted: make(map[common.Address]bool),
}
return &tracers.Tracer{
Hooks: &tracing.Hooks{
@ -133,6 +135,13 @@ func (t *prestateTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scop
case stackLen >= 5 && (op == vm.DELEGATECALL || op == vm.CALL || op == vm.STATICCALL || op == vm.CALLCODE):
addr := common.Address(stackData[stackLen-2].Bytes20())
t.lookupAccount(addr)
// Lookup the delegation target
if t.chainConfig.IsPrague(t.env.BlockNumber, t.env.Time) {
code := t.env.StateDB.GetCode(addr)
if target, ok := types.ParseDelegation(code); ok {
t.lookupAccount(target)
}
}
case op == vm.CREATE:
nonce := t.env.StateDB.GetNonce(caller)
addr := crypto.CreateAddress(caller, nonce)
@ -161,6 +170,13 @@ func (t *prestateTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction
t.created[t.to] = true
} else {
t.to = *tx.To()
// Lookup the delegation target
if t.chainConfig.IsPrague(t.env.BlockNumber, t.env.Time) {
code := t.env.StateDB.GetCode(t.to)
if target, ok := types.ParseDelegation(code); ok {
t.lookupAccount(target)
}
}
}
t.lookupAccount(from)