Skip to content

Commit e3affc0

Browse files
authored
Merge branch 'ethereum:master' into master
2 parents 98708ac + 5e6f737 commit e3affc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1188
-1629
lines changed

accounts/keystore/keystore.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ func (ks *KeyStore) Export(a accounts.Account, passphrase, newPassphrase string)
418418
if err != nil {
419419
return nil, err
420420
}
421+
defer zeroKey(key.PrivateKey)
421422
var N, P int
422423
if store, ok := ks.storage.(*keyStorePassphrase); ok {
423424
N, P = store.scryptN, store.scryptP
@@ -477,6 +478,7 @@ func (ks *KeyStore) Update(a accounts.Account, passphrase, newPassphrase string)
477478
if err != nil {
478479
return err
479480
}
481+
defer zeroKey(key.PrivateKey)
480482
return ks.storage.StoreKey(a.URL.Path, key, newPassphrase)
481483
}
482484

cmd/evm/internal/t8ntool/execution.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package t8ntool
1818

1919
import (
2020
"fmt"
21+
stdmath "math"
2122
"math/big"
2223

2324
"github.com/ethereum/go-ethereum/common"
@@ -43,8 +44,9 @@ import (
4344
)
4445

4546
type Prestate struct {
46-
Env stEnv `json:"env"`
47-
Pre types.GenesisAlloc `json:"pre"`
47+
Env stEnv `json:"env"`
48+
Pre types.GenesisAlloc `json:"pre"`
49+
TreeLeaves map[common.Hash]hexutil.Bytes `json:"vkt,omitempty"`
4850
}
4951

5052
//go:generate go run github.com/fjl/gencodec -type ExecutionResult -field-override executionResultMarshaling -out gen_execresult.go
@@ -142,7 +144,8 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
142144
return h
143145
}
144146
var (
145-
statedb = MakePreState(rawdb.NewMemoryDatabase(), pre.Pre)
147+
isEIP4762 = chainConfig.IsVerkle(big.NewInt(int64(pre.Env.Number)), pre.Env.Timestamp)
148+
statedb = MakePreState(rawdb.NewMemoryDatabase(), pre.Pre, isEIP4762)
146149
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp)
147150
gaspool = new(core.GasPool)
148151
blockHash = common.Hash{0x13, 0x37}
@@ -301,6 +304,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
301304
// Amount is in gwei, turn into wei
302305
amount := new(big.Int).Mul(new(big.Int).SetUint64(w.Amount), big.NewInt(params.GWei))
303306
statedb.AddBalance(w.Address, uint256.MustFromBig(amount), tracing.BalanceIncreaseWithdrawal)
307+
308+
if isEIP4762 {
309+
statedb.AccessEvents().AddAccount(w.Address, true, stdmath.MaxUint64)
310+
}
304311
}
305312

306313
// Gather the execution-layer triggered requests.
@@ -361,8 +368,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
361368
execRs.Requests = requests
362369
}
363370

364-
// Re-create statedb instance with new root upon the updated database
365-
// for accessing latest states.
371+
// Re-create statedb instance with new root for MPT mode
366372
statedb, err = state.New(root, statedb.Database())
367373
if err != nil {
368374
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not reopen state: %v", err))
@@ -371,12 +377,17 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
371377
return statedb, execRs, body, nil
372378
}
373379

374-
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB {
375-
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true})
380+
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, isBintrie bool) *state.StateDB {
381+
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true, IsVerkle: isBintrie})
376382
sdb := state.NewDatabase(tdb, nil)
377-
statedb, err := state.New(types.EmptyRootHash, sdb)
383+
384+
root := types.EmptyRootHash
385+
if isBintrie {
386+
root = types.EmptyBinaryHash
387+
}
388+
statedb, err := state.New(root, sdb)
378389
if err != nil {
379-
panic(fmt.Errorf("failed to create initial state: %v", err))
390+
panic(fmt.Errorf("failed to create initial statedb: %v", err))
380391
}
381392
for addr, a := range accounts {
382393
statedb.SetCode(addr, a.Code, tracing.CodeChangeUnspecified)
@@ -387,18 +398,23 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB
387398
}
388399
}
389400
// Commit and re-open to start with a clean state.
390-
root, err := statedb.Commit(0, false, false)
401+
root, err = statedb.Commit(0, false, false)
391402
if err != nil {
392403
panic(fmt.Errorf("failed to commit initial state: %v", err))
393404
}
405+
// If bintrie mode started, check if conversion happened
406+
if isBintrie {
407+
return statedb
408+
}
409+
// For MPT mode, reopen the state with the committed root
394410
statedb, err = state.New(root, sdb)
395411
if err != nil {
396412
panic(fmt.Errorf("failed to reopen state after commit: %v", err))
397413
}
398414
return statedb
399415
}
400416

401-
func rlpHash(x interface{}) (h common.Hash) {
417+
func rlpHash(x any) (h common.Hash) {
402418
hw := sha3.NewLegacyKeccak256()
403419
rlp.Encode(hw, x)
404420
hw.Sum(h[:0])

cmd/evm/internal/t8ntool/flags.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ var (
8888
"\t<file> - into the file <file> ",
8989
Value: "block.json",
9090
}
91+
OutputBTFlag = &cli.StringFlag{
92+
Name: "output.vkt",
93+
Usage: "Determines where to put the `BT` of the post-state.\n" +
94+
"\t`stdout` - into the stdout output\n" +
95+
"\t`stderr` - into the stderr output\n" +
96+
"\t<file> - into the file <file> ",
97+
Value: "vkt.json",
98+
}
9199
InputAllocFlag = &cli.StringFlag{
92100
Name: "input.alloc",
93101
Usage: "`stdin` or file name of where to find the prestate alloc to use.",
@@ -123,6 +131,11 @@ var (
123131
Usage: "`stdin` or file name of where to find the transactions list in RLP form.",
124132
Value: "txs.rlp",
125133
}
134+
// TODO(@CPerezz): rename `Name` of the file in a follow-up PR (relays on EEST -> https://github.com/ethereum/execution-spec-tests/tree/verkle/main)
135+
InputBTFlag = &cli.StringFlag{
136+
Name: "input.vkt",
137+
Usage: "`stdin` or file name of where to find the prestate BT.",
138+
}
126139
SealCliqueFlag = &cli.StringFlag{
127140
Name: "seal.clique",
128141
Usage: "Seal block with Clique. `stdin` or file name of where to find the Clique sealing data.",

0 commit comments

Comments
 (0)