mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
core/vm: use maps.Clone
This commit is contained in:
parent
6ec5083421
commit
791719a0fe
4 changed files with 7 additions and 13 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math/big"
|
||||
|
||||
"github.com/consensys/gnark-crypto/ecc"
|
||||
|
|
@ -172,16 +173,6 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
// Copy returns a copy of the precompiled contracts. The precompiled
|
||||
// contracts are shallow-copied. It should be safe as they are stateless/immutable.
|
||||
func (p PrecompiledContracts) Copy() PrecompiledContracts {
|
||||
c := make(PrecompiledContracts)
|
||||
for k, v := range p {
|
||||
c[k] = v
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func activePrecompiledContracts(rules params.Rules) PrecompiledContracts {
|
||||
switch {
|
||||
case rules.IsVerkle:
|
||||
|
|
@ -203,7 +194,7 @@ func activePrecompiledContracts(rules params.Rules) PrecompiledContracts {
|
|||
|
||||
// ActivePrecompiledContracts returns a copy of precompiled contracts enabled with the current configuration.
|
||||
func ActivePrecompiledContracts(rules params.Rules) PrecompiledContracts {
|
||||
return activePrecompiledContracts(rules).Copy()
|
||||
return maps.Clone(activePrecompiledContracts(rules))
|
||||
}
|
||||
|
||||
// ActivePrecompiles returns the precompile addresses enabled with the current configuration.
|
||||
|
|
|
|||
|
|
@ -958,6 +958,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
|
|||
if config != nil {
|
||||
config.BlockOverrides.Apply(&vmctx)
|
||||
rules := api.backend.ChainConfig().Rules(vmctx.BlockNumber, vmctx.Random != nil, vmctx.Time)
|
||||
|
||||
precompiles := vm.ActivePrecompiledContracts(rules)
|
||||
if err := config.StateOverrides.Apply(statedb, precompiles); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -1164,7 +1165,7 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
|
|||
blockOverrides.Apply(&blockCtx)
|
||||
}
|
||||
rules := b.ChainConfig().Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time)
|
||||
precompiles := vm.ActivePrecompiledContracts(rules).Copy()
|
||||
precompiles := maps.Clone(vm.ActivePrecompiledContracts(rules))
|
||||
if err := overrides.Apply(state, precompiles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
|
|
@ -282,7 +283,7 @@ func (sim *simulator) activePrecompiles(ctx context.Context, base *types.Header)
|
|||
blockContext = core.NewEVMBlockContext(base, NewChainContext(ctx, sim.b), nil)
|
||||
rules = sim.chainConfig.Rules(blockContext.BlockNumber, blockContext.Random != nil, blockContext.Time)
|
||||
)
|
||||
return vm.ActivePrecompiledContracts(rules).Copy()
|
||||
return maps.Clone(vm.ActivePrecompiledContracts(rules))
|
||||
}
|
||||
|
||||
// sanitizeChain checks the chain integrity. Specifically it checks that
|
||||
|
|
|
|||
Loading…
Reference in a new issue