diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index de25fd1a146d..092401ef86c8 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -170,6 +170,10 @@ func ImportChain(chain *core.BlockChain, fn string) error { } defer fh.Close() + // if _, err := fh.Seek(18224628422, 0); err != nil { + // panic(err) + // } + var reader io.Reader = fh if strings.HasSuffix(fn, ".gz") { if reader, err = gzip.NewReader(reader); err != nil { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 18c7c396e4b5..5f88e110800d 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2157,8 +2157,30 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh } vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)} + // Override the chain config with provided settings. + var overrides core.ChainOverrides + if ctx.IsSet(OverrideCancun.Name) { + v := ctx.Uint64(OverrideCancun.Name) + overrides.OverrideCancun = &v + } + if ctx.IsSet(OverridePrague.Name) { + v := ctx.Uint64(OverridePrague.Name) + overrides.OverridePrague = &v + } + if ctx.IsSet(OverrideProofInBlock.Name) { + v := ctx.Bool(OverrideProofInBlock.Name) + overrides.OverrideProofInBlock = &v + } + if ctx.IsSet(OverrideOverlayStride.Name) { + v := ctx.Uint64(OverrideOverlayStride.Name) + overrides.OverrideOverlayStride = &v + } + if ctx.IsSet(ClearVerkleCosts.Name) { + params.ClearVerkleWitnessCosts() + } + // Disable transaction indexing/unindexing by default. - chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil) + chain, err := core.NewBlockChain(chainDb, cache, gspec, &overrides, engine, vmcfg, nil, nil) if err != nil { Fatalf("Can't create BlockChain: %v", err) } diff --git a/core/block_validator.go b/core/block_validator.go index 337b61ac3396..d3058b156c48 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -98,13 +98,13 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error { return errors.New("data blobs present in block body") } } - if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) { - if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) { - return consensus.ErrUnknownAncestor - } - fmt.Println("failure here") - return consensus.ErrPrunedAncestor - } + // if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) { + // if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) { + // return consensus.ErrUnknownAncestor + // } + // fmt.Println("failure here") + // return consensus.ErrPrunedAncestor + // } return nil } @@ -121,16 +121,16 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD if rbloom != header.Bloom { return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom) } - // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]])) - receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil)) - if receiptSha != header.ReceiptHash { - return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha) - } - // Validate the state root against the received state root and throw - // an error if they don't match. - if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root { - return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error()) - } + // // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]])) + // receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil)) + // if receiptSha != header.ReceiptHash { + // return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha) + // } + // // Validate the state root against the received state root and throw + // // an error if they don't match. + // if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root { + // return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error()) + // } // Verify that the advertised root is correct before // it can be used as an identifier for the conversion // status. diff --git a/core/blockchain.go b/core/blockchain.go index 1ffb36ffb523..9a76587c3291 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -18,15 +18,11 @@ package core import ( - "bufio" "errors" "fmt" "io" - "math" "math/big" - "os" "runtime" - "strconv" "strings" "sync" "sync/atomic" @@ -326,7 +322,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis // for it to be able to recover if interrupted during the transition // but that's left out to a later PR since there's not really a need // right now. - bc.stateCache.InitTransitionStatus(true, true) + bc.stateCache.InitTransitionStatus(false, false) bc.stateCache.EndVerkleTransition() } @@ -1535,30 +1531,6 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { return bc.insertChain(chain, true) } -func findVerkleConversionBlock() (uint64, error) { - if _, err := os.Stat("conversion.txt"); os.IsNotExist(err) { - return math.MaxUint64, nil - } - - f, err := os.Open("conversion.txt") - if err != nil { - log.Error("Failed to open conversion.txt", "err", err) - return 0, err - } - defer f.Close() - - scanner := bufio.NewScanner(f) - scanner.Scan() - conversionBlock, err := strconv.ParseUint(scanner.Text(), 10, 64) - if err != nil { - log.Error("Failed to parse conversionBlock", "err", err) - return 0, err - } - log.Info("Found conversion block info", "conversionBlock", conversionBlock) - - return conversionBlock, nil -} - // insertChain is the internal implementation of InsertChain, which assumes that // 1) chains are contiguous, and 2) The chain mutex is held. // @@ -1573,11 +1545,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) return 0, nil } - conversionBlock, err := findVerkleConversionBlock() - if err != nil { - return 0, err - } - // Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss) SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain) @@ -1767,6 +1734,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) // is the fork block and that the conversion needs to be marked at started. if !bc.stateCache.InTransition() && !bc.stateCache.Transitioned() { bc.stateCache.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), bc.Config().PragueTime, parent.Root) + bc.stateCache.SetLastMerkleRoot(parent.Root) } } else { // If the verkle activation time hasn't started, declare it as "not started". @@ -1774,11 +1742,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) // in the correct mode. bc.stateCache.InitTransitionStatus(false, false) } - if parent.Number.Uint64() == conversionBlock { - bc.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), &parent.Time, parent.Root) - bc.stateCache.SetLastMerkleRoot(parent.Root) + stateRoot := parent.Root + if block.Header().Number.Uint64() == 4702178 { + stateRoot = common.HexToHash("0x00") } - statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps) + statedb, err := state.New(stateRoot, bc.stateCache, bc.snaps) if err != nil { return it.index, err } diff --git a/core/state_processor.go b/core/state_processor.go index d6a01673c6ab..3192692e3795 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -185,7 +185,7 @@ func InsertBlockHashHistoryAtEip2935Fork(statedb *state.StateDB, prevNumber uint statedb.Witness().TouchFullAccount(params.HistoryStorageAddress[:], true) ancestor := chain.GetHeader(prevHash, prevNumber) - for i := prevNumber; i > 0 && i >= prevNumber-params.Eip2935BlockHashHistorySize; i-- { + for i := prevNumber; i > 0 && i > prevNumber-params.Eip2935BlockHashHistorySize; i-- { ProcessParentBlockHash(statedb, i, ancestor.Hash()) ancestor = chain.GetHeader(ancestor.ParentHash, ancestor.Number.Uint64()-1) } diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 036d18a078fe..75fc80e3c18e 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -151,6 +151,7 @@ func init() { func ActivePrecompiles(rules params.Rules) []common.Address { switch { case rules.IsPrague: + // Note: this config should be correctly set depending on replay starting point. return PrecompiledAddressesBerlin case rules.IsCancun: return PrecompiledAddressesCancun diff --git a/core/vm/evm.go b/core/vm/evm.go index e036d2661768..489697eec394 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -41,10 +41,10 @@ type ( func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) { var precompiles map[common.Address]PrecompiledContract switch { - case evm.chainRules.IsPrague: - precompiles = PrecompiledContractsBerlin case evm.chainRules.IsCancun: precompiles = PrecompiledContractsCancun + case evm.chainRules.IsPrague: + precompiles = PrecompiledContractsBerlin case evm.chainRules.IsBerlin: precompiles = PrecompiledContractsBerlin case evm.chainRules.IsIstanbul: diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 427ac4e44fc5..e61b464c0622 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -56,11 +56,11 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { // If jump table was not initialised we set the default one. var table *JumpTable switch { - case evm.chainRules.IsPrague: - // TODO replace with prooper instruction set when fork is specified - table = &pragueInstructionSet case evm.chainRules.IsCancun: table = &cancunInstructionSet + case evm.chainRules.IsPrague: + // TODO replace with proper instruction set when fork is specified + table = &shanghaiInstructionSet case evm.chainRules.IsShanghai: table = &shanghaiInstructionSet case evm.chainRules.IsMerge: diff --git a/params/config.go b/params/config.go index 5b55c5197700..bf8ef84bf691 100644 --- a/params/config.go +++ b/params/config.go @@ -505,7 +505,7 @@ func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool { // IsPrague returns whether num is either equal to the Prague fork time or greater. func (c *ChainConfig) IsPrague(num *big.Int, time uint64) bool { - return c.IsLondon(num) && isTimestampForked(c.PragueTime, time) + return c.IsShanghai(num, time) && isTimestampForked(c.PragueTime, time) } // CheckCompatible checks whether scheduled fork transitions have been imported @@ -830,8 +830,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsPetersburg: c.IsPetersburg(num), IsIstanbul: c.IsIstanbul(num), IsBerlin: c.IsBerlin(num), - IsEIP2929: c.IsBerlin(num) && !c.IsPrague(num, timestamp), - IsEIP4762: c.IsPrague(num, timestamp), + IsEIP2929: c.IsBerlin(num), // && !c.IsPrague(num, timestamp), + IsEIP4762: false, //c.IsPrague(num, timestamp), IsLondon: c.IsLondon(num), IsMerge: isMerge, IsShanghai: c.IsShanghai(num, timestamp), diff --git a/trie/verkle.go b/trie/verkle.go index ee953c232318..c3529a98ec00 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -213,6 +213,24 @@ func (trie *VerkleTrie) UpdateStorage(address common.Address, key, value []byte) } func (t *VerkleTrie) DeleteAccount(addr common.Address) error { + var ( + err error + values = make([][]byte, verkle.NodeWidth) + stem = t.pointCache.GetTreeKeyVersionCached(addr[:]) + ) + + for i := 0; i < verkle.NodeWidth; i++ { + values[i] = zero[:] + } + switch root := t.root.(type) { + case *verkle.InternalNode: + err = root.InsertValuesAtStem(stem, values, t.FlatdbNodeResolver) + default: + return errInvalidRootType + } + if err != nil { + return fmt.Errorf("DeleteAccount (%x) error: %v", addr, err) + } return nil }