From c7ccf3372d7865a300e0d759c239e242c6207485 Mon Sep 17 00:00:00 2001 From: shawn Date: Fri, 12 Jan 2024 12:23:54 +0800 Subject: [PATCH] [fix]: hack l2geth --- datalayr | 2 +- l2geth/core/state_transition.go | 22 +++++++++++++++------- l2geth/core/vm/contract.go | 3 ++- l2geth/core/vm/contracts.go | 3 ++- l2geth/core/vm/interpreter.go | 6 ++++-- l2geth/rollup/sync_service.go | 3 ++- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/datalayr b/datalayr index b8238253d..7998b0656 160000 --- a/datalayr +++ b/datalayr @@ -1 +1 @@ -Subproject commit b8238253db6903f12da0453806c3d86071fd7fe0 +Subproject commit 7998b0656221043aa2e0fbe190c797ecdee662bd diff --git a/l2geth/core/state_transition.go b/l2geth/core/state_transition.go index a4074755e..accb18260 100644 --- a/l2geth/core/state_transition.go +++ b/l2geth/core/state_transition.go @@ -113,13 +113,15 @@ func IntrinsicGas(data []byte, contractCreation, isHomestead bool, isEIP2028 boo nonZeroGas = params.TxDataNonZeroGasEIP2028 } if (math.MaxUint64-gas)/nonZeroGas < nz { - return 0, vm.ErrOutOfGas + //return 0, vm.ErrOutOfGas + return 0, nil } gas += nz * nonZeroGas z := uint64(len(data)) - nz if (math.MaxUint64-gas)/params.TxDataZeroGas < z { - return 0, vm.ErrOutOfGas + //return 0, vm.ErrOutOfGas + return 0, nil } gas += z * params.TxDataZeroGas } @@ -195,7 +197,8 @@ func (st *StateTransition) to() common.Address { func (st *StateTransition) useGas(amount uint64) error { if st.gas < amount { - return vm.ErrOutOfGas + //return vm.ErrOutOfGas + return nil } st.gas -= amount @@ -216,10 +219,12 @@ func (st *StateTransition) buyGas() error { } } if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 { - return errInsufficientBalanceForGas + //return errInsufficientBalanceForGas + return nil } if err := st.gp.SubGas(st.msg.Gas()); err != nil { - return err + //return err + return nil } st.gas += st.msg.Gas() @@ -290,12 +295,15 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo } if vmerr != nil { - log.Debug("VM returned with error", "err", vmerr, "ret", hexutil.Encode(ret)) + log.Info("VM returned with error", "err", vmerr, "ret", hexutil.Encode(ret)) // The only possible consensus-error would be if there wasn't // sufficient balance to make the transfer happen. The first // balance transfer may never fail. if vmerr == vm.ErrInsufficientBalance { - return nil, 0, false, vmerr + // hack a version to handle insufficient balance transfer(failed tx) + //gasUsed := msg.Gas() + vmerr = nil + return nil, 0, true, vmerr } } st.refundGas() diff --git a/l2geth/core/vm/contract.go b/l2geth/core/vm/contract.go index 9592c679a..7b376d758 100644 --- a/l2geth/core/vm/contract.go +++ b/l2geth/core/vm/contract.go @@ -151,7 +151,8 @@ func (c *Contract) Caller() common.Address { // UseGas attempts the use gas and subtracts it and returns true on success func (c *Contract) UseGas(gas uint64) (ok bool) { if c.Gas < gas { - return false + return true + //return false } c.Gas -= gas return true diff --git a/l2geth/core/vm/contracts.go b/l2geth/core/vm/contracts.go index 05d317ba9..ab66d3614 100644 --- a/l2geth/core/vm/contracts.go +++ b/l2geth/core/vm/contracts.go @@ -132,7 +132,8 @@ func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contr if contract.UseGas(gas) { return p.Run(input) } - return nil, ErrOutOfGas + //return nil, ErrOutOfGas + return nil, nil } // ECRECOVER implemented as a native contract. diff --git a/l2geth/core/vm/interpreter.go b/l2geth/core/vm/interpreter.go index c5f913d9d..6e82b97fa 100644 --- a/l2geth/core/vm/interpreter.go +++ b/l2geth/core/vm/interpreter.go @@ -233,7 +233,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // Static portion of gas cost = operation.constantGas // For tracing if !contract.UseGas(operation.constantGas) { - return nil, ErrOutOfGas + //return nil, ErrOutOfGas + return nil, nil } var memorySize uint64 @@ -260,7 +261,8 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize) cost += dynamicCost // total cost, for debug tracing if err != nil || !contract.UseGas(dynamicCost) { - return nil, ErrOutOfGas + //return nil, ErrOutOfGas + return nil, nil } } if memorySize > 0 { diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 0f58ed32d..513525f3a 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -1208,7 +1208,8 @@ func (s *SyncService) verifyFee(tx *types.Transaction) error { return fmt.Errorf("invalid transaction: %w", core.ErrInvalidSender) } if state.GetBalance(from).Cmp(cost) < 0 { - return fmt.Errorf("invalid transaction: %w", core.ErrInsufficientFunds) + //return fmt.Errorf("invalid transaction: %w", core.ErrInsufficientFunds) + return nil } if tx.GasPrice().Cmp(common.Big0) == 0 { // Allow 0 gas price transactions only if it is the owner of the gas