From d3c847c49b8d68e83d8b30f3f1ad1553eca440f1 Mon Sep 17 00:00:00 2001 From: Qi Zhou Date: Mon, 28 Oct 2024 09:11:55 +0000 Subject: [PATCH] fix *uint256 reuse issue --- core/state/dump.go | 3 +++ core/state_processor.go | 1 + core/state_transition.go | 14 +++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/state/dump.go b/core/state/dump.go index c9aad4f8e2..b5f565e9fe 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -125,9 +125,11 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey [] ) log.Info("Trie dumping started", "root", s.trie.Hash()) c.OnRoot(s.trie.Hash()) + fmt.Println("iterating root") trieIt, err := s.trie.NodeIterator(conf.Start) if err != nil { + fmt.Println("trie error", err) log.Error("Trie dumping error", "err", err) return nil } @@ -200,6 +202,7 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey [] } } if missingPreimages > 0 { + fmt.Println("missing image") log.Warn("Dump incomplete due to missing preimages", "missing", missingPreimages) } log.Info("Trie dumping complete", "accounts", accounts, diff --git a/core/state_processor.go b/core/state_processor.go index 5b41e7fa5a..1140206a7d 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -210,6 +210,7 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b // for the transaction, gas used and an error if the transaction failed, // indicating the block was invalid. func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) { + fmt.Println("ApplyTransaction") msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number, header.Time), header.BaseFee) if err != nil { return nil, err diff --git a/core/state_transition.go b/core/state_transition.go index 7b541b5f34..d9667c3be1 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/kzg4844" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/holiman/uint256" ) @@ -197,6 +198,7 @@ func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.In // indicates a core error meaning that the message would always fail for that particular // state and would never be accepted within a block. func ApplyMessage(evm *vm.EVM, msg *Message, gp *GasPool) (*ExecutionResult, error) { + fmt.Println("ApplyMessage") return NewStateTransition(evm, msg, gp).TransitionDb() } @@ -297,7 +299,7 @@ func GetEffectiveGasBalance(state vm.StateDB, chainconfig *params.ChainConfig, a } func GetGasBalances(state vm.StateDB, chainconfig *params.ChainConfig, account common.Address) (*uint256.Int, *uint256.Int) { - balance := state.GetBalance(account) + balance := state.GetBalance(account).Clone() if chainconfig != nil && chainconfig.IsOptimism() && chainconfig.Optimism.UseSoulGasToken { sgtBalanceSlot := TargetSGTBalanceSlot(account) sgtBalanceValue := state.GetState(types.SoulGasTokenAddr, sgtBalanceSlot) @@ -380,12 +382,15 @@ func (st *StateTransition) buyGas() error { st.gasFromSoul = false if st.evm.ChainConfig().IsOptimism() && st.evm.ChainConfig().Optimism.UseSoulGasToken { + fmt.Println("Checking SGT") have := st.GetSoulBalance(st.msg.From) if have, want := have.ToBig(), new(big.Int).Sub(balanceCheck, st.msg.Value); have.Cmp(want) >= 0 { if have, want := st.state.GetBalance(st.msg.From).ToBig(), st.msg.Value; have.Cmp(want) < 0 { return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From.Hex(), have, want) } st.gasFromSoul = true + fmt.Println("buySGT") + log.Info(("Run a SGT tx")) } } if !st.gasFromSoul { @@ -414,6 +419,8 @@ func (st *StateTransition) buyGas() error { } func (st *StateTransition) preCheck() error { + fmt.Println("buyGas") + if st.msg.IsDepositTx { // No fee fields to check, no nonce to check, and no need to check if EOA (L1 already verified it for us) // Gas is free, but no refunds! @@ -429,6 +436,9 @@ func (st *StateTransition) preCheck() error { } return st.gp.SubGas(st.msg.GasLimit) // gas used by deposits may not be used by other txs } + + fmt.Println("buyGas1") + // Only check transactions that are not fake msg := st.msg if !msg.SkipNonceChecks { @@ -756,6 +766,8 @@ func (st *StateTransition) refundGas(refundQuotient uint64) uint64 { // Return ETH for remaining gas, exchanged at the original rate. if st.gasFromSoul { remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gasRemaining), st.msg.GasPrice) + log.Info("refund", "remaining", remaining) + fmt.Println("refund") st.AddSoulBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn) } else { remaining := uint256.NewInt(st.gasRemaining)