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"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/consensys/gnark-crypto/ecc"
|
"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 {
|
func activePrecompiledContracts(rules params.Rules) PrecompiledContracts {
|
||||||
switch {
|
switch {
|
||||||
case rules.IsVerkle:
|
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.
|
// ActivePrecompiledContracts returns a copy of precompiled contracts enabled with the current configuration.
|
||||||
func ActivePrecompiledContracts(rules params.Rules) PrecompiledContracts {
|
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.
|
// 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 {
|
if config != nil {
|
||||||
config.BlockOverrides.Apply(&vmctx)
|
config.BlockOverrides.Apply(&vmctx)
|
||||||
rules := api.backend.ChainConfig().Rules(vmctx.BlockNumber, vmctx.Random != nil, vmctx.Time)
|
rules := api.backend.ChainConfig().Rules(vmctx.BlockNumber, vmctx.Random != nil, vmctx.Time)
|
||||||
|
|
||||||
precompiles := vm.ActivePrecompiledContracts(rules)
|
precompiles := vm.ActivePrecompiledContracts(rules)
|
||||||
if err := config.StateOverrides.Apply(statedb, precompiles); err != nil {
|
if err := config.StateOverrides.Apply(statedb, precompiles); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -1164,7 +1165,7 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
|
||||||
blockOverrides.Apply(&blockCtx)
|
blockOverrides.Apply(&blockCtx)
|
||||||
}
|
}
|
||||||
rules := b.ChainConfig().Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time)
|
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 {
|
if err := overrides.Apply(state, precompiles); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -282,7 +283,7 @@ func (sim *simulator) activePrecompiles(ctx context.Context, base *types.Header)
|
||||||
blockContext = core.NewEVMBlockContext(base, NewChainContext(ctx, sim.b), nil)
|
blockContext = core.NewEVMBlockContext(base, NewChainContext(ctx, sim.b), nil)
|
||||||
rules = sim.chainConfig.Rules(blockContext.BlockNumber, blockContext.Random != nil, blockContext.Time)
|
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
|
// sanitizeChain checks the chain integrity. Specifically it checks that
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue