diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index de25fd1a146..9e8f5ffaa5f 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/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index e40c180aa42..d3e9be2c60a 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -28,7 +28,6 @@ import ( "github.com/ethereum/go-ethereum/core/overlay" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/trie" @@ -346,6 +345,14 @@ func (beacon *Beacon) Prepare(chain consensus.ChainHeaderReader, header *types.H // Finalize implements consensus.Engine and processes withdrawals on top. func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) { + if chain.Config().IsPrague(header.Number, header.Time) { + // uncomment when debugging + // fmt.Println("at block", header.Number, "performing transition?", state.Database().InTransition()) + parent := chain.GetHeaderByHash(header.ParentHash) + if err := overlay.OverlayVerkleTransition(state, parent.Root, chain.Config().OverlayStride); err != nil { + panic(err) + } + } if !beacon.IsPoSHeader(header) { beacon.ethone.Finalize(chain, header, state, txs, uncles, nil) return @@ -361,14 +368,6 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. state.Witness().TouchFullAccount(w.Address[:], true) } - if chain.Config().IsPrague(header.Number, header.Time) { - // uncomment when debugging - // fmt.Println("at block", header.Number, "performing transition?", state.Database().InTransition()) - parent := chain.GetHeaderByHash(header.ParentHash) - if err := overlay.OverlayVerkleTransition(state, parent.Root, chain.Config().OverlayStride); err != nil { - log.Error("error performing the transition", "err", err) - } - } } // FinalizeAndAssemble implements consensus.Engine, setting the final state and diff --git a/core/blockchain.go b/core/blockchain.go index f92d174ccf1..c0a34c6ec62 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -322,8 +322,8 @@ 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.EndVerkleTransition() + bc.stateCache.InitTransitionStatus(false, false) + // bc.stateCache.EndVerkleTransition() } if !bc.HasState(head.Root) { diff --git a/core/state/database.go b/core/state/database.go index 826c03cd9f0..7ffb7a4073d 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -415,7 +415,7 @@ func (db *cachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Addre } } if db.InTransition() { - fmt.Printf("OpenStorageTrie during transition, state root=%x root=%x\n", stateRoot, root) + // fmt.Printf("OpenStorageTrie during transition, state root=%x root=%x\n", stateRoot, root) mpt, err := db.openStorageMPTrie(db.LastMerkleRoot, address, root, nil) if err != nil { return nil, err diff --git a/core/state_processor.go b/core/state_processor.go index d6a01673c6a..3192692e379 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 75fc80e3c18..0065757dd71 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -152,7 +152,7 @@ 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 + return PrecompiledAddressesByzantium case rules.IsCancun: return PrecompiledAddressesCancun case rules.IsBerlin: diff --git a/core/vm/evm.go b/core/vm/evm.go index 489697eec39..cacf41150c7 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -43,12 +43,12 @@ func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) { switch { case evm.chainRules.IsCancun: precompiles = PrecompiledContractsCancun - case evm.chainRules.IsPrague: - precompiles = PrecompiledContractsBerlin case evm.chainRules.IsBerlin: precompiles = PrecompiledContractsBerlin case evm.chainRules.IsIstanbul: precompiles = PrecompiledContractsIstanbul + case evm.chainRules.IsPrague: + precompiles = PrecompiledContractsByzantium case evm.chainRules.IsByzantium: precompiles = PrecompiledContractsByzantium default: @@ -511,7 +511,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, // be stored due to not enough gas set an error and let it be handled // by the error checking condition below. if err == nil { - if !evm.chainRules.IsEIP4762 { + if !evm.chainRules.IsEIP4762 || replayMode { createDataGas := uint64(len(ret)) * params.CreateDataGas if !contract.UseGas(createDataGas) { err = ErrCodeStoreOutOfGas diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index 5f8183801f1..4f5b19e93c5 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -377,6 +377,8 @@ func gasExpEIP158(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memor return gas, nil } +var replayMode = true + func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { var ( gas uint64 @@ -391,7 +393,7 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize } else if !evm.StateDB.Exist(address) { gas += params.CallNewAccountGas } - if transfersValue && !evm.chainRules.IsEIP4762 { + if transfersValue && (!evm.chainRules.IsEIP4762 || replayMode) { gas += params.CallValueTransferGas } memoryGas, err := memoryGasCost(mem, memorySize) @@ -431,7 +433,7 @@ func gasCallCode(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory gas uint64 overflow bool ) - if stack.Back(2).Sign() != 0 && !evm.chainRules.IsEIP4762 { + if stack.Back(2).Sign() != 0 && (!evm.chainRules.IsEIP4762 || replayMode) { gas += params.CallValueTransferGas } if gas, overflow = math.SafeAdd(gas, memoryGas); overflow { diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index e61b464c062..959650e63ea 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -58,9 +58,6 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { switch { 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: @@ -73,6 +70,9 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { table = &istanbulInstructionSet case evm.chainRules.IsConstantinople: table = &constantinopleInstructionSet + case evm.chainRules.IsPrague: + // TODO replace with proper instruction set when fork is specified + table = &byzantiumInstructionSet case evm.chainRules.IsByzantium: table = &byzantiumInstructionSet case evm.chainRules.IsEIP158: diff --git a/params/config.go b/params/config.go index 6c9e95197fd..d680c5bf0f5 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.IsShanghai(num, time) && isTimestampForked(c.PragueTime, time) + return c.IsByzantium(num) && isTimestampForked(c.PragueTime, time) } // CheckCompatible checks whether scheduled fork transitions have been imported