Skip to content

Commit b5a55d6

Browse files
committed
handle static
1 parent c6c61d3 commit b5a55d6

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

rpc/types/types.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,16 @@ func ParseOverrides(overrides *json.RawMessage, isPrecompile bool) (*StateOverri
224224
// extractFromOverrideAccount extracts cosmos overrides from state/stateDiff fields
225225
func extractFromOverrideAccount(overrideAccount map[string]interface{}) []evmtypes.StoreStateDiff {
226226
for stateType, stateValue := range overrideAccount {
227-
if (stateType == "state" || stateType == "stateDiff") && stateValue != nil {
228-
if encodedStr, ok := stateValue.(string); ok {
229-
if cosmosOverrides := decodeCosmosOverrides(encodedStr); cosmosOverrides != nil {
230-
return cosmosOverrides
227+
if stateValue != nil {
228+
if stateType == "" {
229+
return make([]evmtypes.StoreStateDiff, 0)
230+
}
231+
232+
if stateType == "state" || stateType == "stateDiff" {
233+
if encodedStr, ok := stateValue.(string); ok {
234+
if cosmosOverrides := decodeCosmosOverrides(encodedStr); cosmosOverrides != nil {
235+
return cosmosOverrides
236+
}
231237
}
232238
}
233239
}

x/vm/keeper/precompiles.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,36 @@ func (k *Keeper) GetPrecompilesCallHook(ctx sdktypes.Context) types.CallHook {
7171
return nil
7272
}
7373
}
74+
75+
// GetPrecompileRecipientCallHook returns a closure that can be used to instantiate the EVM with a specific
76+
// recipient from precompiles.
77+
func (k *Keeper) GetPrecompileRecipientCallHook(ctx sdktypes.Context) types.CallHook {
78+
return func(evm *vm.EVM, _ common.Address, recipient common.Address) error {
79+
// Check if the EVM already has precompiles set (including moved precompiles from overrides)
80+
activePrecompiles := evm.ActivePrecompiles()
81+
if len(activePrecompiles) > 0 {
82+
for _, addr := range activePrecompiles {
83+
if addr == recipient {
84+
evm.StateDB.AddAddressToAccessList(recipient)
85+
return nil
86+
}
87+
}
88+
return nil
89+
}
90+
91+
// Check if the recipient is a precompile contract and if so, load the precompile instance
92+
precompiles, found, err := k.GetPrecompileInstance(ctx, recipient)
93+
if err != nil {
94+
return err
95+
}
96+
97+
// If the precompile instance is created, we have to update the EVM with
98+
// only the recipient precompile and add it's address to the access list.
99+
if found {
100+
evm.WithPrecompiles(precompiles.Map)
101+
evm.StateDB.AddAddressToAccessList(recipient)
102+
}
103+
104+
return nil
105+
}
106+
}

x/vm/keeper/state_transition.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (k *Keeper) NewEVMWithOverridePrecompiles(
3939
cfg *statedb.EVMConfig,
4040
tracer *tracing.Hooks,
4141
stateDB vm.StateDB,
42-
overridePrecompiles bool,
42+
noOverridePrecompiles bool,
4343
) *vm.EVM {
4444
ctx = k.SetConsensusParamsInCtx(ctx)
4545
blockCtx := vm.BlockContext{
@@ -73,9 +73,15 @@ func (k *Keeper) NewEVMWithOverridePrecompiles(
7373
evmHooks.AddCallHooks(
7474
accessControl.GetCallHook(signer),
7575
)
76-
evmHooks.AddCallHooks(
77-
k.GetPrecompilesCallHook(ctx),
78-
)
76+
if noOverridePrecompiles {
77+
evmHooks.AddCallHooks(
78+
k.GetPrecompilesCallHook(ctx),
79+
)
80+
} else {
81+
evmHooks.AddCallHooks(
82+
k.GetPrecompileRecipientCallHook(ctx),
83+
)
84+
}
7985
return vm.NewEVMWithHooks(evmHooks, blockCtx, txCtx, stateDB, ethCfg, vmConfig)
8086
}
8187

0 commit comments

Comments
 (0)