Skip to content

Commit

Permalink
test: ProcessProposal with invalid namespace in index wrapped PFB tx (#…
Browse files Browse the repository at this point in the history
…1614)

Closes #1558
  • Loading branch information
rootulp authored Apr 13, 2023
1 parent 70eb8e5 commit dd19531
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 7 deletions.
41 changes: 34 additions & 7 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"testing"

"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -30,6 +31,7 @@ func TestProcessProposal(t *testing.T) {
accounts := testfactory.GenerateAccounts(6)
testApp, kr := testutil.SetupTestAppWithGenesisValSet(accounts...)
infos := queryAccountInfo(testApp, accounts, kr)
signer := types.GenerateKeyringSigner(t, accounts[0])

// create 3 single blob blobTxs that are signed with valid account numbers
// and sequences
Expand Down Expand Up @@ -107,17 +109,18 @@ func TestProcessProposal(t *testing.T) {
)[0]
badSigPFBData.Txs = append(badSigPFBData.Txs, badSigBlobTx)

ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))
invalidNamespace, err := appns.New(appns.NamespaceVersionZero, bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))
// expect an error because the input is invalid: it doesn't contain the namespace version zero prefix.
assert.Error(t, err)
data := bytes.Repeat([]byte{1}, 13)

type test struct {
name string
input *core.Data
mutator func(*core.Data)
expectedResult abci.ResponseProcessProposal_Result
}
ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))
// explicitly ignore the error from appns.New because we know the input is
// invalid because it doesn't contain the namespace verzion zero prefix
invalidNamespace, _ := appns.New(appns.NamespaceVersionZero, bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))
data := []byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}

tests := []test{
{
Expand Down Expand Up @@ -203,18 +206,42 @@ func TestProcessProposal(t *testing.T) {
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "invalid namespace",
name: "invalid blob namespace",
input: validData(),
mutator: func(d *core.Data) {
d.Blobs[0] = core.Blob{
NamespaceId: invalidNamespace.ID,
Data: data,
NamespaceVersion: uint32(invalidNamespace.Version),
ShareVersion: uint32(appconsts.ShareVersionZero),
NamespaceVersion: uint32(invalidNamespace.Version),
}
},
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "invalid namespace in index wrapper tx",
input: validData(),
mutator: func(d *core.Data) {
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
index := 4
tx, blob := blobfactory.IndexWrappedTxWithInvalidNamespace(t, encCfg.TxConfig.TxEncoder(), signer, 0, 0, uint32(index))

// Replace the data with new contents
d.Blobs = []tmproto.Blob{blob}
d.Txs = [][]byte{tx}

// Erasure code the data to update the data root so this doesn't doesn't fail on an incorrect data root.
coreData, err := coretypes.DataFromProto(d)
assert.NoError(t, err)
dataSquare, err := shares.Split(coreData, true)
assert.NoError(t, err)
eds, err := da.ExtendShares(d.SquareSize, shares.ToBytes(dataSquare))
assert.NoError(t, err)
dah := da.NewDataAvailabilityHeader(eds)
d.Hash = dah.Hash()
},
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "unsorted blobs",
input: validData(),
Expand Down
45 changes: 45 additions & 0 deletions testutil/blobfactory/payforblob_factory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blobfactory

import (
"bytes"
"context"
"testing"

Expand Down Expand Up @@ -377,6 +378,50 @@ func MultiBlobTx(
return cTx
}

// IndexWrappedTxWithInvalidNamespace returns an index wrapped PFB tx with an
// invalid namespace and a blob associated with that index wrapped PFB tx.
func IndexWrappedTxWithInvalidNamespace(
t *testing.T,
enc sdk.TxEncoder,
signer *blobtypes.KeyringSigner,
sequence uint64,
accountNum uint64,
index uint32,
) (coretypes.Tx, tmproto.Blob) {
addr, err := signer.GetSignerInfo().GetAddress()
require.NoError(t, err)

coin := sdk.Coin{
Denom: bondDenom,
Amount: sdk.NewInt(10),
}
opts := []blobtypes.TxBuilderOption{
blobtypes.SetFeeAmount(sdk.NewCoins(coin)),
blobtypes.SetGasLimit(10000000),
}

blob := ManyRandBlobs(t, 100)[0]
msg, err := blobtypes.NewMsgPayForBlobs(addr.String(), blob)
require.NoError(t, err)

signer.SetAccountNumber(accountNum)
signer.SetSequence(sequence)

msg.Namespaces[0] = bytes.Repeat([]byte{1}, 33) // invalid namespace

builder := signer.NewTxBuilder(opts...)
stx, err := signer.BuildSignedTx(builder, msg)
require.NoError(t, err)

rawTx, err := enc(stx)
require.NoError(t, err)

cTx, err := coretypes.MarshalIndexWrapper(rawTx, index)
require.NoError(t, err)

return cTx, *blob
}

func RandBlobTxsWithNamespacesAndSigner(
enc sdk.TxEncoder,
signer *blobtypes.KeyringSigner,
Expand Down

0 comments on commit dd19531

Please sign in to comment.