Skip to content

Commit

Permalink
Only allow deposit messages from the op node
Browse files Browse the repository at this point in the history
The important change is in helpers/ante.go.

Before, we were only blocking deposit transactions from the Monomer mempool.
This meant that standard auth txs could contain deposit messages, minting arbitrary amounts of eth.
We fix this by checking for deposit messages in all transactions in helpers/ante.go.
  • Loading branch information
joshklop committed Dec 5, 2024
1 parent b427ec0 commit 1b6970a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
8 changes: 0 additions & 8 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

comettypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/polymerdao/monomer"
"github.com/polymerdao/monomer/utils"
)

Expand Down Expand Up @@ -39,13 +38,6 @@ func (p *Pool) Enqueue(userTxn comettypes.Tx) (err error) {
// Unfortunately, comet's DB interface doesn't support it.
// Moving to a different DB interface is left for future work.

// Attempt to adapt the Cosmos transaction to an Ethereum deposit transaction.
// If the adaptation succeeds, it indicates that the
// user transaction is a deposit transaction, which is not allowed in the pool.
if _, err := monomer.GetDepositTxs(userTxn); err == nil {
return errors.New("deposit txs are not allowed in the pool")
}

batch := p.db.NewBatch()
defer func() {
err = utils.WrapCloseErr(err, batch)
Expand Down
14 changes: 0 additions & 14 deletions mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"testing"

comettypes "github.com/cometbft/cometbft/types"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/polymerdao/monomer"
"github.com/polymerdao/monomer/mempool"
"github.com/polymerdao/monomer/testutils"
"github.com/stretchr/testify/assert"
Expand All @@ -24,18 +22,6 @@ func TestMempool(t *testing.T) {
require.Error(t, err)
})

t.Run("deposit transaction", func(t *testing.T) {
l1AttributesTx, depositTx, _ := testutils.GenerateEthTxs(t)
l1AttributesTxBytes, err := l1AttributesTx.MarshalBinary()
require.NoError(t, err)
depositTxBytes, err := depositTx.MarshalBinary()
require.NoError(t, err)

cosmosTxs, err := monomer.AdaptPayloadTxsToCosmosTxs([]hexutil.Bytes{l1AttributesTxBytes, depositTxBytes})
require.NoError(t, err)
require.ErrorContains(t, pool.Enqueue(cosmosTxs[0]), "deposit txs are not allowed in the pool")
})

// enqueue multiple to empty
for i := byte(0); i < 3; i++ {
require.NoError(t, pool.Enqueue(comettypes.Tx([]byte{i})))
Expand Down
31 changes: 19 additions & 12 deletions x/rollup/tx/helpers/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helpers

import (
"errors"
"fmt"

sdktypes "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -35,22 +36,28 @@ func (a *AnteHandler) AnteHandle(
tx sdktypes.Tx,
simulate bool,
) (sdktypes.Context, error) {
switch tx.(type) {
case *rolluptypes.DepositsTx:
if _, ok := tx.(*rolluptypes.DepositsTx); ok {
newCtx, err := rolluptx.DepositAnteHandler(ctx, tx, simulate)
if err != nil {
return newCtx, fmt.Errorf("deposit ante handle: %v", err)
}
return newCtx, err
default: // Unfortunately, the Cosmos SDK does not export its default tx type.
newCtx, err := a.authAnteHandler(ctx, tx, simulate)
if err != nil {
return newCtx, fmt.Errorf("auth ante handle: %v", err)
}
newCtx, err = rolluptx.L1DataAnteHandler(newCtx, tx, a.rollupKeeper)
if err != nil {
return newCtx, fmt.Errorf("l1 data ante handle: %v", err)
}
return newCtx, nil
}

for _, msg := range tx.GetMsgs() {
if _, ok := msg.(rolluptypes.DepositMsg); ok {

Check failure on line 48 in x/rollup/tx/helpers/ante.go

View workflow job for this annotation

GitHub Actions / go

undefined: rolluptypes.DepositMsg (typecheck)

Check failure on line 48 in x/rollup/tx/helpers/ante.go

View workflow job for this annotation

GitHub Actions / go

undefined: rolluptypes.DepositMsg) (typecheck)

Check failure on line 48 in x/rollup/tx/helpers/ante.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: rolluptypes.DepositMsg

Check failure on line 48 in x/rollup/tx/helpers/ante.go

View workflow job for this annotation

GitHub Actions / short (ubuntu-latest)

undefined: rolluptypes.DepositMsg

Check failure on line 48 in x/rollup/tx/helpers/ante.go

View workflow job for this annotation

GitHub Actions / short (macos-latest)

undefined: rolluptypes.DepositMsg
return ctx, errors.New("transaction contains deposit message")
}
}

// need the tx decoder
newCtx, err := a.authAnteHandler(ctx, tx, simulate)
if err != nil {
return newCtx, fmt.Errorf("auth ante handle: %v", err)
}
newCtx, err = rolluptx.L1DataAnteHandler(newCtx, tx, a.rollupKeeper)
if err != nil {
return newCtx, fmt.Errorf("l1 data ante handle: %v", err)
}
return newCtx, nil
}

0 comments on commit 1b6970a

Please sign in to comment.