Skip to content

Commit

Permalink
gasLimit: error on gas limit too high for queue origin sequencer txs (e…
Browse files Browse the repository at this point in the history
…thereum#180)

* gasLimit: prevent txs with too high of gas limit

* gasLimit: fixes + test

* test: fix

* send tx: use >=
  • Loading branch information
tynes authored Jan 12, 2021
1 parent 42c15d2 commit 5314233
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
16 changes: 12 additions & 4 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts"
Expand Down Expand Up @@ -48,6 +49,8 @@ type EthAPIBackend struct {
gpo *gasprice.Oracle
verifier bool
DisableTransfers bool
GasLimit uint64
UsingOVM bool
}

func (b *EthAPIBackend) RollupTransactionSender() *common.Address {
Expand Down Expand Up @@ -271,14 +274,18 @@ func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscri
// Transactions originating from the RPC endpoints are added to remotes so that
// a lock can be used around the remotes for when the sequencer is reorganizing.
func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
if vm.UsingOVM {
if b.UsingOVM {
to := signedTx.To()
if to != nil {
if *to == (common.Address{}) {
return errors.New("Cannot send transaction to zero address")
}

// Need to add a config option here
// Prevent transactions from being submitted if the gas limit too high
if signedTx.Gas() >= b.GasLimit {
return fmt.Errorf("Transaction gasLimit (%d) is greater than max gasLimit (%d)", signedTx.Gas(), b.GasLimit)
}

if b.DisableTransfers {
data := signedTx.Data()
if len(data) >= 4 {
Expand All @@ -295,9 +302,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
}
}
}

return b.eth.syncService.ApplyTransaction(signedTx)
}
return b.eth.syncService.ApplyTransaction(signedTx)
// OVM Disabled
return b.eth.txPool.AddLocal(signedTx)
}

func (b *EthAPIBackend) SetTimestamp(timestamp int64) {
Expand Down
44 changes: 44 additions & 0 deletions eth/api_backend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package eth

import (
"context"
"fmt"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

func TestGasLimit(t *testing.T) {
backend := &EthAPIBackend{
extRPCEnabled: false,
eth: nil,
gpo: nil,
verifier: false,
DisableTransfers: false,
GasLimit: 0,
UsingOVM: true,
}

nonce := uint64(0)
to := common.HexToAddress("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c")
value := big.NewInt(0)
gasPrice := big.NewInt(0)
data := []byte{}
qo := types.QueueOriginSequencer
sighash := types.SighashEIP155

// Set the gas limit to 1 so that the transaction will not be
// able to be added.
gasLimit := uint64(1)
tx := types.NewTransaction(nonce, to, value, gasLimit, gasPrice, data, nil, nil, qo, sighash)

err := backend.SendTx(context.Background(), tx)
if err == nil {
t.Fatal("Transaction with too large of gas limit accepted")
}
if err.Error() != fmt.Sprintf("Transaction gasLimit (%d) is greater than max gasLimit (%d)", gasLimit, backend.GasLimit) {
t.Fatalf("Unexpected error type: %s", err)
}
}
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, config.Rollup.IsVerifier, config.Rollup.DisableTransfers}
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, config.Rollup.IsVerifier, config.Rollup.DisableTransfers, config.Rollup.GasLimit, vm.UsingOVM}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
Expand Down

0 comments on commit 5314233

Please sign in to comment.