From a128567065e1cab19b4e0f41b14865feb365115b Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:39:50 +0200 Subject: [PATCH] fix: force conversion of withdrawal code --- cmd/evm/internal/t8ntool/execution.go | 11 +++++++++++ consensus/beacon/consensus.go | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index db9b7775114d..0d7f040df0e9 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -344,6 +344,17 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, // Amount is in gwei, turn into wei amount := new(big.Int).Mul(new(big.Int).SetUint64(w.Amount), big.NewInt(params.GWei)) statedb.AddBalance(w.Address, amount) + + // fix: during the transition, if the withdrawals account + // hasn't been translated yet, then the code will not make + // it to the verkle tree when it's being written. + if state.Database().InTransition() { + codeHash := state.GetCodeHash(w.Address) + if codeHash != types.EmptyCodeHash { + code := state.GetCode(w.Address) + state.GetTrie().UpdateContractCode(w.Address, codeHash, code) + } + } } if chainConfig.IsPrague(big.NewInt(int64(pre.Env.Number)), pre.Env.Timestamp) { if err := overlay.OverlayVerkleTransition(statedb, common.Hash{}, chainConfig.OverlayStride); err != nil { diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index f1d1b1bafa04..0c9e0272912a 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -357,6 +357,17 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. amount = amount.Mul(amount, big.NewInt(params.GWei)) state.AddBalance(w.Address, amount) + // fix: during the transition, if the withdrawals account + // hasn't been translated yet, then the code will not make + // it to the verkle tree when it's being written. + if state.Database().InTransition() { + codeHash := state.GetCodeHash(w.Address) + if codeHash != types.EmptyCodeHash { + code := state.GetCode(w.Address) + state.GetTrie().UpdateContractCode(w.Address, codeHash, code) + } + } + // The returned gas is not charged state.Witness().TouchFullAccount(w.Address[:], true) }