mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-07 23:48:36 +00:00
Merge fa21201ee3 into 12eabbd76d
This commit is contained in:
commit
5ef18a2250
2 changed files with 50 additions and 3 deletions
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
gomath "math"
|
gomath "math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -1314,12 +1315,15 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
|
||||||
if db == nil || err != nil {
|
if db == nil || err != nil {
|
||||||
return nil, 0, nil, err
|
return nil, 0, nil, err
|
||||||
}
|
}
|
||||||
|
isPostMerge := header.Difficulty.Sign() == 0
|
||||||
|
rules := b.ChainConfig().Rules(header.Number, isPostMerge, header.Time)
|
||||||
|
precompileSet := maps.Clone(vm.ActivePrecompiledContracts(rules))
|
||||||
|
|
||||||
// Apply state overrides immediately after StateAndHeaderByNumberOrHash.
|
// Apply state overrides immediately after StateAndHeaderByNumberOrHash.
|
||||||
// If not applied here, there could be cases where user-specified overrides (e.g., nonce)
|
// If not applied here, there could be cases where user-specified overrides (e.g., nonce)
|
||||||
// may conflict with default values from the database, leading to inconsistencies.
|
// may conflict with default values from the database, leading to inconsistencies.
|
||||||
if stateOverrides != nil {
|
if stateOverrides != nil {
|
||||||
if err := stateOverrides.Apply(db, nil); err != nil {
|
if err := stateOverrides.Apply(db, precompileSet); err != nil {
|
||||||
return nil, 0, nil, err
|
return nil, 0, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1343,9 +1347,11 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
|
||||||
} else {
|
} else {
|
||||||
to = crypto.CreateAddress(args.from(), uint64(*args.Nonce))
|
to = crypto.CreateAddress(args.from(), uint64(*args.Nonce))
|
||||||
}
|
}
|
||||||
isPostMerge := header.Difficulty.Sign() == 0
|
|
||||||
// Retrieve the precompiles since they don't need to be added to the access list
|
// Retrieve the precompiles since they don't need to be added to the access list
|
||||||
precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number, isPostMerge, header.Time))
|
precompiles := make([]common.Address, 0, len(precompileSet))
|
||||||
|
for addr := range precompileSet {
|
||||||
|
precompiles = append(precompiles, addr)
|
||||||
|
}
|
||||||
|
|
||||||
// addressesToExclude contains sender, receiver, precompiles and valid authorizations
|
// addressesToExclude contains sender, receiver, precompiles and valid authorizations
|
||||||
addressesToExclude := map[common.Address]struct{}{args.from(): {}, to: {}}
|
addressesToExclude := map[common.Address]struct{}{args.from(): {}, to: {}}
|
||||||
|
|
@ -1393,6 +1399,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
|
||||||
tracer := logger.NewAccessListTracer(accessList, addressesToExclude)
|
tracer := logger.NewAccessListTracer(accessList, addressesToExclude)
|
||||||
config := vm.Config{Tracer: tracer.Hooks(), NoBaseFee: true}
|
config := vm.Config{Tracer: tracer.Hooks(), NoBaseFee: true}
|
||||||
evm := b.GetEVM(ctx, statedb, header, &config, nil)
|
evm := b.GetEVM(ctx, statedb, header, &config, nil)
|
||||||
|
evm.SetPrecompiles(precompileSet)
|
||||||
|
|
||||||
// Lower the basefee to 0 to avoid breaking EVM
|
// Lower the basefee to 0 to avoid breaking EVM
|
||||||
// invariants (basefee < feecap).
|
// invariants (basefee < feecap).
|
||||||
|
|
|
||||||
|
|
@ -3939,6 +3939,46 @@ func TestCreateAccessListWithStateOverrides(t *testing.T) {
|
||||||
require.Equal(t, expected, result.Accesslist)
|
require.Equal(t, expected, result.Accesslist)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateAccessListWithMovePrecompile(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
// Initialize test accounts
|
||||||
|
var (
|
||||||
|
accounts = newAccounts(2)
|
||||||
|
genesis = &core.Genesis{
|
||||||
|
Config: params.MergedTestChainConfig,
|
||||||
|
Alloc: types.GenesisAlloc{
|
||||||
|
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
backend := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
|
||||||
|
b.SetPoS()
|
||||||
|
})
|
||||||
|
api := NewBlockChainAPI(backend)
|
||||||
|
|
||||||
|
var (
|
||||||
|
sha256Addr = common.BytesToAddress([]byte{0x2})
|
||||||
|
newSha256Addr = common.BytesToAddress([]byte{0x10, 0})
|
||||||
|
sha256Input = hexutil.Bytes([]byte("hello"))
|
||||||
|
gas = hexutil.Uint64(100000)
|
||||||
|
args = TransactionArgs{
|
||||||
|
From: &accounts[0].addr,
|
||||||
|
To: &newSha256Addr,
|
||||||
|
Data: &sha256Input,
|
||||||
|
Gas: &gas,
|
||||||
|
}
|
||||||
|
overrides = &override.StateOverride{
|
||||||
|
sha256Addr: override.OverrideAccount{
|
||||||
|
MovePrecompileTo: &newSha256Addr,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
result, err := api.CreateAccessList(context.Background(), args, nil, overrides)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, result)
|
||||||
|
require.NotNil(t, result.Accesslist)
|
||||||
|
}
|
||||||
|
|
||||||
func TestEstimateGasWithMovePrecompile(t *testing.T) {
|
func TestEstimateGasWithMovePrecompile(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
// Initialize test accounts
|
// Initialize test accounts
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue