Skip to content

Commit

Permalink
[fix]: hack l2geth
Browse files Browse the repository at this point in the history
  • Loading branch information
Sha3nS committed Jan 12, 2024
1 parent dc93f2a commit c7ccf33
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion datalayr
22 changes: 15 additions & 7 deletions l2geth/core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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

Expand All @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion l2geth/core/vm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion l2geth/core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions l2geth/core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c7ccf33

Please sign in to comment.