Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: hack l2geth #1396

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datalayr
40 changes: 40 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

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), "msg.From", msg.From(), "msg.To", msg.To(), "msg.Nonce", msg.Nonce())
// 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
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,17 @@
npmlog "^4.1.2"
write-file-atomic "^3.0.3"

"@mantleio/sdk@0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@mantleio/sdk/-/sdk-0.2.1.tgz#b1f1331cfc166ff5fbe4da565078952eb4611c52"
integrity sha512-bPC3eHEsRHSPAVv4EGC6lY43btiMaEK0e39yArz9LBtub8EkxyokDnD+XLdaeQrL8flucTH5DRcZAanqn9bq4g==
dependencies:
"@mantleio/contracts" "0.2.1"
"@mantleio/core-utils" "0.1.0"
lodash "^4.17.21"
merkletreejs "^0.2.27"
rlp "^2.2.7"

"@manypkg/find-root@^1.1.0":
version "1.1.0"
resolved "https://registry.npmjs.org/@manypkg/find-root/-/find-root-1.1.0.tgz"
Expand Down
Loading