From 7bad5ea95067a52d76a5b89c33a362ab516da392 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 26 Jul 2024 17:17:30 +0200 Subject: [PATCH 1/9] chore!: migrate to new square version --- app/check_tx.go | 7 +- app/errors/insufficient_gas_price_test.go | 4 +- app/errors/nonce_mismatch_test.go | 4 +- app/extend_block.go | 6 +- app/prepare_proposal.go | 6 +- app/process_proposal.go | 13 +- app/test/big_blob_test.go | 6 +- app/test/check_tx_test.go | 23 ++- app/test/consistent_apphash_test.go | 24 ++- app/test/integration_test.go | 15 +- app/test/prepare_proposal_test.go | 9 +- app/test/priority_test.go | 4 +- app/test/process_proposal_test.go | 111 +++++------ app/validate_txs.go | 17 +- go.mod | 4 +- go.sum | 4 +- pkg/appconsts/global_consts.go | 2 +- pkg/da/data_availability_header.go | 4 +- pkg/da/data_availability_header_test.go | 4 +- pkg/inclusion/get_commit.go | 2 +- pkg/inclusion/nmt_caching_test.go | 6 +- pkg/inclusion/paths.go | 2 +- pkg/proof/proof.go | 36 ++-- pkg/proof/proof_test.go | 47 +++-- pkg/proof/querier.go | 32 ++-- pkg/proof/row_proof.go | 2 +- pkg/user/e2e_test.go | 6 +- pkg/user/signer.go | 6 +- pkg/user/tx_client.go | 20 +- pkg/wrapper/nmt_wrapper.go | 2 +- pkg/wrapper/nmt_wrapper_test.go | 2 +- proto/celestia/core/v1/blob/blob.proto | 2 +- specs/src/specs/namespace.md | 4 +- specs/src/specs/shares.md | 2 +- test/txsim/account.go | 6 +- test/txsim/blob.go | 14 +- test/txsim/sequence.go | 4 +- test/util/blobfactory/payforblob_factory.go | 52 +++--- test/util/direct_tx_gen.go | 4 +- test/util/malicious/app_test.go | 8 +- test/util/malicious/out_of_order_builder.go | 27 ++- test/util/malicious/out_of_order_prepare.go | 4 +- test/util/malicious/tree.go | 5 +- test/util/testfactory/blob.go | 39 ++-- test/util/testfactory/common.go | 4 +- test/util/testfactory/namespace.go | 16 +- test/util/testnode/full_node_test.go | 2 +- test/util/testnode/node_interaction_api.go | 12 +- test/util/testnode/read.go | 7 +- x/blob/ante/ante_test.go | 14 +- x/blob/ante/blob_share_decorator.go | 4 +- x/blob/ante/blob_share_decorator_test.go | 20 +- x/blob/ante/max_total_blob_size_ante.go | 4 +- x/blob/ante/max_total_blob_size_ante_test.go | 16 +- x/blob/client/cli/payforblob.go | 31 ++-- x/blob/client/testutil/integration_test.go | 6 +- x/blob/keeper/keeper_test.go | 10 +- x/blob/test/decode_blob_tx_test.go | 7 +- x/blob/types/blob_tx.go | 35 ++-- x/blob/types/blob_tx_test.go | 113 +++++------ x/blob/types/estimate_gas_test.go | 8 +- x/blob/types/params.go | 4 +- x/blob/types/payforblob.go | 59 ++---- x/blob/types/payforblob_test.go | 185 ++++++------------- x/blobstream/client/verify.go | 4 +- 65 files changed, 550 insertions(+), 612 deletions(-) diff --git a/app/check_tx.go b/app/check_tx.go index 316359dedc..b2e5103cf9 100644 --- a/app/check_tx.go +++ b/app/check_tx.go @@ -5,7 +5,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abci "github.com/tendermint/tendermint/abci/types" ) @@ -16,7 +16,10 @@ import ( func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { tx := req.Tx // check if the transaction contains blobs - btx, isBlob := blob.UnmarshalBlobTx(tx) + btx, isBlob, err := share.UnmarshalBlobTx(tx) + if isBlob && err != nil { + return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false) + } if !isBlob { // reject transactions that can't be decoded diff --git a/app/errors/insufficient_gas_price_test.go b/app/errors/insufficient_gas_price_test.go index 401bf78a1a..049f1afb00 100644 --- a/app/errors/insufficient_gas_price_test.go +++ b/app/errors/insufficient_gas_price_test.go @@ -13,7 +13,7 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -40,7 +40,7 @@ func TestInsufficientMinGasPriceIntegration(t *testing.T) { signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence())) require.NoError(t, err) - b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0) + b, err := blob.NewBlob(share.RandomNamespace(), []byte("hello world"), 0) require.NoError(t, err) msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, b) diff --git a/app/errors/nonce_mismatch_test.go b/app/errors/nonce_mismatch_test.go index fdb8126df2..0f8744ae03 100644 --- a/app/errors/nonce_mismatch_test.go +++ b/app/errors/nonce_mismatch_test.go @@ -12,7 +12,7 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/stretchr/testify/require" @@ -35,7 +35,7 @@ func TestNonceMismatchIntegration(t *testing.T) { signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence()+1)) require.NoError(t, err) - b, err := blob.NewBlob(namespace.RandomNamespace(), []byte("hello world"), 0) + b, err := blob.NewBlob(share.RandomNamespace(), []byte("hello world"), 0) require.NoError(t, err) msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, b) diff --git a/app/extend_block.go b/app/extend_block.go index 11586f5a2b..f14a764b26 100644 --- a/app/extend_block.go +++ b/app/extend_block.go @@ -3,8 +3,8 @@ package app import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + square "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" coretypes "github.com/tendermint/tendermint/types" ) @@ -22,7 +22,7 @@ func ExtendBlock(data coretypes.Data, appVersion uint64) (*rsmt2d.ExtendedDataSq return nil, err } - return da.ExtendShares(shares.ToBytes(dataSquare)) + return da.ExtendShares(share.ToBytes(dataSquare)) } // EmptyBlock returns true if the given block data is considered empty by the diff --git a/app/prepare_proposal.go b/app/prepare_proposal.go index a7e90fc42c..78049a1ad4 100644 --- a/app/prepare_proposal.go +++ b/app/prepare_proposal.go @@ -6,8 +6,8 @@ import ( "github.com/celestiaorg/celestia-app/v3/app/ante" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + square "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/telemetry" abci "github.com/tendermint/tendermint/abci/types" core "github.com/tendermint/tendermint/proto/tendermint/types" @@ -58,7 +58,7 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr // Erasure encode the data square to create the extended data square (eds). // Note: uses the nmt wrapper to construct the tree. See // pkg/wrapper/nmt_wrapper.go for more information. - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(share.ToBytes(dataSquare)) if err != nil { app.Logger().Error( "failure to erasure the data square while creating a proposal block", diff --git a/app/process_proposal.go b/app/process_proposal.go index c67766e237..668c80b4f2 100644 --- a/app/process_proposal.go +++ b/app/process_proposal.go @@ -9,9 +9,8 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/da" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -56,8 +55,12 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp // blobTxs have no PFBs present for idx, rawTx := range req.BlockData.Txs { tx := rawTx - blobTx, isBlobTx := blob.UnmarshalBlobTx(rawTx) + blobTx, isBlobTx, err := share.UnmarshalBlobTx(rawTx) if isBlobTx { + if err != nil { + logInvalidPropBlockError(app.Logger(), req.Header, fmt.Sprintf("err with blob tx %d", idx), err) + return reject() + } tx = blobTx.Tx } @@ -135,7 +138,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp return reject() } - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(share.ToBytes(dataSquare)) if err != nil { logInvalidPropBlockError(app.Logger(), req.Header, "failure to erasure the data square", err) return reject() diff --git a/app/test/big_blob_test.go b/app/test/big_blob_test.go index 4ae8266a6b..41934c6379 100644 --- a/app/test/big_blob_test.go +++ b/app/test/big_blob_test.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -61,7 +61,7 @@ func (s *BigBlobSuite) TestErrBlobsTooLarge() { type testCase struct { name string - blob *blob.Blob + blob *share.Blob // want is the expected tx response ABCI code. want uint32 } @@ -80,7 +80,7 @@ func (s *BigBlobSuite) TestErrBlobsTooLarge() { s.Run(tc.name, func() { subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second) defer cancel() - res, err := txClient.SubmitPayForBlob(subCtx, []*blob.Blob{tc.blob}, user.SetGasLimitAndGasPrice(1e9, appconsts.DefaultMinGasPrice)) + res, err := txClient.SubmitPayForBlob(subCtx, []*share.Blob{tc.blob}, user.SetGasLimitAndGasPrice(1e9, appconsts.DefaultMinGasPrice)) require.Error(t, err) require.NotNil(t, res) require.Equal(t, tc.want, res.Code, res.Logs) diff --git a/app/test/check_tx_test.go b/app/test/check_tx_test.go index 88f04b2472..b582272ff7 100644 --- a/app/test/check_tx_test.go +++ b/app/test/check_tx_test.go @@ -15,8 +15,7 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -27,7 +26,8 @@ import ( // assume that the rest of CheckTx is tested by the cosmos-sdk. func TestCheckTx(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1, err := share.NewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) + require.NoError(t, err) accs := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"} @@ -51,7 +51,7 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[0], encCfg.TxConfig, 1) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []share.Namespace{ns1}, []int{100}, )[0] return btx @@ -65,7 +65,7 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[1], encCfg.TxConfig, 2) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []share.Namespace{ns1}, []int{100}, )[0] return btx @@ -79,13 +79,16 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[2], encCfg.TxConfig, 3) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []share.Namespace{ns1}, []int{100}, )[0] - dtx, _ := blob.UnmarshalBlobTx(btx) - dtx.Blobs[0].NamespaceId = appns.RandomBlobNamespace().ID - bbtx, err := blob.MarshalBlobTx(dtx.Tx, dtx.Blobs[0]) + dtx, _, err := share.UnmarshalBlobTx(btx) + require.NoError(t, err) + newBlob, err := share.NewBlob(share.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion, nil) + require.NoError(t, err) + dtx.Blobs[0] = newBlob + bbtx, err := share.MarshalBlobTx(dtx.Tx, dtx.Blobs[0]) require.NoError(t, err) return bbtx }, @@ -98,7 +101,7 @@ func TestCheckTx(t *testing.T) { signer := createSigner(t, kr, accs[3], encCfg.TxConfig, 4) btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []appns.Namespace{ns1}, + []share.Namespace{ns1}, []int{100}, )[0] dtx, _ := coretypes.UnmarshalBlobTx(btx) diff --git a/app/test/consistent_apphash_test.go b/app/test/consistent_apphash_test.go index 85c4fe5b7c..6193656f3d 100644 --- a/app/test/consistent_apphash_test.go +++ b/app/test/consistent_apphash_test.go @@ -13,8 +13,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -37,7 +36,7 @@ import ( type BlobTx struct { author string - blobs []*blob.Blob + blobs []*share.Blob txOptions []user.TxOption } @@ -268,10 +267,13 @@ func TestConsistentAppHash(t *testing.T) { thirdBlockEncodedTxs, err := processSdkMessages(valSigner, thirdBlockSdkMsgs) require.NoError(t, err) + blob, err := share.NewBlob(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion, nil) + require.NoError(t, err) + // Create a Blob Tx blobTx := BlobTx{ author: accountNames[1], - blobs: []*blob.Blob{blob.New(fixedNamespace(), []byte{1}, appconsts.DefaultShareVersion)}, + blobs: []*share.Blob{blob}, txOptions: blobfactory.DefaultTxOpts(), } encodedBlobTx, _, err := signer.CreatePayForBlobs(blobTx.author, blobTx.blobs, blobTx.txOptions...) @@ -300,11 +302,12 @@ func TestConsistentAppHash(t *testing.T) { } // fixedNamespace returns a hardcoded namespace -func fixedNamespace() appns.Namespace { - return appns.Namespace{ - Version: 0, - ID: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 67, 154, 200, 228, 130, 74, 147, 162, 11}, +func fixedNamespace() share.Namespace { + ns, err := share.NewNamespace(0, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 67, 154, 200, 228, 130, 74, 147, 162, 11}) + if err != nil { + panic(err) } + return ns } // deterministicKeyRing returns a deterministic keyring and a list of deterministic public keys @@ -430,10 +433,13 @@ func executeTxs(testApp *app.App, encodedBlobTx []byte, encodedSdkTxs [][]byte, // Deliver Blob Txs if len(encodedBlobTx) != 0 { // Deliver Blob Tx - blob, isBlobTx := blob.UnmarshalBlobTx(encodedBlobTx) + blob, isBlobTx, err := share.UnmarshalBlobTx(encodedBlobTx) if !isBlobTx { return nil, nil, fmt.Errorf("Not a valid BlobTx") } + if err != nil { + return nil, nil, fmt.Errorf("Not a valid BlobTx: %w", err) + } respDeliverTx := testApp.DeliverTx(abci.RequestDeliverTx{Tx: blob.Tx}) if respDeliverTx.Code != uint32(0) { diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 2529bc4bc6..6988843357 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -24,9 +24,8 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/celestia-app/v3/pkg/user" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/square" + square "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" abci "github.com/tendermint/tendermint/abci/types" tmrand "github.com/tendermint/tendermint/libs/rand" @@ -287,8 +286,12 @@ func (s *IntegrationTestSuite) TestEmptyBlock() { } } -func newBlobWithSize(size int) *blob.Blob { - ns := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) +func newBlobWithSize(size int) *share.Blob { + ns := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) data := tmrand.Bytes(size) - return blob.New(ns, data, appconsts.ShareVersionZero) + blob, err := share.NewBlob(ns, data, appconsts.ShareVersionZero, nil) + if err != nil { + panic(err) + } + return blob } diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index a1c9cfc22e..d37be2dc23 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -19,8 +19,7 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" ) func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) { @@ -30,6 +29,8 @@ func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) infos := queryAccountInfo(testApp, accnts, kr) + protoBlob, err := share.NewBlob(share.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion, nil) + require.NoError(t, err) blobTxs := blobfactory.ManyMultiBlobTx( t, encCfg.TxConfig, @@ -37,9 +38,7 @@ func TestPrepareProposalPutsPFBsAtEnd(t *testing.T) { testutil.ChainID, accnts[:numBlobTxs], infos[:numBlobTxs], - testfactory.Repeat([]*blob.Blob{ - blob.New(appns.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion), - }, numBlobTxs), + testfactory.Repeat([]*share.Blob{protoBlob}, numBlobTxs), ) normalTxs := testutil.SendTxsWithAccounts( diff --git a/app/test/priority_test.go b/app/test/priority_test.go index e401f98177..72586e5718 100644 --- a/app/test/priority_test.go +++ b/app/test/priority_test.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/user" @@ -85,7 +85,7 @@ func (s *PriorityTestSuite) TestPriorityByGasPrice() { defer wg.Done() // ensure that it is greater than the min gas price gasPrice := float64(s.rand.Intn(1000)+1) * appconsts.DefaultMinGasPrice - blobs := blobfactory.ManyBlobs(s.rand, []namespace.Namespace{namespace.RandomBlobNamespace()}, []int{100}) + blobs := blobfactory.ManyBlobs(s.rand, []share.Namespace{share.RandomBlobNamespace()}, []int{100}) resp, err := s.txClient.BroadcastPayForBlobWithAccount( s.cctx.GoContext(), accName, diff --git a/app/test/process_proposal_test.go b/app/test/process_proposal_test.go index 52774e630e..303ac85be8 100644 --- a/app/test/process_proposal_test.go +++ b/app/test/process_proposal_test.go @@ -24,10 +24,8 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" ) func TestProcessProposal(t *testing.T) { @@ -75,8 +73,8 @@ func TestProcessProposal(t *testing.T) { t, enc, kr, 1000, 1, false, testutil.ChainID, accounts[:1], 1, 3, false, )[0] - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - invalidNamespace, err := appns.New(appns.NamespaceVersionZero, bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) + invalidNamespace, err := share.NewNamespace(share.NamespaceVersionZero, bytes.Repeat([]byte{1}, share.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) @@ -119,14 +117,12 @@ func TestProcessProposal(t *testing.T) { name: "modified a blobTx", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: ns1.ID, - Data: data, - NamespaceVersion: uint32(ns1.Version), - ShareVersion: uint32(appconsts.ShareVersionZero), - } - blobTxBytes, _ := blob.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + require.NoError(t, err) + newBlob, err := share.NewBlob(ns1, data, appconsts.ShareVersionZero, nil) + require.NoError(t, err) + blobTx.Blobs[0] = newBlob + blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -136,14 +132,12 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace TailPadding", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: appns.TailPaddingNamespace.ID, - Data: data, - NamespaceVersion: uint32(appns.TailPaddingNamespace.Version), - ShareVersion: uint32(appconsts.ShareVersionZero), - } - blobTxBytes, _ := blob.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + require.NoError(t, err) + newBlob, err := share.NewBlob(share.TailPaddingNamespace, data, appconsts.ShareVersionZero, nil) + require.NoError(t, err) + blobTx.Blobs[0] = newBlob + blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -153,14 +147,12 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace TxNamespace", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: appns.TxNamespace.ID, - Data: data, - NamespaceVersion: uint32(appns.TxNamespace.Version), - ShareVersion: uint32(appconsts.ShareVersionZero), - } - blobTxBytes, _ := blob.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + require.NoError(t, err) + newBlob, err := share.NewBlob(share.TxNamespace, data, appconsts.ShareVersionZero, nil) + require.NoError(t, err) + blobTx.Blobs[0] = newBlob + blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -170,14 +162,12 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace ParityShares", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: appns.ParitySharesNamespace.ID, - Data: data, - NamespaceVersion: uint32(appns.ParitySharesNamespace.Version), - ShareVersion: uint32(appconsts.ShareVersionZero), - } - blobTxBytes, _ := blob.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + require.NoError(t, err) + newBlob, err := share.NewBlob(share.ParitySharesNamespace, data, appconsts.ShareVersionZero, nil) + require.NoError(t, err) + blobTx.Blobs[0] = newBlob + blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -187,14 +177,21 @@ func TestProcessProposal(t *testing.T) { name: "invalid blob namespace", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0] = &blob.Blob{ - NamespaceId: invalidNamespace.ID, - Data: data, - ShareVersion: uint32(appconsts.ShareVersionZero), - NamespaceVersion: uint32(invalidNamespace.Version), + blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + require.NoError(t, err) + newBlob, err := share.NewBlob(invalidNamespace, data, appconsts.ShareVersionZero, nil) + require.NoError(t, err) + if newBlob == nil { + t.Fatal("newBlob is nil") } - blobTxBytes, _ := blob.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTx.Blobs[0] = newBlob + for _, blob := range blobTx.Blobs { + if blob == nil { + t.Fatal("blob is nil") + } + } + blobTxBytes, err := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + require.NoError(t, err) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -204,9 +201,14 @@ func TestProcessProposal(t *testing.T) { name: "pfb namespace version does not match blob", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _ := blob.UnmarshalBlobTx(blobTxs[0]) - blobTx.Blobs[0].NamespaceVersion = appns.NamespaceVersionMax - blobTxBytes, _ := blob.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + require.NoError(t, err) + nsMax, err := share.NewNamespace(share.NamespaceVersionMax, ns1.ID()) + require.Error(t, err) + newBlob, err := share.NewBlob(nsMax, data, appconsts.ShareVersionZero, nil) + require.NoError(t, err) + blobTx.Blobs[0] = newBlob + blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes d.Hash = calculateNewDataHash(t, d.Txs) }, @@ -219,7 +221,7 @@ func TestProcessProposal(t *testing.T) { mutator: func(d *tmproto.Data) { index := 4 tx, b := blobfactory.IndexWrappedTxWithInvalidNamespace(t, tmrand.NewRand(), signer, uint32(index)) - blobTx, err := blob.MarshalBlobTx(tx, b) + blobTx, err := share.MarshalBlobTx(tx, b) require.NoError(t, err) // Replace the data with new contents @@ -312,13 +314,14 @@ func TestProcessProposal(t *testing.T) { dataSquare, err := square.Construct(d.Txs, appconsts.DefaultSquareSizeUpperBound, appconsts.DefaultSubtreeRootThreshold) require.NoError(t, err) - b := shares.NewEmptyBuilder().ImportRawShare(dataSquare[1].ToBytes()) - b.FlipSequenceStart() - updatedShare, err := b.Build() + b := dataSquare[1].ToBytes() + // flip the sequence start + b[share.NamespaceSize] ^= 0x01 + updatedShare, err := share.NewShare(b) require.NoError(t, err) dataSquare[1] = *updatedShare - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(share.ToBytes(dataSquare)) require.NoError(t, err) dah, err := da.NewDataAvailabilityHeader(eds) @@ -364,7 +367,7 @@ func TestProcessProposal(t *testing.T) { func calculateNewDataHash(t *testing.T, txs [][]byte) []byte { dataSquare, err := square.Construct(txs, appconsts.DefaultSquareSizeUpperBound, appconsts.DefaultSubtreeRootThreshold) require.NoError(t, err) - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(share.ToBytes(dataSquare)) require.NoError(t, err) dah, err := da.NewDataAvailabilityHeader(eds) require.NoError(t, err) diff --git a/app/validate_txs.go b/app/validate_txs.go index 00e4b7d64e..e3a0557ee7 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -1,7 +1,7 @@ package app import ( - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,12 +11,15 @@ import ( ) // separateTxs decodes raw tendermint txs into normal and blob txs. -func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []*blob.BlobTx) { +func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []*share.BlobTx) { normalTxs := make([][]byte, 0, len(rawTxs)) - blobTxs := make([]*blob.BlobTx, 0, len(rawTxs)) + blobTxs := make([]*share.BlobTx, 0, len(rawTxs)) for _, rawTx := range rawTxs { - bTx, isBlob := blob.UnmarshalBlobTx(rawTx) + bTx, isBlob, err := share.UnmarshalBlobTx(rawTx) if isBlob { + if err != nil { + panic(err) + } blobTxs = append(blobTxs, bTx) } else { normalTxs = append(normalTxs, rawTx) @@ -72,7 +75,7 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler // filterBlobTxs applies the provided antehandler to each transaction // and removes transactions that return an error. Panics are caught by the checkTxValidity // function used to apply the ante handler. -func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []*blob.BlobTx) ([]*blob.BlobTx, sdk.Context) { +func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []*share.BlobTx) ([]*share.BlobTx, sdk.Context) { n := 0 for _, tx := range txs { sdkTx, err := dec(tx.Tx) @@ -108,11 +111,11 @@ func msgTypes(sdkTx sdk.Tx) []string { return msgNames } -func encodeBlobTxs(blobTxs []*blob.BlobTx) [][]byte { +func encodeBlobTxs(blobTxs []*share.BlobTx) [][]byte { txs := make([][]byte, len(blobTxs)) var err error for i, tx := range blobTxs { - txs[i], err = blob.MarshalBlobTx(tx.Tx, tx.Blobs...) + txs[i], err = share.MarshalBlobTx(tx.Tx, tx.Blobs...) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index f00f22ebbc..2756ac0d6f 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/celestiaorg/celestia-app/v3 -go 1.22.4 +go 1.22.5 require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 github.com/celestiaorg/go-square v1.1.0 - github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 + github.com/celestiaorg/go-square/v2 v2.0.0-rc0 github.com/celestiaorg/knuu v0.14.0 github.com/celestiaorg/nmt v0.22.0 github.com/celestiaorg/rsmt2d v0.14.0 diff --git a/go.sum b/go.sum index 65226ef709..4132f2b266 100644 --- a/go.sum +++ b/go.sum @@ -324,8 +324,8 @@ github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16 h1:AlBZS4WykzrwfcNbKD+yQQ github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0= github.com/celestiaorg/go-square v1.1.0 h1:K4tBL5PCJwDtpBfyDxxZ3N962aC9VYb5/bw3LjagEtY= github.com/celestiaorg/go-square v1.1.0/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= -github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 h1:PYInrsYzrDIsZW9Yb86OTi2aEKuPcpgJt6Mc0Jlc/yg= -github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076/go.mod h1:hlidgivKyvv7m4Yl2Fdf2mSTmazZYxX8+bnr5IQrI98= +github.com/celestiaorg/go-square/v2 v2.0.0-rc0 h1:BNV50WdCcDhIhkgbZ3DGeVYuFePZ5Hu6AxjPWX7XVoI= +github.com/celestiaorg/go-square/v2 v2.0.0-rc0/go.mod h1:eeaU8f8jBpk3ZS/gaDZIlTesJR2F51QAmveNzWH6aEU= github.com/celestiaorg/knuu v0.14.0 h1:96uaDHTzlTfhDLrAiygq9Ewow7UzOzGAbUvMwws1S4A= github.com/celestiaorg/knuu v0.14.0/go.mod h1:5x/+tlLebBSfLmmSBm2ps6aLjnKLn5bOaZpUfI5FpsA= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index 65adc27ae1..a7004d0e4d 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -3,7 +3,7 @@ package appconsts import ( "math" - ns "github.com/celestiaorg/go-square/namespace" + ns "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/tendermint/tendermint/pkg/consts" ) diff --git a/pkg/da/data_availability_header.go b/pkg/da/data_availability_header.go index af5e763a7a..421efdaac6 100644 --- a/pkg/da/data_availability_header.go +++ b/pkg/da/data_availability_header.go @@ -6,15 +6,15 @@ import ( "fmt" "math" - "github.com/celestiaorg/go-square/merkle" + "github.com/celestiaorg/go-square/shares" "github.com/celestiaorg/rsmt2d" + "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/types" "golang.org/x/exp/constraints" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" daproto "github.com/celestiaorg/celestia-app/v3/proto/celestia/core/v1/da" - "github.com/celestiaorg/go-square/shares" ) var ( diff --git a/pkg/da/data_availability_header_test.go b/pkg/da/data_availability_header_test.go index 8b1863c408..7bd38addb5 100644 --- a/pkg/da/data_availability_header_test.go +++ b/pkg/da/data_availability_header_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -245,7 +245,7 @@ func TestSquareSize(t *testing.T) { // generateShares generates count number of shares with a constant namespace and // share contents. func generateShares(count int) (shares [][]byte) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) for i := 0; i < count; i++ { share := generateShare(ns1.Bytes()) diff --git a/pkg/inclusion/get_commit.go b/pkg/inclusion/get_commit.go index 5d98d29a98..d000f00d44 100644 --- a/pkg/inclusion/get_commit.go +++ b/pkg/inclusion/get_commit.go @@ -4,7 +4,7 @@ import ( "errors" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/merkle" + "github.com/tendermint/tendermint/crypto/merkle" ) // GetCommitment gets the share commitment for a blob in the original data diff --git a/pkg/inclusion/nmt_caching_test.go b/pkg/inclusion/nmt_caching_test.go index 2191d659f0..80bb19d5b6 100644 --- a/pkg/inclusion/nmt_caching_test.go +++ b/pkg/inclusion/nmt_caching_test.go @@ -8,7 +8,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/rsmt2d" "github.com/stretchr/testify/assert" @@ -21,7 +21,7 @@ func TestWalkCachedSubTreeRoot(t *testing.T) { strc := newSubTreeRootCacher() squareSize := uint64(8) tr := wrapper.NewErasuredNamespacedMerkleTree(squareSize, 0, nmt.NodeVisitor(strc.Visit)) - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) data := append(ns1.Bytes(), []byte("data")...) for i := 0; i < 8; i++ { @@ -191,7 +191,7 @@ func chunkSlice(slice [][]byte, chunkSize int) [][][]byte { func generateRandNamespacedRawData(count int) (result [][]byte) { for i := 0; i < count; i++ { rawData := tmrand.Bytes(appconsts.ShareSize) - namespace := appns.RandomBlobNamespace().Bytes() + namespace := share.RandomBlobNamespace().Bytes() copy(rawData, namespace) result = append(result, rawData) } diff --git a/pkg/inclusion/paths.go b/pkg/inclusion/paths.go index bd14683c28..981658b77c 100644 --- a/pkg/inclusion/paths.go +++ b/pkg/inclusion/paths.go @@ -3,7 +3,7 @@ package inclusion import ( "math" - "github.com/celestiaorg/go-square/inclusion" + "github.com/celestiaorg/go-square/v2/inclusion" ) type path struct { diff --git a/pkg/proof/proof.go b/pkg/proof/proof.go index 06d00a49ce..9a389bf88a 100644 --- a/pkg/proof/proof.go +++ b/pkg/proof/proof.go @@ -11,11 +11,9 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/merkle" - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" + "github.com/tendermint/tendermint/crypto/merkle" ) // NewTxInclusionProof returns a new share inclusion proof for the given @@ -48,12 +46,12 @@ func NewTxInclusionProof(txs [][]byte, txIndex, appVersion uint64) (ShareProof, return NewShareInclusionProof(dataSquare, namespace, shareRange) } -func getTxNamespace(tx []byte) (ns appns.Namespace) { - _, isBlobTx := blob.UnmarshalBlobTx(tx) +func getTxNamespace(tx []byte) (ns share.Namespace) { + _, isBlobTx, _ := share.UnmarshalBlobTx(tx) if isBlobTx { - return appns.PayForBlobNamespace + return share.PayForBlobNamespace } - return appns.TxNamespace + return share.TxNamespace } // NewShareInclusionProof takes an ODS, extends it, then @@ -62,10 +60,10 @@ func getTxNamespace(tx []byte) (ns appns.Namespace) { // Expects the share range to be pre-validated. func NewShareInclusionProof( dataSquare square.Square, - namespace appns.Namespace, - shareRange shares.Range, + namespace share.Namespace, + shareRange share.Range, ) (ShareProof, error) { - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(share.ToBytes(dataSquare)) if err != nil { return ShareProof{}, err } @@ -78,8 +76,8 @@ func NewShareInclusionProof( // Expects the share range to be pre-validated. func NewShareInclusionProofFromEDS( eds *rsmt2d.ExtendedDataSquare, - namespace appns.Namespace, - shareRange shares.Range, + namespace share.Namespace, + shareRange share.Range, ) (ShareProof, error) { squareSize := square.Size(len(eds.FlattenedODS())) startRow := shareRange.Start / squareSize @@ -112,9 +110,9 @@ func NewShareInclusionProofFromEDS( } // get the extended rows containing the shares. - rows := make([][]shares.Share, endRow-startRow+1) + rows := make([][]share.Share, endRow-startRow+1) for i := startRow; i <= endRow; i++ { - shares, err := shares.FromBytes(eds.Row(uint(i))) + shares, err := share.FromBytes(eds.Row(uint(i))) if err != nil { return ShareProof{}, err } @@ -157,7 +155,7 @@ func NewShareInclusionProofFromEDS( endLeafPos = squareSize - 1 } - rawShares = append(rawShares, shares.ToBytes(row[startLeafPos:endLeafPos+1])...) + rawShares = append(rawShares, share.ToBytes(row[startLeafPos:endLeafPos+1])...) proof, err := tree.ProveRange(startLeafPos, endLeafPos+1) if err != nil { return ShareProof{}, err @@ -180,8 +178,8 @@ func NewShareInclusionProofFromEDS( }, Data: rawShares, ShareProofs: shareProofs, - NamespaceId: namespace.ID, - NamespaceVersion: uint32(namespace.Version), + NamespaceId: namespace.ID(), + NamespaceVersion: uint32(namespace.Version()), }, nil } diff --git a/pkg/proof/proof_test.go b/pkg/proof/proof_test.go index f55064702d..6684727c15 100644 --- a/pkg/proof/proof_test.go +++ b/pkg/proof/proof_test.go @@ -15,11 +15,10 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/da" "github.com/celestiaorg/celestia-app/v3/pkg/proof" - "github.com/celestiaorg/go-square/square" + square "github.com/celestiaorg/go-square/v2" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -96,13 +95,13 @@ func TestNewTxInclusionProof(t *testing.T) { } func TestNewShareInclusionProof(t *testing.T) { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - ns2 := appns.MustNewV0(bytes.Repeat([]byte{2}, appns.NamespaceVersionZeroIDSize)) - ns3 := appns.MustNewV0(bytes.Repeat([]byte{3}, appns.NamespaceVersionZeroIDSize)) + ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) + ns2 := share.MustNewV0Namespace(bytes.Repeat([]byte{2}, share.NamespaceVersionZeroIDSize)) + ns3 := share.MustNewV0Namespace(bytes.Repeat([]byte{3}, share.NamespaceVersionZeroIDSize)) signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - blobTxs := blobfactory.RandBlobTxsWithNamespacesAndSigner(signer, []appns.Namespace{ns1, ns2, ns3}, []int{500, 500, 500}) + blobTxs := blobfactory.RandBlobTxsWithNamespacesAndSigner(signer, []share.Namespace{ns1, ns2, ns3}, []int{500, 500, 500}) txs := testfactory.GenerateRandomTxs(50, 500) txs = append(txs, blobTxs...) @@ -112,7 +111,7 @@ func TestNewShareInclusionProof(t *testing.T) { } // erasure the data square which we use to create the data root. - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(share.ToBytes(dataSquare)) require.NoError(t, err) // create the new data root by creating the data availability header (merkle @@ -125,7 +124,7 @@ func TestNewShareInclusionProof(t *testing.T) { name string startingShare int endingShare int - namespaceID appns.Namespace + namespaceID share.Namespace expectErr bool } tests := []test{ @@ -133,70 +132,70 @@ func TestNewShareInclusionProof(t *testing.T) { name: "negative starting share", startingShare: -1, endingShare: 99, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: true, }, { name: "negative ending share", startingShare: 0, endingShare: -99, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: true, }, { name: "ending share lower than starting share", startingShare: 1, endingShare: 0, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: true, }, { name: "ending share is equal to the starting share", startingShare: 1, endingShare: 1, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: true, }, { name: "ending share higher than number of shares available in square size of 32", startingShare: 0, endingShare: 4097, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: true, }, { name: "1 transaction share", startingShare: 0, endingShare: 1, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: false, }, { name: "10 transaction shares", startingShare: 0, endingShare: 10, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: false, }, { name: "53 transaction shares", startingShare: 0, endingShare: 53, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: false, }, { name: "shares from different namespaces", startingShare: 48, endingShare: 55, - namespaceID: appns.TxNamespace, + namespaceID: share.TxNamespace, expectErr: true, }, { name: "shares from PFB namespace", startingShare: 53, endingShare: 55, - namespaceID: appns.PayForBlobNamespace, + namespaceID: share.PayForBlobNamespace, expectErr: false, }, { @@ -227,7 +226,7 @@ func TestNewShareInclusionProof(t *testing.T) { proof, err := proof.NewShareInclusionProof( dataSquare, tt.namespaceID, - shares.NewRange(tt.startingShare, tt.endingShare), + share.NewRange(tt.startingShare, tt.endingShare), ) require.NoError(t, err) assert.NoError(t, proof.Validate(dataRoot)) @@ -246,7 +245,7 @@ func TestAllSharesInclusionProof(t *testing.T) { assert.Equal(t, 256, len(dataSquare)) // erasure the data square which we use to create the data root. - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) + eds, err := da.ExtendShares(share.ToBytes(dataSquare)) require.NoError(t, err) // create the new data root by creating the data availability header (merkle @@ -257,11 +256,11 @@ func TestAllSharesInclusionProof(t *testing.T) { actualNamespace, err := proof.ParseNamespace(dataSquare, 0, 256) require.NoError(t, err) - require.Equal(t, appns.TxNamespace, actualNamespace) + require.Equal(t, share.TxNamespace, actualNamespace) proof, err := proof.NewShareInclusionProof( dataSquare, - appns.TxNamespace, - shares.NewRange(0, 256), + share.TxNamespace, + share.NewRange(0, 256), ) require.NoError(t, err) assert.NoError(t, proof.Validate(dataRoot)) diff --git a/pkg/proof/querier.go b/pkg/proof/querier.go index 46a9124124..8b306add7c 100644 --- a/pkg/proof/querier.go +++ b/pkg/proof/querier.go @@ -7,10 +7,9 @@ import ( "strconv" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" - appns "github.com/celestiaorg/go-square/namespace" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -113,7 +112,7 @@ func QueryShareInclusionProof(_ sdk.Context, path []string, req abci.RequestQuer return nil, err } - shareRange := shares.NewRange(begin, end) + shareRange := share.NewRange(begin, end) // create and marshal the share inclusion proof, which we return in the form of []byte shareProof, err := NewShareInclusionProof(dataSquare, nID, shareRange) if err != nil { @@ -131,35 +130,28 @@ func QueryShareInclusionProof(_ sdk.Context, path []string, req abci.RequestQuer // ParseNamespace validates the share range, checks if it only contains one namespace and returns // that namespace ID. // The provided range, defined by startShare and endShare, is end-exclusive. -func ParseNamespace(rawShares []shares.Share, startShare int, endShare int) (appns.Namespace, error) { +func ParseNamespace(rawShares []share.Share, startShare int, endShare int) (share.Namespace, error) { if startShare < 0 { - return appns.Namespace{}, fmt.Errorf("start share %d should be positive", startShare) + return share.Namespace{}, fmt.Errorf("start share %d should be positive", startShare) } if endShare < 0 { - return appns.Namespace{}, fmt.Errorf("end share %d should be positive", endShare) + return share.Namespace{}, fmt.Errorf("end share %d should be positive", endShare) } if endShare <= startShare { - return appns.Namespace{}, fmt.Errorf("end share %d cannot be lower or equal to the starting share %d", endShare, startShare) + return share.Namespace{}, fmt.Errorf("end share %d cannot be lower or equal to the starting share %d", endShare, startShare) } if endShare > len(rawShares) { - return appns.Namespace{}, fmt.Errorf("end share %d is higher than block shares %d", endShare, len(rawShares)) + return share.Namespace{}, fmt.Errorf("end share %d is higher than block shares %d", endShare, len(rawShares)) } - startShareNs, err := rawShares[startShare].Namespace() - if err != nil { - return appns.Namespace{}, err - } - - for i, share := range rawShares[startShare:endShare] { - ns, err := share.Namespace() - if err != nil { - return appns.Namespace{}, err - } + startShareNs := rawShares[startShare].Namespace() + for i, sh := range rawShares[startShare:endShare] { + ns := sh.Namespace() if !bytes.Equal(startShareNs.Bytes(), ns.Bytes()) { - return appns.Namespace{}, fmt.Errorf("shares range contain different namespaces at index %d: %v and %v ", i, startShareNs, ns) + return share.Namespace{}, fmt.Errorf("shares range contain different namespaces at index %d: %v and %v ", i, startShareNs, ns) } } return startShareNs, nil diff --git a/pkg/proof/row_proof.go b/pkg/proof/row_proof.go index e3e02798e9..f3c63b6a7e 100644 --- a/pkg/proof/row_proof.go +++ b/pkg/proof/row_proof.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/merkle" + "github.com/tendermint/tendermint/crypto/merkle" ) // Validate performs checks on the fields of this RowProof. Returns an error if diff --git a/pkg/user/e2e_test.go b/pkg/user/e2e_test.go index 2cd506aa69..e42710c22f 100644 --- a/pkg/user/e2e_test.go +++ b/pkg/user/e2e_test.go @@ -11,7 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" ) @@ -47,9 +47,9 @@ func TestConcurrentTxSubmission(t *testing.T) { time.AfterFunc(time.Minute, cancel) for i := 0; i < numTxs; i++ { wg.Add(1) - go func(b *blob.Blob) { + go func(b *share.Blob) { defer wg.Done() - _, err := txClient.SubmitPayForBlob(subCtx, []*blob.Blob{b}, user.SetGasLimitAndGasPrice(500_000, appconsts.DefaultMinGasPrice)) + _, err := txClient.SubmitPayForBlob(subCtx, []*share.Blob{b}, user.SetGasLimitAndGasPrice(500_000, appconsts.DefaultMinGasPrice)) if err != nil && !errors.Is(err, context.Canceled) { // only catch the first error select { diff --git a/pkg/user/signer.go b/pkg/user/signer.go index ecb1673733..4670f079aa 100644 --- a/pkg/user/signer.go +++ b/pkg/user/signer.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" - "github.com/celestiaorg/go-square/blob" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -13,6 +12,7 @@ import ( authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" + "github.com/celestiaorg/go-square/v2/share" ) // Signer is struct for building and signing Celestia transactions @@ -85,7 +85,7 @@ func (s *Signer) SignTx(msgs []sdktypes.Msg, opts ...TxOption) (authsigning.Tx, return txBuilder.GetTx(), signer, sequence, nil } -func (s *Signer) CreatePayForBlobs(accountName string, blobs []*blob.Blob, opts ...TxOption) ([]byte, uint64, error) { +func (s *Signer) CreatePayForBlobs(accountName string, blobs []*share.Blob, opts ...TxOption) ([]byte, uint64, error) { acc, exists := s.accounts[accountName] if !exists { return nil, 0, fmt.Errorf("account %s not found", accountName) @@ -106,7 +106,7 @@ func (s *Signer) CreatePayForBlobs(accountName string, blobs []*blob.Blob, opts return nil, 0, err } - blobTx, err := blob.MarshalBlobTx(txBytes, blobs...) + blobTx, err := share.MarshalBlobTx(txBytes, blobs...) return blobTx, sequence, err } diff --git a/pkg/user/tx_client.go b/pkg/user/tx_client.go index caaed72f82..77eaa06271 100644 --- a/pkg/user/tx_client.go +++ b/pkg/user/tx_client.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -199,7 +199,7 @@ func SetupTxClient( // SubmitPayForBlob forms a transaction from the provided blobs, signs it, and submits it to the chain. // TxOptions may be provided to set the fee and gas limit. -func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*blob.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { +func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { resp, err := client.BroadcastPayForBlob(ctx, blobs, opts...) if err != nil { return resp, err @@ -208,7 +208,7 @@ func (client *TxClient) SubmitPayForBlob(ctx context.Context, blobs []*blob.Blob return client.ConfirmTx(ctx, resp.TxHash) } -func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account string, blobs []*blob.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { +func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account string, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { resp, err := client.BroadcastPayForBlobWithAccount(ctx, account, blobs, opts...) if err != nil { return resp, err @@ -221,11 +221,11 @@ func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account // It does not confirm that the transaction has been committed on chain. // If no gas or gas price is set, it will estimate the gas and use // the max effective gas price: max(localMinGasPrice, networkMinGasPrice). -func (client *TxClient) BroadcastPayForBlob(ctx context.Context, blobs []*blob.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { +func (client *TxClient) BroadcastPayForBlob(ctx context.Context, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { return client.BroadcastPayForBlobWithAccount(ctx, client.defaultAccount, blobs, opts...) } -func (client *TxClient) BroadcastPayForBlobWithAccount(ctx context.Context, account string, blobs []*blob.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { +func (client *TxClient) BroadcastPayForBlobWithAccount(ctx context.Context, account string, blobs []*share.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) { client.mtx.Lock() defer client.mtx.Unlock() if err := client.checkAccountLoaded(ctx, account); err != nil { @@ -234,7 +234,7 @@ func (client *TxClient) BroadcastPayForBlobWithAccount(ctx context.Context, acco blobSizes := make([]uint32, len(blobs)) for i, blob := range blobs { - blobSizes[i] = uint32(len(blob.Data)) + blobSizes[i] = uint32(len(blob.Data())) } gasLimit := uint64(float64(types.DefaultEstimateGas(blobSizes)) * client.gasMultiplier) @@ -355,8 +355,12 @@ func (client *TxClient) broadcastTx(ctx context.Context, txBytes []byte, signer // retryBroadcastingTx creates a new transaction by copying over an existing transaction but creates a new signature with the // new sequence number. It then calls `broadcastTx` and attempts to submit the transaction func (client *TxClient) retryBroadcastingTx(ctx context.Context, txBytes []byte) (*sdktypes.TxResponse, error) { - blobTx, isBlobTx := blob.UnmarshalBlobTx(txBytes) + blobTx, isBlobTx, err := share.UnmarshalBlobTx(txBytes) if isBlobTx { + // only check the error if the bytes are supposed to be of type blob tx + if err != nil { + return nil, err + } txBytes = blobTx.Tx } tx, err := client.signer.DecodeTx(txBytes) @@ -397,7 +401,7 @@ func (client *TxClient) retryBroadcastingTx(ctx context.Context, txBytes []byte) // rewrap the blob tx if it was originally a blob tx if isBlobTx { - newTxBytes, err = blob.MarshalBlobTx(newTxBytes, blobTx.Blobs...) + newTxBytes, err = share.MarshalBlobTx(newTxBytes, blobTx.Blobs...) if err != nil { return nil, err } diff --git a/pkg/wrapper/nmt_wrapper.go b/pkg/wrapper/nmt_wrapper.go index ad0cdf2a48..82ad3ad94b 100644 --- a/pkg/wrapper/nmt_wrapper.go +++ b/pkg/wrapper/nmt_wrapper.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - appns "github.com/celestiaorg/go-square/namespace" + appns "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" diff --git a/pkg/wrapper/nmt_wrapper_test.go b/pkg/wrapper/nmt_wrapper_test.go index 92c9cb8e11..ea807fe90f 100644 --- a/pkg/wrapper/nmt_wrapper_test.go +++ b/pkg/wrapper/nmt_wrapper_test.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - appns "github.com/celestiaorg/go-square/namespace" + appns "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmtnamespace "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" diff --git a/proto/celestia/core/v1/blob/blob.proto b/proto/celestia/core/v1/blob/blob.proto index 45ece976ed..b4d67d04ec 100644 --- a/proto/celestia/core/v1/blob/blob.proto +++ b/proto/celestia/core/v1/blob/blob.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package celestia.core.v1.blob; -option go_package = "github.com/celestiaorg/go-square/blob"; +option go_package = "github.com/celestiaorg/go-square/v2/share"; // Blob (named after binary large object) is a chunk of data submitted by a user // to be published to the Celestia blockchain. The data of a Blob is published diff --git a/specs/src/specs/namespace.md b/specs/src/specs/namespace.md index 7423c91b53..c035bee215 100644 --- a/specs/src/specs/namespace.md +++ b/specs/src/specs/namespace.md @@ -94,8 +94,8 @@ Among the potential consequences is the _Woods Attack_, as elaborated in this fo ## Implementation -See the [namespace implementation in go-square](https://github.com/celestiaorg/go-square/blob/be3c2801e902a0f90f694c062b9c4e6a7e01154e/namespace/namespace.go). -For the most recent version, which may not reflect the current specifications, refer to [the latest namespace code](https://github.com/celestiaorg/go-square/blob/main/share/namespace.go). +See the [namespace implementation in go-square](https://github.com/celestiaorg/go-square/v2/share/be3c2801e902a0f90f694c062b9c4e6a7e01154e/namespace/namespace.go). +For the most recent version, which may not reflect the current specifications, refer to [the latest namespace code](https://github.com/celestiaorg/go-square/v2/share/main/share/namespace.go). ## Go Definition diff --git a/specs/src/specs/shares.md b/specs/src/specs/shares.md index ee469f25f7..f3139596e3 100644 --- a/specs/src/specs/shares.md +++ b/specs/src/specs/shares.md @@ -112,7 +112,7 @@ Share splitting is the process of converting a blob into a share sequence. The p ## Implementation -See [go-square/shares](https://github.com/celestiaorg/go-square/tree/be3c2801e902a0f90f694c062b9c4e6a7e01154e/shares). +See [go-square/shares](https://github.com/celestiaorg/go-square/v2/tree/be3c2801e902a0f90f694c062b9c4e6a7e01154e/shares). ## References diff --git a/test/txsim/account.go b/test/txsim/account.go index ac3eee2797..e01264c68d 100644 --- a/test/txsim/account.go +++ b/test/txsim/account.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/user" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -292,10 +292,10 @@ func (am *AccountManager) Submit(ctx context.Context, op Operation) error { return nil } -func getSize(blobs []*blob.Blob) int64 { +func getSize(blobs []*share.Blob) int64 { size := int64(0) for _, blob := range blobs { - size += int64(len(blob.GetData())) + size += int64(len(blob.Data())) } return size } diff --git a/test/txsim/blob.go b/test/txsim/blob.go index 88f0570a85..f6dc432be7 100644 --- a/test/txsim/blob.go +++ b/test/txsim/blob.go @@ -8,7 +8,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" - ns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/types" "github.com/gogo/protobuf/grpc" ) @@ -21,7 +21,7 @@ const fundsForGas int = 1e9 // 1000 TIA // BlobSequence defines a pattern whereby a single user repeatedly sends a pay for blob // message roughly every height. The PFB may consist of several blobs type BlobSequence struct { - namespace ns.Namespace + namespace share.Namespace sizes Range blobsPerPFB Range @@ -38,7 +38,7 @@ func NewBlobSequence(sizes, blobsPerPFB Range) *BlobSequence { // WithNamespace provides the option of fixing a predefined namespace for // all blobs. -func (s *BlobSequence) WithNamespace(namespace ns.Namespace) *BlobSequence { +func (s *BlobSequence) WithNamespace(namespace share.Namespace) *BlobSequence { s.namespace = namespace return s } @@ -67,18 +67,18 @@ func (s *BlobSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccoun func (s *BlobSequence) Next(_ context.Context, _ grpc.ClientConn, rand *rand.Rand) (Operation, error) { numBlobs := s.blobsPerPFB.Rand(rand) sizes := make([]int, numBlobs) - namespaces := make([]ns.Namespace, numBlobs) + namespaces := make([]share.Namespace, numBlobs) for i := range sizes { - if s.namespace.ID != nil { + if s.namespace.ID() != nil { namespaces[i] = s.namespace } else { // generate a random namespace for the blob - namespace := make([]byte, ns.NamespaceVersionZeroIDSize) + namespace := make([]byte, share.NamespaceVersionZeroIDSize) _, err := rand.Read(namespace) if err != nil { return Operation{}, fmt.Errorf("generating random namespace: %w", err) } - namespaces[i] = ns.MustNewV0(namespace) + namespaces[i] = share.MustNewV0Namespace(namespace) } sizes[i] = s.sizes.Rand(rand) } diff --git a/test/txsim/sequence.go b/test/txsim/sequence.go index d1ac8eea13..7c7459eaad 100644 --- a/test/txsim/sequence.go +++ b/test/txsim/sequence.go @@ -5,7 +5,7 @@ import ( "errors" "math/rand" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/types" "github.com/gogo/protobuf/grpc" ) @@ -35,7 +35,7 @@ type Sequence interface { // The gas limit and price can also be set. If left at 0, the DefaultGasLimit will be used. type Operation struct { Msgs []types.Msg - Blobs []*blob.Blob + Blobs []*share.Blob Delay uint64 GasLimit uint64 GasPrice float64 diff --git a/test/util/blobfactory/payforblob_factory.go b/test/util/blobfactory/payforblob_factory.go index 0f4583ef46..c405c3ba75 100644 --- a/test/util/blobfactory/payforblob_factory.go +++ b/test/util/blobfactory/payforblob_factory.go @@ -10,8 +10,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" @@ -28,8 +27,8 @@ var ( TestMaxBlobCount = 5 ) -func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCount int) (*blobtypes.MsgPayForBlobs, []*blob.Blob) { - blobs := make([]*blob.Blob, blobCount) +func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCount int) (*blobtypes.MsgPayForBlobs, []*share.Blob) { + blobs := make([]*share.Blob, blobCount) for i := 0; i < blobCount; i++ { blob, err := blobtypes.NewBlob(testfactory.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero) if err != nil { @@ -45,15 +44,19 @@ func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCo return msg, blobs } -func RandBlobsWithNamespace(namespaces []appns.Namespace, sizes []int) []*blob.Blob { - blobs := make([]*blob.Blob, len(namespaces)) +func RandBlobsWithNamespace(namespaces []share.Namespace, sizes []int) []*share.Blob { + blobs := make([]*share.Blob, len(namespaces)) + var err error for i, ns := range namespaces { - blobs[i] = blob.New(ns, tmrand.Bytes(sizes[i]), appconsts.ShareVersionZero) + blobs[i], err = share.NewBlob(ns, tmrand.Bytes(sizes[i]), appconsts.ShareVersionZero, nil) + if err != nil { + panic(err) + } } return blobs } -func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns appns.Namespace, size int) (*blobtypes.MsgPayForBlobs, *blob.Blob) { +func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns share.Namespace, size int) (*blobtypes.MsgPayForBlobs, *share.Blob) { blob, err := blobtypes.NewBlob(ns, tmrand.Bytes(size), appconsts.ShareVersionZero) if err != nil { panic(err) @@ -69,8 +72,11 @@ func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns appns.Namespace, return msg, blob } -func RandMsgPayForBlobs(rand *tmrand.Rand, size int) (*blobtypes.MsgPayForBlobs, *blob.Blob) { - blob := blob.New(testfactory.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero) +func RandMsgPayForBlobs(rand *tmrand.Rand, size int) (*blobtypes.MsgPayForBlobs, *share.Blob) { + blob, err := share.NewBlob(testfactory.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero, nil) + if err != nil { + panic(err) + } msg, err := blobtypes.NewMsgPayForBlobs( testfactory.TestAccAddr, appconsts.LatestVersion, @@ -180,7 +186,7 @@ func RandBlobTxs(signer *user.Signer, rand *tmrand.Rand, count, blobsPerTx, size return txs } -func ManyRandBlobs(rand *tmrand.Rand, sizes ...int) []*blob.Blob { +func ManyRandBlobs(rand *tmrand.Rand, sizes ...int) []*share.Blob { return ManyBlobs(rand, testfactory.RandomBlobNamespaces(rand, len(sizes)), sizes) } @@ -192,16 +198,20 @@ func Repeat[T any](s T, count int) []T { return ss } -func ManyBlobs(rand *tmrand.Rand, namespaces []appns.Namespace, sizes []int) []*blob.Blob { - blobs := make([]*blob.Blob, len(namespaces)) +func ManyBlobs(rand *tmrand.Rand, namespaces []share.Namespace, sizes []int) []*share.Blob { + blobs := make([]*share.Blob, len(namespaces)) for i, ns := range namespaces { - blobs[i] = blob.New(ns, rand.Bytes(sizes[i]), appconsts.ShareVersionZero) + blob, err := share.NewBlob(ns, rand.Bytes(sizes[i]), appconsts.ShareVersionZero, nil) + if err != nil { + panic(err) + } + blobs[i] = blob } return blobs } -func NestedBlobs(t *testing.T, namespaces []appns.Namespace, sizes [][]int) [][]*blob.Blob { - blobs := make([][]*blob.Blob, len(sizes)) +func NestedBlobs(t *testing.T, namespaces []share.Namespace, sizes [][]int) [][]*share.Blob { + blobs := make([][]*share.Blob, len(sizes)) counter := 0 for i, set := range sizes { for _, size := range set { @@ -221,7 +231,7 @@ func ManyMultiBlobTx( chainid string, accounts []string, accInfos []AccountInfo, - blobs [][]*blob.Blob, + blobs [][]*share.Blob, ) [][]byte { t.Helper() txs := make([][]byte, len(accounts)) @@ -242,7 +252,7 @@ func IndexWrappedTxWithInvalidNamespace( rand *tmrand.Rand, signer *user.Signer, index uint32, -) (coretypes.Tx, *blob.Blob) { +) (coretypes.Tx, *share.Blob) { t.Helper() blob := ManyRandBlobs(rand, 100)[0] acc := signer.Accounts()[0] @@ -264,7 +274,7 @@ func IndexWrappedTxWithInvalidNamespace( func RandBlobTxsWithNamespacesAndSigner( signer *user.Signer, - namespaces []appns.Namespace, + namespaces []share.Namespace, sizes []int, ) []coretypes.Tx { txs := make([]coretypes.Tx, len(namespaces)) @@ -272,7 +282,7 @@ func RandBlobTxsWithNamespacesAndSigner( // take the first account the signer has acc := signer.Accounts()[0] _, b := RandMsgPayForBlobsWithNamespaceAndSigner(acc.Address().String(), namespaces[i], sizes[i]) - cTx, _, err := signer.CreatePayForBlobs(acc.Name(), []*blob.Blob{b}, DefaultTxOpts()...) + cTx, _, err := signer.CreatePayForBlobs(acc.Name(), []*share.Blob{b}, DefaultTxOpts()...) if err != nil { panic(err) } @@ -294,7 +304,7 @@ func ComplexBlobTxWithOtherMsgs(t *testing.T, rand *tmrand.Rand, signer *user.Si require.NoError(t, err) - btx, err := blob.MarshalBlobTx(rawTx, blobs...) + btx, err := share.MarshalBlobTx(rawTx, blobs...) require.NoError(t, err) return btx } diff --git a/test/util/direct_tx_gen.go b/test/util/direct_tx_gen.go index 87372e7f5d..017359360e 100644 --- a/test/util/direct_tx_gen.go +++ b/test/util/direct_tx_gen.go @@ -11,7 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" @@ -146,7 +146,7 @@ func RandBlobTxsWithManualSequence( require.NoError(t, err) } - cTx, err := blob.MarshalBlobTx(tx, blobs...) + cTx, err := share.MarshalBlobTx(tx, blobs...) if err != nil { panic(err) } diff --git a/test/util/malicious/app_test.go b/test/util/malicious/app_test.go index 5aee076304..eae4512a90 100644 --- a/test/util/malicious/app_test.go +++ b/test/util/malicious/app_test.go @@ -9,8 +9,8 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + square "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmrand "github.com/tendermint/tendermint/libs/rand" @@ -95,7 +95,7 @@ func TestMaliciousTestNode(t *testing.T) { s, err := Construct(block.Block.Txs.ToSliceOfBytes(), appconsts.LatestVersion, appconsts.DefaultSquareSizeUpperBound, OutOfOrderExport) require.NoError(t, err) - rawSquare := shares.ToBytes(s) + rawSquare := share.ToBytes(s) eds, err := ExtendShares(rawSquare) require.NoError(t, err) @@ -109,7 +109,7 @@ func TestMaliciousTestNode(t *testing.T) { ) require.NoError(t, err) - goodEds, err := da.ExtendShares(shares.ToBytes(correctSquare)) + goodEds, err := da.ExtendShares(share.ToBytes(correctSquare)) require.NoError(t, err) goodDah, err := da.NewDataAvailabilityHeader(goodEds) diff --git a/test/util/malicious/out_of_order_builder.go b/test/util/malicious/out_of_order_builder.go index 6f98c1e4a2..afad4aca45 100644 --- a/test/util/malicious/out_of_order_builder.go +++ b/test/util/malicious/out_of_order_builder.go @@ -6,11 +6,9 @@ import ( "sort" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" - "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "google.golang.org/protobuf/proto" ) @@ -28,16 +26,17 @@ func Build(txs [][]byte, appVersion uint64, maxSquareSize int, efn ExportFn) (sq } normalTxs := make([][]byte, 0, len(txs)) blobTxs := make([][]byte, 0, len(txs)) - for _, tx := range txs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(tx) + for idx, tx := range txs { + blobTx, isBlobTx, err := share.UnmarshalBlobTx(tx) if isBlobTx { + if err != nil { + return nil, nil, fmt.Errorf("unmarshaling blob tx %d: %w", idx, err) + } if builder.AppendBlobTx(blobTx) { blobTxs = append(blobTxs, tx) } - } else { - if builder.AppendTx(tx) { - normalTxs = append(normalTxs, tx) - } + } else if builder.AppendTx(tx) { + normalTxs = append(normalTxs, tx) } } // note that this is using the malicious Export function @@ -89,7 +88,7 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) { } // write all the regular transactions into compact shares - txWriter := shares.NewCompactShareSplitter(namespace.TxNamespace, appconsts.ShareVersionZero) + txWriter := share.NewCompactShareSplitter(share.TxNamespace, appconsts.ShareVersionZero) for _, tx := range b.Txs { if err := txWriter.WriteTx(tx); err != nil { return nil, fmt.Errorf("writing tx into compact shares: %w", err) @@ -100,7 +99,7 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) { nonReservedStart := b.TxCounter.Size() + b.PfbCounter.Size() cursor := nonReservedStart endOfLastBlob := nonReservedStart - blobWriter := shares.NewSparseShareSplitter() + blobWriter := share.NewSparseShareSplitter() for i, element := range b.Blobs { // NextShareIndex returned where the next blob should start so as to comply with the share commitment rules // We fill out the remaining @@ -135,7 +134,7 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) { // write all the pay for blob transactions into compact shares. We need to do this after allocating the blobs to their // appropriate shares as the starting index of each blob needs to be included in the PFB transaction - pfbWriter := shares.NewCompactShareSplitter(namespace.PayForBlobNamespace, appconsts.ShareVersionZero) + pfbWriter := share.NewCompactShareSplitter(share.PayForBlobNamespace, appconsts.ShareVersionZero) for _, iw := range b.Pfbs { iwBytes, err := proto.Marshal(iw) if err != nil { diff --git a/test/util/malicious/out_of_order_prepare.go b/test/util/malicious/out_of_order_prepare.go index 50ea5660da..fa4bdb89ec 100644 --- a/test/util/malicious/out_of_order_prepare.go +++ b/test/util/malicious/out_of_order_prepare.go @@ -4,7 +4,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/ante" "github.com/celestiaorg/celestia-app/v3/pkg/da" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" abci "github.com/tendermint/tendermint/abci/types" core "github.com/tendermint/tendermint/proto/tendermint/types" version "github.com/tendermint/tendermint/proto/tendermint/version" @@ -54,7 +54,7 @@ func (a *App) OutOfOrderPrepareProposal(req abci.RequestPrepareProposal) abci.Re // erasure the data square which we use to create the data root. Note: this // is using a modified version of nmt where the order of the namepspaces is // not enforced. - eds, err := ExtendShares(shares.ToBytes(dataSquare)) + eds, err := ExtendShares(share.ToBytes(dataSquare)) if err != nil { a.Logger().Error( "failure to erasure the data square while creating a proposal block", diff --git a/test/util/malicious/tree.go b/test/util/malicious/tree.go index cb2c4528ca..4a1107e144 100644 --- a/test/util/malicious/tree.go +++ b/test/util/malicious/tree.go @@ -5,8 +5,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" - "github.com/celestiaorg/go-square/shares" - "github.com/celestiaorg/go-square/square" + "github.com/celestiaorg/go-square/v2" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" @@ -60,7 +59,7 @@ func (c constructor) NewTree(_ rsmt2d.Axis, axisIndex uint) rsmt2d.Tree { func ExtendShares(s [][]byte) (*rsmt2d.ExtendedDataSquare, error) { // Check that the length of the square is a power of 2. - if !shares.IsPowerOfTwo(len(s)) { + if !square.IsPowerOfTwo(len(s)) { return nil, fmt.Errorf("number of shares is not a power of 2: got %d", len(s)) } squareSize := square.Size(len(s)) diff --git a/test/util/testfactory/blob.go b/test/util/testfactory/blob.go index ddbf9c5edc..52b452562a 100644 --- a/test/util/testfactory/blob.go +++ b/test/util/testfactory/blob.go @@ -5,17 +5,15 @@ import ( "encoding/binary" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/tendermint/tendermint/types" ) -func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*blob.Blob { - blobs := make([]*blob.Blob, count) +func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*share.Blob { + blobs := make([]*share.Blob, count) for i := 0; i < count; i++ { blobs[i] = GenerateRandomBlob(tmrand.Intn(maxBlobSize)) - if len(blobs[i].Data) == 0 { + if len(blobs[i].Data()) == 0 { i-- } } @@ -25,20 +23,19 @@ func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*blob.Blob { blobs = nil } - blob.Sort(blobs) + share.SortBlobs(blobs) return blobs } -// GenerateBlobsWithNamespace generates blobs with namespace ns. -func GenerateBlobsWithNamespace(count int, blobSize int, ns appns.Namespace) []types.Blob { - blobs := make([]types.Blob, count) +// GenerateBlobsWithNamespace generates blobs with namespace share. +func GenerateBlobsWithNamespace(count int, blobSize int, ns share.Namespace) []*share.Blob { + blobs := make([]*share.Blob, count) for i := 0; i < count; i++ { - blobs[i] = types.Blob{ - NamespaceVersion: ns.Version, - NamespaceID: ns.ID, - Data: tmrand.Bytes(blobSize), - ShareVersion: appconsts.ShareVersionZero, + blob, err := share.NewBlob(ns, tmrand.Bytes(blobSize), appconsts.ShareVersionZero, nil) + if err != nil { + panic(err) } + blobs[i] = blob } // this is just to let us use assert.Equal @@ -49,14 +46,18 @@ func GenerateBlobsWithNamespace(count int, blobSize int, ns appns.Namespace) []t return blobs } -func GenerateRandomBlob(dataSize int) *blob.Blob { - ns := appns.MustNewV0(bytes.Repeat([]byte{0x1}, appns.NamespaceVersionZeroIDSize)) - return blob.New(ns, tmrand.Bytes(dataSize), appconsts.ShareVersionZero) +func GenerateRandomBlob(dataSize int) *share.Blob { + ns := share.MustNewV0Namespace(bytes.Repeat([]byte{0x1}, share.NamespaceVersionZeroIDSize)) + blob, err := share.NewBlob(ns, tmrand.Bytes(dataSize), appconsts.ShareVersionZero, nil) + if err != nil { + panic(err) + } + return blob } // GenerateRandomBlobOfShareCount returns a blob that spans the given // number of shares -func GenerateRandomBlobOfShareCount(count int) *blob.Blob { +func GenerateRandomBlobOfShareCount(count int) *share.Blob { size := rawBlobSize(appconsts.FirstSparseShareContentSize * count) return GenerateRandomBlob(size) } diff --git a/test/util/testfactory/common.go b/test/util/testfactory/common.go index 9f9ea65fc9..f37d4e4439 100644 --- a/test/util/testfactory/common.go +++ b/test/util/testfactory/common.go @@ -5,7 +5,7 @@ import ( "sort" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -36,7 +36,7 @@ func Repeat[T any](s T, count int) []T { func GenerateRandNamespacedRawData(count int) (result [][]byte) { for i := 0; i < count; i++ { rawData := tmrand.Bytes(appconsts.ShareSize) - namespace := namespace.RandomBlobNamespace().Bytes() + namespace := share.RandomBlobNamespace().Bytes() copy(rawData, namespace) result = append(result, rawData) } diff --git a/test/util/testfactory/namespace.go b/test/util/testfactory/namespace.go index d04cdf2ec4..147cc298dd 100644 --- a/test/util/testfactory/namespace.go +++ b/test/util/testfactory/namespace.go @@ -3,31 +3,31 @@ package testfactory import ( "slices" - ns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" tmrand "github.com/tendermint/tendermint/libs/rand" ) // RandomBlobNamespaceIDWithPRG returns a random blob namespace ID using the supplied Pseudo-Random number Generator (PRG). func RandomBlobNamespaceIDWithPRG(prg *tmrand.Rand) []byte { - return prg.Bytes(ns.NamespaceVersionZeroIDSize) + return prg.Bytes(share.NamespaceVersionZeroIDSize) } -func RandomBlobNamespace() ns.Namespace { +func RandomBlobNamespace() share.Namespace { return RandomBlobNamespaceWithPRG(tmrand.NewRand()) } // RandomBlobNamespaceWithPRG generates and returns a random blob namespace using the supplied Pseudo-Random number Generator (PRG). -func RandomBlobNamespaceWithPRG(prg *tmrand.Rand) ns.Namespace { +func RandomBlobNamespaceWithPRG(prg *tmrand.Rand) share.Namespace { for { id := RandomBlobNamespaceIDWithPRG(prg) - namespace := ns.MustNewV0(id) + namespace := share.MustNewV0Namespace(id) if isBlobNamespace(namespace) { return namespace } } } -func RandomBlobNamespaces(rand *tmrand.Rand, count int) (namespaces []ns.Namespace) { +func RandomBlobNamespaces(rand *tmrand.Rand, count int) (namespaces []share.Namespace) { for i := 0; i < count; i++ { namespaces = append(namespaces, RandomBlobNamespaceWithPRG(rand)) } @@ -36,12 +36,12 @@ func RandomBlobNamespaces(rand *tmrand.Rand, count int) (namespaces []ns.Namespa // isBlobNamespace returns an true if this namespace is a valid user-specifiable // blob namespace. -func isBlobNamespace(namespace ns.Namespace) bool { +func isBlobNamespace(namespace share.Namespace) bool { if namespace.IsReserved() { return false } - if !slices.Contains(ns.SupportedBlobNamespaceVersions, namespace.Version) { + if !slices.Contains(share.SupportedBlobNamespaceVersions, namespace.Version()) { return false } diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index 68d4328330..5a62602b65 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -11,7 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/test/util/genesis" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - appns "github.com/celestiaorg/go-square/namespace" + appns "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" diff --git a/test/util/testnode/node_interaction_api.go b/test/util/testnode/node_interaction_api.go index 2d44015d1f..4a041503e4 100644 --- a/test/util/testnode/node_interaction_api.go +++ b/test/util/testnode/node_interaction_api.go @@ -13,9 +13,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -222,7 +220,7 @@ func (c *Context) WaitForTx(hashHexStr string, blocks int) (*rpctypes.ResultTx, // PostData will create and submit PFB transaction containing the namespace and // blobData. This function blocks until the PFB has been included in a block and // returns an error if the transaction is invalid or is rejected by the mempool. -func (c *Context) PostData(account, broadcastMode string, ns appns.Namespace, blobData []byte) (*sdk.TxResponse, error) { +func (c *Context) PostData(account, broadcastMode string, ns share.Namespace, blobData []byte) (*sdk.TxResponse, error) { rec, err := c.Keyring.Key(account) if err != nil { return nil, err @@ -252,7 +250,7 @@ func (c *Context) PostData(account, broadcastMode string, ns appns.Namespace, bl gas := types.DefaultEstimateGas([]uint32{uint32(len(blobData))}) opts := blobfactory.FeeTxOpts(gas) - blobTx, _, err := signer.CreatePayForBlobs(account, []*blob.Blob{b}, opts...) + blobTx, _, err := signer.CreatePayForBlobs(account, []*share.Blob{b}, opts...) if err != nil { return nil, err } @@ -297,8 +295,8 @@ func (c *Context) FillBlock(squareSize int, account string, broadcastMode string shareCount := (squareSize - 1) * squareSize // we use a formula to guarantee that the tx is the exact size needed to force a specific square size. - blobSize := shares.AvailableBytesFromSparseShares(shareCount) - return c.PostData(account, broadcastMode, appns.RandomBlobNamespace(), tmrand.Bytes(blobSize)) + blobSize := share.AvailableBytesFromSparseShares(shareCount) + return c.PostData(account, broadcastMode, share.RandomBlobNamespace(), tmrand.Bytes(blobSize)) } // HeightForTimestamp returns the block height for the first block after a diff --git a/test/util/testnode/read.go b/test/util/testnode/read.go index 6363b2195a..a5d0e2d46f 100644 --- a/test/util/testnode/read.go +++ b/test/util/testnode/read.go @@ -6,7 +6,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/rpc/client/http" "github.com/tendermint/tendermint/types" @@ -117,8 +117,11 @@ func DecodeBlockData(data types.Data) ([]sdk.Tx, error) { decoder := encCfg.TxConfig.TxDecoder() txs := make([]sdk.Tx, 0) for _, txBytes := range data.Txs { - blobTx, isBlobTx := blob.UnmarshalBlobTx(txBytes) + blobTx, isBlobTx, err := share.UnmarshalBlobTx(txBytes) if isBlobTx { + if err != nil { + return nil, fmt.Errorf("decoding blob tx: %w", err) + } txBytes = blobTx.Tx } tx, err := decoder(txBytes) diff --git a/x/blob/ante/ante_test.go b/x/blob/ante/ante_test.go index 0f7bf39b02..c5fefd3d93 100644 --- a/x/blob/ante/ante_test.go +++ b/x/blob/ante/ante_test.go @@ -8,7 +8,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" ante "github.com/celestiaorg/celestia-app/v3/x/blob/ante" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) @@ -31,7 +31,7 @@ func TestPFBAnteHandler(t *testing.T) { name: "valid pfb single blob", pfb: &blob.MsgPayForBlobs{ // 1 share = 512 bytes = 5120 gas - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(1))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1))}, }, txGas: appconsts.ShareSize * testGasPerBlobByte, gasConsumed: 0, @@ -40,7 +40,7 @@ func TestPFBAnteHandler(t *testing.T) { { name: "valid pfb multi blob", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(1)), uint32(shares.AvailableBytesFromSparseShares(2))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1)), uint32(share.AvailableBytesFromSparseShares(2))}, }, txGas: 3 * appconsts.ShareSize * testGasPerBlobByte, gasConsumed: 0, @@ -50,7 +50,7 @@ func TestPFBAnteHandler(t *testing.T) { name: "pfb single blob not enough gas", pfb: &blob.MsgPayForBlobs{ // 2 share = 1024 bytes = 10240 gas - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(1) + 1)}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1) + 1)}, }, txGas: 2*appconsts.ShareSize*testGasPerBlobByte - 1, gasConsumed: 0, @@ -59,7 +59,7 @@ func TestPFBAnteHandler(t *testing.T) { { name: "pfb mulit blob not enough gas", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(1)), uint32(shares.AvailableBytesFromSparseShares(2))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1)), uint32(share.AvailableBytesFromSparseShares(2))}, }, txGas: 3*appconsts.ShareSize*testGasPerBlobByte - 1, gasConsumed: 0, @@ -69,7 +69,7 @@ func TestPFBAnteHandler(t *testing.T) { name: "pfb with existing gas consumed", pfb: &blob.MsgPayForBlobs{ // 1 share = 512 bytes = 5120 gas - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(1))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1))}, }, txGas: appconsts.ShareSize*testGasPerBlobByte + 10000 - 1, gasConsumed: 10000, @@ -79,7 +79,7 @@ func TestPFBAnteHandler(t *testing.T) { name: "valid pfb with existing gas consumed", pfb: &blob.MsgPayForBlobs{ // 1 share = 512 bytes = 5120 gas - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(10))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(10))}, }, txGas: 1000000, gasConsumed: 10000, diff --git a/x/blob/ante/blob_share_decorator.go b/x/blob/ante/blob_share_decorator.go index 40c9c7c9cc..3a23f45588 100644 --- a/x/blob/ante/blob_share_decorator.go +++ b/x/blob/ante/blob_share_decorator.go @@ -4,7 +4,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" v1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -77,7 +77,7 @@ func (d BlobShareDecorator) getMaxSquareSize(ctx sdk.Context) int { // the blobs described by blobSizes. func getSharesNeeded(blobSizes []uint32) (sum int) { for _, blobSize := range blobSizes { - sum += shares.SparseSharesNeeded(blobSize) + sum += share.SparseSharesNeeded(blobSize) } return sum } diff --git a/x/blob/ante/blob_share_decorator_test.go b/x/blob/ante/blob_share_decorator_test.go index 77b2bcfda6..bfcf899f43 100644 --- a/x/blob/ante/blob_share_decorator_test.go +++ b/x/blob/ante/blob_share_decorator_test.go @@ -9,7 +9,7 @@ import ( v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" ante "github.com/celestiaorg/celestia-app/v3/x/blob/ante" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -83,7 +83,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with many single byte blobs should fit", pfb: &blob.MsgPayForBlobs{ - // 4095 blobs each of size 1 byte should occupy 4095 shares. + // 4095 blobs each of size 1 byte should occupy 4095 share. // When square size is 64, there are 4095 shares available to // blob shares so we don't expect an error for this test case. BlobSizes: repeat(4095, 1), @@ -93,7 +93,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with too many single byte blobs should not fit", pfb: &blob.MsgPayForBlobs{ - // 4096 blobs each of size 1 byte should occupy 4096 shares. + // 4096 blobs each of size 1 byte should occupy 4096 share. // When square size is 64, there are 4095 shares available to // blob shares so we expect an error for this test case. BlobSizes: repeat(4096, 1), @@ -104,21 +104,21 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 share", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(1))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1))}, }, appVersion: v2.Version, }, { name: "PFB with 1 blob that occupies total square - 1", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares((squareSize * squareSize) - 1))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares((squareSize * squareSize) - 1))}, }, appVersion: v2.Version, }, { name: "PFB with 1 blob that occupies total square", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(squareSize * squareSize))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(squareSize * squareSize))}, }, appVersion: v2.Version, // This test case should return an error because if the blob @@ -130,8 +130,8 @@ func TestBlobShareDecorator(t *testing.T) { name: "PFB with 2 blobs that are 1 share each", pfb: &blob.MsgPayForBlobs{ BlobSizes: []uint32{ - uint32(shares.AvailableBytesFromSparseShares(1)), - uint32(shares.AvailableBytesFromSparseShares(1)), + uint32(share.AvailableBytesFromSparseShares(1)), + uint32(share.AvailableBytesFromSparseShares(1)), }, }, appVersion: v2.Version, @@ -140,8 +140,8 @@ func TestBlobShareDecorator(t *testing.T) { name: "PFB with 2 blobs that occupy half the square each", pfb: &blob.MsgPayForBlobs{ BlobSizes: []uint32{ - uint32(shares.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), - uint32(shares.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), + uint32(share.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), + uint32(share.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), }, }, appVersion: v2.Version, diff --git a/x/blob/ante/max_total_blob_size_ante.go b/x/blob/ante/max_total_blob_size_ante.go index c92be31996..3a9af081c1 100644 --- a/x/blob/ante/max_total_blob_size_ante.go +++ b/x/blob/ante/max_total_blob_size_ante.go @@ -5,7 +5,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" v1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -53,7 +53,7 @@ func (d MaxTotalBlobSizeDecorator) maxTotalBlobSize(ctx sdk.Context) int { // The PFB tx share must occupy at least one share so the # of blob shares // is at least one less than totalShares. blobShares := totalShares - 1 - return shares.AvailableBytesFromSparseShares(blobShares) + return share.AvailableBytesFromSparseShares(blobShares) } // getMaxSquareSize returns the maximum square size based on the current values diff --git a/x/blob/ante/max_total_blob_size_ante_test.go b/x/blob/ante/max_total_blob_size_ante_test.go index fc14f21d0a..5156bc89a7 100644 --- a/x/blob/ante/max_total_blob_size_ante_test.go +++ b/x/blob/ante/max_total_blob_size_ante_test.go @@ -9,7 +9,7 @@ import ( v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" ante "github.com/celestiaorg/celestia-app/v3/x/blob/ante" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -78,21 +78,21 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 share", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(1))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1))}, }, appVersion: v1.Version, }, { name: "PFB with 1 blob that occupies total square - 1", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares((squareSize * squareSize) - 1))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares((squareSize * squareSize) - 1))}, }, appVersion: v1.Version, }, { name: "PFB with 1 blob that occupies total square", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{uint32(shares.AvailableBytesFromSparseShares(squareSize * squareSize))}, + BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(squareSize * squareSize))}, }, appVersion: v1.Version, // This test case should return an error because if the blob @@ -104,8 +104,8 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { name: "PFB with 2 blobs that are 1 share each", pfb: &blob.MsgPayForBlobs{ BlobSizes: []uint32{ - uint32(shares.AvailableBytesFromSparseShares(1)), - uint32(shares.AvailableBytesFromSparseShares(1)), + uint32(share.AvailableBytesFromSparseShares(1)), + uint32(share.AvailableBytesFromSparseShares(1)), }, }, appVersion: v1.Version, @@ -114,8 +114,8 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { name: "PFB with 2 blobs that occupy half the square each", pfb: &blob.MsgPayForBlobs{ BlobSizes: []uint32{ - uint32(shares.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), - uint32(shares.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), + uint32(share.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), + uint32(share.AvailableBytesFromSparseShares(squareSize * squareSize / 2)), }, }, appVersion: v1.Version, diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 667d9e3969..720b3cbc0c 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -13,8 +13,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" @@ -24,11 +23,11 @@ import ( const ( // FlagShareVersion allows the user to override the share version when - // submitting a PayForBlob. + // submitting a PayForshare. FlagShareVersion = "share-version" // FlagNamespaceVersion allows the user to override the namespace version when - // submitting a PayForBlob. + // submitting a PayForshare. FlagNamespaceVersion = "namespace-version" // FlagFileInput allows the user to provide the path to a JSON file for @@ -130,7 +129,7 @@ The blob must be a hex encoded string of non-zero length. return err } - var blobs []*blob.Blob + var blobs []*share.Blob for _, paresdBlob := range paresdBlobs { blob, err := getBlobFromArguments(paresdBlob.NamespaceID, paresdBlob.Blob, namespaceVersion, shareVersion) if err != nil { @@ -151,7 +150,7 @@ The blob must be a hex encoded string of non-zero length. return cmd } -func getBlobFromArguments(namespaceIDArg, blobArg string, namespaceVersion, shareVersion uint8) (*blob.Blob, error) { +func getBlobFromArguments(namespaceIDArg, blobArg string, namespaceVersion, shareVersion uint8) (*share.Blob, error) { namespaceID, err := hex.DecodeString(strings.TrimPrefix(namespaceIDArg, "0x")) if err != nil { return nil, fmt.Errorf("failed to decode hex namespace ID: %w", err) @@ -174,24 +173,24 @@ func getBlobFromArguments(namespaceIDArg, blobArg string, namespaceVersion, shar return blob, nil } -func getNamespace(namespaceID []byte, namespaceVersion uint8) (appns.Namespace, error) { +func getNamespace(namespaceID []byte, namespaceVersion uint8) (share.Namespace, error) { switch namespaceVersion { - case appns.NamespaceVersionZero: - if len(namespaceID) != appns.NamespaceVersionZeroIDSize { - return appns.Namespace{}, fmt.Errorf("the user specifiable portion of the namespace ID must be %d bytes for namespace version 0", appns.NamespaceVersionZeroIDSize) + case share.NamespaceVersionZero: + if len(namespaceID) != share.NamespaceVersionZeroIDSize { + return share.Namespace{}, fmt.Errorf("the user specifiable portion of the namespace ID must be %d bytes for namespace version 0", share.NamespaceVersionZeroIDSize) } - id := make([]byte, 0, appns.NamespaceIDSize) - id = append(id, appns.NamespaceVersionZeroPrefix...) + id := make([]byte, 0, share.NamespaceIDSize) + id = append(id, share.NamespaceVersionZeroPrefix...) id = append(id, namespaceID...) - return appns.New(namespaceVersion, id) + return share.NewNamespace(namespaceVersion, id) default: - return appns.Namespace{}, fmt.Errorf("namespace version %d is not supported", namespaceVersion) + return share.Namespace{}, fmt.Errorf("namespace version %d is not supported", namespaceVersion) } } // broadcastPFB creates the new PFB message type that will later be broadcast to tendermint nodes // this private func is used in CmdPayForBlob -func broadcastPFB(cmd *cobra.Command, b ...*blob.Blob) error { +func broadcastPFB(cmd *cobra.Command, b ...*share.Blob) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err @@ -214,7 +213,7 @@ func broadcastPFB(cmd *cobra.Command, b ...*blob.Blob) error { return err } - blobTx, err := blob.MarshalBlobTx(txBytes, b...) + blobTx, err := share.MarshalBlobTx(txBytes, b...) if err != nil { return err } diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 6ff896a189..d29de7f658 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -20,7 +20,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testnode" paycli "github.com/celestiaorg/celestia-app/v3/x/blob/client/cli" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" abci "github.com/tendermint/tendermint/abci/types" ) @@ -89,7 +89,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { } ] } - `, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob, hex.EncodeToString(appns.RandomBlobNamespaceID()), hexBlob) + `, hex.EncodeToString(share.RandomBlobNamespaceID()), hexBlob, hex.EncodeToString(share.RandomBlobNamespaceID()), hexBlob) validPropFile := createTestFile(s.T(), validBlob, true) invalidPropFile := createTestFile(s.T(), validBlob, false) @@ -103,7 +103,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { { name: "single blob valid transaction", args: []string{ - hex.EncodeToString(appns.RandomBlobNamespaceID()), + hex.EncodeToString(share.RandomBlobNamespaceID()), hexBlob, fmt.Sprintf("--from=%s", username), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), diff --git a/x/blob/keeper/keeper_test.go b/x/blob/keeper/keeper_test.go index 1ad3fbb923..b42aea310c 100644 --- a/x/blob/keeper/keeper_test.go +++ b/x/blob/keeper/keeper_test.go @@ -9,8 +9,7 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/x/blob/keeper" "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - appns "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -30,7 +29,7 @@ import ( func TestPayForBlobs(t *testing.T) { k, _, ctx := CreateKeeper(t) signer := "celestia15drmhzw5kwgenvemy30rqqqgq52axf5wwrruf7" - namespace := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + namespace := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) namespaces := [][]byte{namespace.Bytes()} blobData := []byte("blob") blobSizes := []uint32{uint32(len(blobData))} @@ -65,8 +64,9 @@ func convertToEventPayForBlobs(message proto.Message) (*types.EventPayForBlobs, return nil, fmt.Errorf("message is not of type EventPayForBlobs") } -func createMsgPayForBlob(t *testing.T, signer string, namespace appns.Namespace, blobData []byte) *types.MsgPayForBlobs { - blob := blob.New(namespace, blobData, appconsts.ShareVersionZero) +func createMsgPayForBlob(t *testing.T, signer string, namespace share.Namespace, blobData []byte) *types.MsgPayForBlobs { + blob, err := share.NewBlob(namespace, blobData, appconsts.ShareVersionZero, nil) + require.NoError(t, err) msg, err := types.NewMsgPayForBlobs(signer, appconsts.LatestVersion, blob) require.NoError(t, err) return msg diff --git a/x/blob/test/decode_blob_tx_test.go b/x/blob/test/decode_blob_tx_test.go index 219b012ff9..f58f73b642 100644 --- a/x/blob/test/decode_blob_tx_test.go +++ b/x/blob/test/decode_blob_tx_test.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/proto/tendermint/blockchain" @@ -79,8 +79,11 @@ func getTestdataBlockResponse(t *testing.T) (resp blockchain.BlockResponse) { } func getTxBytes(txBytes []byte) []byte { - bTx, isBlob := blob.UnmarshalBlobTx(txBytes) + bTx, isBlob, err := share.UnmarshalBlobTx(txBytes) if isBlob { + if err != nil { + panic(err) + } return bTx.Tx } return txBytes diff --git a/x/blob/types/blob_tx.go b/x/blob/types/blob_tx.go index 249c37b574..35f9a07427 100644 --- a/x/blob/types/blob_tx.go +++ b/x/blob/types/blob_tx.go @@ -3,10 +3,8 @@ package types import ( "bytes" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" - appns "github.com/celestiaorg/go-square/namespace" - shares "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/client" "github.com/tendermint/tendermint/crypto/merkle" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -14,7 +12,8 @@ import ( // NewBlob creates a new coretypes.Blob from the provided data after performing // basic stateless checks over it. -func NewBlob(ns appns.Namespace, data []byte, shareVersion uint8) (*blob.Blob, error) { +func NewBlob(ns share.Namespace, data []byte, shareVersion uint8) (*share.Blob, error) { + // checks that it is a non reserved, valid namespace err := ValidateBlobNamespace(ns) if err != nil { return nil, err @@ -24,17 +23,12 @@ func NewBlob(ns appns.Namespace, data []byte, shareVersion uint8) (*blob.Blob, e return nil, ErrZeroBlobSize } - return &blob.Blob{ - NamespaceId: ns.ID, - Data: data, - ShareVersion: uint32(shareVersion), - NamespaceVersion: uint32(ns.Version), - }, nil + return share.NewBlob(ns, data, shareVersion, nil) } // ValidateBlobTx performs stateless checks on the BlobTx to ensure that the // blobs attached to the transaction are valid. -func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *blob.BlobTx, subtreeRootThreshold int) error { +func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *share.BlobTx, subtreeRootThreshold int) error { if bTx == nil { return ErrNoBlobs } @@ -63,7 +57,7 @@ func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *blob.BlobTx, subtreeRoot // perform basic checks on the blobs sizes := make([]uint32, len(bTx.Blobs)) for i, pblob := range bTx.Blobs { - sizes[i] = uint32(len(pblob.Data)) + sizes[i] = uint32(len(pblob.Data())) } err = ValidateBlobs(bTx.Blobs...) if err != nil { @@ -76,20 +70,13 @@ func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *blob.BlobTx, subtreeRoot } for i, ns := range msgPFB.Namespaces { - msgPFBNamespace, err := appns.From(ns) + msgPFBNamespace, err := share.NewNamespaceFromBytes(ns) if err != nil { return err } - // this not only checks that the pfb namespaces match the ones in the blobs - // but that the namespace version and namespace id are valid - blobNamespace, err := appns.New(uint8(bTx.Blobs[i].NamespaceVersion), bTx.Blobs[i].NamespaceId) - if err != nil { - return err - } - - if !bytes.Equal(blobNamespace.Bytes(), msgPFBNamespace.Bytes()) { - return ErrNamespaceMismatch.Wrapf("%v %v", blobNamespace.Bytes(), msgPFB.Namespaces[i]) + if !bytes.Equal(bTx.Blobs[i].Namespace().Bytes(), msgPFBNamespace.Bytes()) { + return ErrNamespaceMismatch.Wrapf("%v %v", bTx.Blobs[i].Namespace().Bytes(), msgPFB.Namespaces[i]) } } @@ -110,7 +97,7 @@ func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *blob.BlobTx, subtreeRoot func BlobTxSharesUsed(btx tmproto.BlobTx) int { sharesUsed := 0 for _, blob := range btx.Blobs { - sharesUsed += shares.SparseSharesNeeded(uint32(len(blob.Data))) + sharesUsed += share.SparseSharesNeeded(uint32(len(blob.Data))) } return sharesUsed } diff --git a/x/blob/types/blob_tx_test.go b/x/blob/types/blob_tx_test.go index 9b861273ee..ca02ee19e2 100644 --- a/x/blob/types/blob_tx_test.go +++ b/x/blob/types/blob_tx_test.go @@ -11,27 +11,26 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" - "github.com/celestiaorg/go-square/merkle" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/merkle" tmrand "github.com/tendermint/tendermint/libs/rand" ) func TestNewBlob(t *testing.T) { rawBlob := []byte{1} - validBlob, err := types.NewBlob(namespace.RandomBlobNamespace(), rawBlob, appconsts.ShareVersionZero) + validBlob, err := types.NewBlob(share.RandomBlobNamespace(), rawBlob, appconsts.ShareVersionZero) require.NoError(t, err) - require.Equal(t, validBlob.Data, rawBlob) + require.Equal(t, validBlob.Data(), rawBlob) - _, err = types.NewBlob(namespace.TxNamespace, rawBlob, appconsts.ShareVersionZero) + _, err = types.NewBlob(share.TxNamespace, rawBlob, appconsts.ShareVersionZero) require.Error(t, err) - _, err = types.NewBlob(namespace.RandomBlobNamespace(), []byte{}, appconsts.ShareVersionZero) + _, err = types.NewBlob(share.RandomBlobNamespace(), []byte{}, appconsts.ShareVersionZero) require.Error(t, err) } @@ -39,21 +38,21 @@ func TestValidateBlobTx(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - ns1 := namespace.MustNewV0(bytes.Repeat([]byte{0x01}, namespace.NamespaceVersionZeroIDSize)) + ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{0x01}, share.NamespaceVersionZeroIDSize)) acc := signer.Account(testfactory.TestAccName) require.NotNil(t, acc) addr := acc.Address() type test struct { name string - getTx func() *blob.BlobTx + getTx func() *share.BlobTx expectedErr error } validRawBtx := func() []byte { btx := blobfactory.RandBlobTxsWithNamespacesAndSigner( signer, - []namespace.Namespace{ns1}, + []share.Namespace{ns1}, []int{10}, )[0] return btx @@ -62,42 +61,50 @@ func TestValidateBlobTx(t *testing.T) { tests := []test{ { name: "normal transaction", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { rawBtx := validRawBtx() - btx, _ := blob.UnmarshalBlobTx(rawBtx) + btx, _, err := share.UnmarshalBlobTx(rawBtx) + require.NoError(t, err) return btx }, expectedErr: nil, }, { name: "invalid transaction, mismatched namespace", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { rawBtx := validRawBtx() - btx, _ := blob.UnmarshalBlobTx(rawBtx) - btx.Blobs[0].NamespaceId = namespace.RandomBlobNamespace().ID + btx, _, err := share.UnmarshalBlobTx(rawBtx) + require.NoError(t, err) + + originalBlob := btx.Blobs[0] + differentBlob, err := share.NewBlob(share.RandomBlobNamespace(), originalBlob.Data(), originalBlob.ShareVersion(), nil) + require.NoError(t, err) + + btx.Blobs[0] = differentBlob return btx }, expectedErr: types.ErrNamespaceMismatch, }, { name: "invalid transaction, no pfb", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { sendTx := blobfactory.GenerateManyRawSendTxs(signer, 1) - b, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + b, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) - return &blob.BlobTx{ + return &share.BlobTx{ Tx: sendTx[0], - Blobs: []*blob.Blob{b}, + Blobs: []*share.Blob{b}, } }, expectedErr: types.ErrNoPFB, }, { name: "mismatched number of pfbs and blobs", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { rawBtx := validRawBtx() - btx, _ := blob.UnmarshalBlobTx(rawBtx) - blob, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + btx, _, err := share.UnmarshalBlobTx(rawBtx) + require.NoError(t, err) + blob, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) btx.Blobs = append(btx.Blobs, blob) return btx @@ -106,8 +113,8 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "invalid share commitment", - getTx: func() *blob.BlobTx { - b, err := types.NewBlob(namespace.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + getTx: func() *share.BlobTx { + b, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) msg, err := types.NewMsgPayForBlobs( addr.String(), @@ -116,13 +123,10 @@ func TestValidateBlobTx(t *testing.T) { ) require.NoError(t, err) + anotherBlob, err := share.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(99), appconsts.ShareVersionZero, nil) + require.NoError(t, err) badCommit, err := inclusion.CreateCommitment( - &blob.Blob{ - NamespaceVersion: uint32(namespace.RandomBlobNamespace().Version), - NamespaceId: namespace.RandomBlobNamespace().ID, - Data: tmrand.Bytes(99), - ShareVersion: uint32(appconsts.ShareVersionZero), - }, + anotherBlob, merkle.HashFromByteSlices, appconsts.DefaultSubtreeRootThreshold, ) @@ -133,9 +137,9 @@ func TestValidateBlobTx(t *testing.T) { rawTx, err := signer.CreateTx([]sdk.Msg{msg}) require.NoError(t, err) - btx := &blob.BlobTx{ + btx := &share.BlobTx{ Tx: rawTx, - Blobs: []*blob.Blob{b}, + Blobs: []*share.Blob{b}, } return btx }, @@ -143,7 +147,7 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "complex transaction with one send and one pfb", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { sendMsg := banktypes.NewMsgSend(addr, addr, sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))) tx := blobfactory.ComplexBlobTxWithOtherMsgs( t, @@ -151,17 +155,18 @@ func TestValidateBlobTx(t *testing.T) { signer, sendMsg, ) - btx, isBlob := blob.UnmarshalBlobTx(tx) - require.True(t, isBlob) + btx, ok, err := share.UnmarshalBlobTx(tx) + require.NoError(t, err) + require.True(t, ok) return btx }, expectedErr: types.ErrMultipleMsgsInBlobTx, }, { name: "only send tx", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { sendtx := blobfactory.GenerateManyRawSendTxs(signer, 1)[0] - return &blob.BlobTx{ + return &share.BlobTx{ Tx: sendtx, } }, @@ -169,13 +174,14 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two blobs w/ different namespaces", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), blobfactory.RandBlobsWithNamespace( - []namespace.Namespace{namespace.RandomBlobNamespace(), namespace.RandomBlobNamespace()}, + []share.Namespace{share.RandomBlobNamespace(), share.RandomBlobNamespace()}, []int{100, 100})) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + require.NoError(t, err) require.True(t, isBlobTx) return btx }, @@ -183,14 +189,15 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two large blobs w/ different namespaces", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), blobfactory.RandBlobsWithNamespace( - []namespace.Namespace{namespace.RandomBlobNamespace(), namespace.RandomBlobNamespace()}, + []share.Namespace{share.RandomBlobNamespace(), share.RandomBlobNamespace()}, []int{100000, 1000000}), ) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + require.NoError(t, err) require.True(t, isBlobTx) return btx }, @@ -198,15 +205,16 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two blobs w/ same namespace", - getTx: func() *blob.BlobTx { - ns := namespace.RandomBlobNamespace() + getTx: func() *share.BlobTx { + ns := share.RandomBlobNamespace() rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), blobfactory.RandBlobsWithNamespace( - []namespace.Namespace{ns, ns}, + []share.Namespace{ns, ns}, []int{100, 100}), ) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + require.NoError(t, err) require.True(t, isBlobTx) return btx }, @@ -214,11 +222,11 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with one hundred blobs of the same namespace", - getTx: func() *blob.BlobTx { + getTx: func() *share.BlobTx { count := 100 - ns := namespace.RandomBlobNamespace() + ns := share.RandomBlobNamespace() sizes := make([]int, count) - namespaces := make([]namespace.Namespace, count) + namespaces := make([]share.Namespace, count) for i := 0; i < count; i++ { sizes[i] = 100 namespaces[i] = ns @@ -229,7 +237,8 @@ func TestValidateBlobTx(t *testing.T) { sizes, )) require.NoError(t, err) - btx, isBlobTx := blob.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + require.NoError(t, err) require.True(t, isBlobTx) return btx }, diff --git a/x/blob/types/estimate_gas_test.go b/x/blob/types/estimate_gas_test.go index 75a08b8c3d..3eeeed1e10 100644 --- a/x/blob/types/estimate_gas_test.go +++ b/x/blob/types/estimate_gas_test.go @@ -11,7 +11,7 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/blob" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/require" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" @@ -44,7 +44,8 @@ func TestPFBGasEstimation(t *testing.T) { gas := blobtypes.DefaultEstimateGas(toUint32(tc.blobSizes)) tx, _, err := signer.CreatePayForBlobs(accnts[0], blobs, user.SetGasLimitAndGasPrice(gas, appconsts.DefaultMinGasPrice)) require.NoError(t, err) - blobTx, ok := blob.UnmarshalBlobTx(tx) + blobTx, ok, err := share.UnmarshalBlobTx(tx) + require.NoError(t, err) require.True(t, ok) resp := testApp.DeliverTx(abci.RequestDeliverTx{ Tx: blobTx.Tx, @@ -87,7 +88,8 @@ func FuzzPFBGasEstimation(f *testing.F) { gas := blobtypes.DefaultEstimateGas(toUint32(blobSizes)) tx, _, err := signer.CreatePayForBlobs(accnts[0], blobs, user.SetGasLimitAndGasPrice(gas, appconsts.DefaultMinGasPrice)) require.NoError(t, err) - blobTx, ok := blob.UnmarshalBlobTx(tx) + blobTx, ok, err := share.UnmarshalBlobTx(tx) + require.NoError(t, err) require.True(t, ok) resp := testApp.DeliverTx(abci.RequestDeliverTx{ Tx: blobTx.Tx, diff --git a/x/blob/types/params.go b/x/blob/types/params.go index b9289c8940..b852473632 100644 --- a/x/blob/types/params.go +++ b/x/blob/types/params.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "gopkg.in/yaml.v2" ) @@ -84,7 +84,7 @@ func validateGovMaxSquareSize(v interface{}) error { return fmt.Errorf("gov max square size cannot be zero") } - if !shares.IsPowerOfTwo(govMaxSquareSize) { + if !square.IsPowerOfTwo(govMaxSquareSize) { return fmt.Errorf( "gov max square size must be a power of two: %d", govMaxSquareSize, diff --git a/x/blob/types/payforblob.go b/x/blob/types/payforblob.go index e1db0c7cf6..dbffa3432f 100644 --- a/x/blob/types/payforblob.go +++ b/x/blob/types/payforblob.go @@ -6,14 +6,12 @@ import ( "cosmossdk.io/errors" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" - "github.com/celestiaorg/go-square/merkle" - appns "github.com/celestiaorg/go-square/namespace" - appshares "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" auth "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/tendermint/tendermint/crypto/merkle" "golang.org/x/exp/slices" ) @@ -45,7 +43,7 @@ const ( // See: https://github.com/cosmos/cosmos-sdk/blob/v0.46.15/docs/building-modules/messages-and-queries.md#legacy-amino-legacymsgs var _ legacytx.LegacyMsg = &MsgPayForBlobs{} -func NewMsgPayForBlobs(signer string, version uint64, blobs ...*blob.Blob) (*MsgPayForBlobs, error) { +func NewMsgPayForBlobs(signer string, version uint64, blobs ...*share.Blob) (*MsgPayForBlobs, error) { err := ValidateBlobs(blobs...) if err != nil { return nil, err @@ -55,15 +53,7 @@ func NewMsgPayForBlobs(signer string, version uint64, blobs ...*blob.Blob) (*Msg return nil, fmt.Errorf("creating commitments: %w", err) } - namespaceVersions, namespaceIDs, sizes, shareVersions := ExtractBlobComponents(blobs) - namespaces := []appns.Namespace{} - for i := range namespaceVersions { - namespace, err := appns.New(uint8(namespaceVersions[i]), namespaceIDs[i]) - if err != nil { - return nil, err - } - namespaces = append(namespaces, namespace) - } + namespaces, sizes, shareVersions := ExtractBlobComponents(blobs) msg := &MsgPayForBlobs{ Signer: signer, @@ -76,7 +66,7 @@ func NewMsgPayForBlobs(signer string, version uint64, blobs ...*blob.Blob) (*Msg return msg, msg.ValidateBasic() } -func namespacesToBytes(namespaces []appns.Namespace) (result [][]byte) { +func namespacesToBytes(namespaces []share.Namespace) (result [][]byte) { for _, namespace := range namespaces { result = append(result, namespace.Bytes()) } @@ -118,7 +108,7 @@ func (msg *MsgPayForBlobs) ValidateBasic() error { } for _, namespace := range msg.Namespaces { - ns, err := appns.From(namespace) + ns, err := share.NewNamespaceFromBytes(namespace) if err != nil { return errors.Wrap(ErrInvalidNamespace, err.Error()) } @@ -158,7 +148,7 @@ func (msg *MsgPayForBlobs) Gas(gasPerByte uint32) uint64 { func GasToConsume(blobSizes []uint32, gasPerByte uint32) uint64 { var totalSharesUsed uint64 for _, size := range blobSizes { - totalSharesUsed += uint64(appshares.SparseSharesNeeded(size)) + totalSharesUsed += uint64(share.SparseSharesNeeded(size)) } return totalSharesUsed * appconsts.ShareSize * uint64(gasPerByte) @@ -181,12 +171,12 @@ func DefaultEstimateGas(blobSizes []uint32) uint64 { // ValidateBlobNamespace returns an error if the provided namespace is an // invalid user-specifiable blob namespace (e.g. reserved, parity shares, or // tail padding). -func ValidateBlobNamespace(ns appns.Namespace) error { +func ValidateBlobNamespace(ns share.Namespace) error { if ns.IsReserved() { return ErrReservedNamespace } - if !slices.Contains(appns.SupportedBlobNamespaceVersions, ns.Version) { + if !slices.Contains(share.SupportedBlobNamespaceVersions, ns.Version()) { return ErrInvalidNamespaceVersion } @@ -209,29 +199,22 @@ func (msg *MsgPayForBlobs) GetSigners() []sdk.AccAddress { } // ValidateBlobs performs basic checks over the components of one or more PFBs. -func ValidateBlobs(blobs ...*blob.Blob) error { +func ValidateBlobs(blobs ...*share.Blob) error { if len(blobs) == 0 { return ErrNoBlobs } for _, blob := range blobs { - if blob.NamespaceVersion > appconsts.NamespaceVersionMaxValue { - return fmt.Errorf("namespace version %d is too large", blob.NamespaceVersion) - } - ns, err := appns.New(uint8(blob.NamespaceVersion), blob.NamespaceId) - if err != nil { - return err - } - err = ValidateBlobNamespace(ns) + err := ValidateBlobNamespace(blob.Namespace()) if err != nil { return err } - if len(blob.Data) == 0 { + if len(blob.Data()) == 0 { return ErrZeroBlobSize } - if !slices.Contains(appconsts.SupportedShareVersions, uint8(blob.ShareVersion)) { + if !slices.Contains(appconsts.SupportedShareVersions, blob.ShareVersion()) { return ErrUnsupportedShareVersion } } @@ -241,18 +224,16 @@ func ValidateBlobs(blobs ...*blob.Blob) error { // ExtractBlobComponents separates and returns the components of a slice of // blobs. -func ExtractBlobComponents(pblobs []*blob.Blob) (namespaceVersions []uint32, namespaceIDs [][]byte, sizes []uint32, shareVersions []uint32) { - namespaceVersions = make([]uint32, len(pblobs)) - namespaceIDs = make([][]byte, len(pblobs)) +func ExtractBlobComponents(pblobs []*share.Blob) (namespaces []share.Namespace, sizes []uint32, shareVersions []uint32) { + namespaces = make([]share.Namespace, len(pblobs)) sizes = make([]uint32, len(pblobs)) shareVersions = make([]uint32, len(pblobs)) for i, pblob := range pblobs { - namespaceVersions[i] = pblob.NamespaceVersion - namespaceIDs[i] = pblob.NamespaceId - sizes[i] = uint32(len(pblob.Data)) - shareVersions[i] = pblob.ShareVersion + namespaces[i] = pblob.Namespace() + sizes[i] = uint32(len(pblob.Data())) + shareVersions[i] = uint32(pblob.ShareVersion()) } - return namespaceVersions, namespaceIDs, sizes, shareVersions + return namespaces, sizes, shareVersions } diff --git a/x/blob/types/payforblob_test.go b/x/blob/types/payforblob_test.go index c5390acc35..0b48759cb8 100644 --- a/x/blob/types/payforblob_test.go +++ b/x/blob/types/payforblob_test.go @@ -2,6 +2,7 @@ package types_test import ( "bytes" + "encoding/binary" "testing" sdkerrors "cosmossdk.io/errors" @@ -9,10 +10,8 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/blob" - "github.com/celestiaorg/go-square/inclusion" - appns "github.com/celestiaorg/go-square/namespace" - shares "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2/inclusion" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -35,23 +34,23 @@ func TestValidateBasic(t *testing.T) { // MsgPayForBlobs that uses parity shares namespace paritySharesMsg := validMsgPayForBlobs(t) - paritySharesMsg.Namespaces[0] = appns.ParitySharesNamespace.Bytes() + paritySharesMsg.Namespaces[0] = share.ParitySharesNamespace.Bytes() // MsgPayForBlobs that uses tail padding namespace tailPaddingMsg := validMsgPayForBlobs(t) - tailPaddingMsg.Namespaces[0] = appns.TailPaddingNamespace.Bytes() + tailPaddingMsg.Namespaces[0] = share.TailPaddingNamespace.Bytes() // MsgPayForBlobs that uses transaction namespace txNamespaceMsg := validMsgPayForBlobs(t) - txNamespaceMsg.Namespaces[0] = appns.TxNamespace.Bytes() + txNamespaceMsg.Namespaces[0] = share.TxNamespace.Bytes() // MsgPayForBlobs that uses intermediateStateRoots namespace intermediateStateRootsNamespaceMsg := validMsgPayForBlobs(t) - intermediateStateRootsNamespaceMsg.Namespaces[0] = appns.IntermediateStateRootsNamespace.Bytes() + intermediateStateRootsNamespaceMsg.Namespaces[0] = share.IntermediateStateRootsNamespace.Bytes() // MsgPayForBlobs that uses the max primary reserved namespace maxReservedNamespaceMsg := validMsgPayForBlobs(t) - maxReservedNamespaceMsg.Namespaces[0] = appns.MaxPrimaryReservedNamespace.Bytes() + maxReservedNamespaceMsg.Namespaces[0] = share.MaxPrimaryReservedNamespace.Bytes() // MsgPayForBlobs that has an empty share commitment emptyShareCommitment := validMsgPayForBlobs(t) @@ -163,25 +162,27 @@ func TestValidateBasic(t *testing.T) { // totalBlobSize subtracts the delimiter size from the desired total size. this // is useful for testing for blobs that occupy exactly so many shares. func totalBlobSize(size int) int { - return size - shares.DelimLen(uint64(size)) + return size - delimLen(uint64(size)) +} + +func delimLen(size uint64) int { + lenBuf := make([]byte, binary.MaxVarintLen64) + return binary.PutUvarint(lenBuf, size) } func validMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - ns1 := appns.NamespaceVersionZeroPrefix - ns1 = append(ns1, bytes.Repeat([]byte{0x01}, appns.NamespaceVersionZeroIDSize)...) + ns1 := share.NamespaceVersionZeroPrefix + ns1 = append(ns1, bytes.Repeat([]byte{0x01}, share.NamespaceVersionZeroIDSize)...) + ns := share.MustNewNamespace(share.NamespaceVersionZero, ns1) data := bytes.Repeat([]byte{2}, totalBlobSize(appconsts.ContinuationSparseShareContentSize*12)) - pblob := &blob.Blob{ - Data: data, - NamespaceId: ns1, - NamespaceVersion: uint32(appns.NamespaceVersionZero), - ShareVersion: uint32(appconsts.ShareVersionZero), - } + blob, err := share.NewV0Blob(ns, data) + require.NoError(t, err) addr := signer.Account(testfactory.TestAccName).Address() - pfb, err := types.NewMsgPayForBlobs(addr.String(), appconsts.LatestVersion, pblob) + pfb, err := types.NewMsgPayForBlobs(addr.String(), appconsts.LatestVersion, blob) assert.NoError(t, err) return pfb @@ -190,29 +191,19 @@ func validMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { func invalidNamespaceVersionMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - ns1 := appns.NamespaceVersionZeroPrefix - ns1 = append(ns1, bytes.Repeat([]byte{0x01}, appns.NamespaceVersionZeroIDSize)...) + ns1 := share.NamespaceVersionZeroPrefix + ns1 = append(ns1, bytes.Repeat([]byte{0x01}, share.NamespaceVersionZeroIDSize)...) + ns := share.MustNewNamespace(255, ns1) data := bytes.Repeat([]byte{2}, totalBlobSize(appconsts.ContinuationSparseShareContentSize*12)) - pblob := &blob.Blob{ - Data: data, - NamespaceId: ns1, - NamespaceVersion: uint32(255), - ShareVersion: uint32(appconsts.ShareVersionZero), - } - - blobs := []*blob.Blob{pblob} + blob, err := share.NewV0Blob(ns, data) + require.NoError(t, err) + blobs := []*share.Blob{blob} commitments, err := inclusion.CreateCommitments(blobs, merkle.HashFromByteSlices, appconsts.DefaultSubtreeRootThreshold) require.NoError(t, err) - namespaceVersions, namespaceIDs, sizes, shareVersions := types.ExtractBlobComponents(blobs) - namespaces := []appns.Namespace{} - for i := range namespaceVersions { - namespace, err := appns.New(uint8(namespaceVersions[i]), namespaceIDs[i]) - require.NoError(t, err) - namespaces = append(namespaces, namespace) - } + namespaces, sizes, shareVersions := types.ExtractBlobComponents(blobs) namespacesBytes := make([][]byte, len(namespaces)) for idx, namespace := range namespaces { @@ -235,93 +226,53 @@ func TestNewMsgPayForBlobs(t *testing.T) { type testCase struct { name string signer string - blobs []*blob.Blob + blobs []*share.Blob expectedErr bool } - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - ns2 := appns.MustNewV0(bytes.Repeat([]byte{2}, appns.NamespaceVersionZeroIDSize)) + ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) + ns2 := share.MustNewV0Namespace(bytes.Repeat([]byte{2}, share.NamespaceVersionZeroIDSize)) testCases := []testCase{ { name: "valid msg PFB with small blob", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ - { - NamespaceVersion: uint32(ns1.Version), - NamespaceId: ns1.ID, - Data: []byte{1}, - ShareVersion: uint32(appconsts.ShareVersionZero), - }, - }, - expectedErr: false, + blobs: []*share.Blob{mustNewBlob(t, ns1, []byte{1}, appconsts.ShareVersionZero, nil)}, }, { name: "valid msg PFB with large blob", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ - { - NamespaceVersion: uint32(ns1.Version), - NamespaceId: ns1.ID, - Data: tmrand.Bytes(1000000), - ShareVersion: uint32(appconsts.ShareVersionZero), - }, - }, - expectedErr: false, + blobs: []*share.Blob{mustNewBlob(t, ns1, tmrand.Bytes(1000000), appconsts.ShareVersionZero, nil)}, }, { name: "valid msg PFB with two blobs", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ - { - NamespaceVersion: uint32(ns1.Version), - NamespaceId: ns1.ID, - Data: []byte{1}, - ShareVersion: uint32(appconsts.ShareVersionZero), - }, - { - NamespaceVersion: uint32(ns2.Version), - NamespaceId: ns2.ID, - Data: []byte{2}, - ShareVersion: uint32(appconsts.ShareVersionZero), - }, + blobs: []*share.Blob{ + mustNewBlob(t, ns1, []byte{1}, appconsts.ShareVersionZero, nil), + mustNewBlob(t, ns2, []byte{2}, appconsts.ShareVersionZero, nil), }, + expectedErr: false, }, { name: "unsupported share version returns an error", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ - { - NamespaceVersion: uint32(ns1.Version), - NamespaceId: ns1.ID, - Data: tmrand.Bytes(1000000), - ShareVersion: uint32(10), // unsupported share version - }, + blobs: []*share.Blob{ + mustNewBlob(t, ns1, tmrand.Bytes(1000000), 10, nil), }, expectedErr: true, }, { name: "msg PFB with tx namespace returns an error", signer: testfactory.TestAccAddr, - blobs: []*blob.Blob{ - { - NamespaceVersion: uint32(appns.TxNamespace.Version), - NamespaceId: appns.TxNamespace.ID, - Data: tmrand.Bytes(1000000), - ShareVersion: uint32(appconsts.ShareVersionZero), - }, + blobs: []*share.Blob{ + mustNewBlob(t, share.TxNamespace, tmrand.Bytes(1000000), appconsts.ShareVersionZero, nil), }, expectedErr: true, }, { name: "msg PFB with invalid signer returns an error", signer: testfactory.TestAccAddr[:10], - blobs: []*blob.Blob{ - { - NamespaceVersion: uint32(ns1.Version), - NamespaceId: ns1.ID, - Data: []byte{1}, - ShareVersion: uint32(appconsts.ShareVersionZero), - }, + blobs: []*share.Blob{ + mustNewBlob(t, ns1, []byte{1}, appconsts.ShareVersionZero, nil), }, expectedErr: true, }, @@ -335,11 +286,10 @@ func TestNewMsgPayForBlobs(t *testing.T) { } for i, blob := range tc.blobs { - assert.Equal(t, uint32(len(blob.Data)), msgPFB.BlobSizes[i]) - ns, err := appns.From(msgPFB.Namespaces[i]) + assert.Equal(t, uint32(len(blob.Data())), msgPFB.BlobSizes[i]) + ns, err := share.NewNamespaceFromBytes(msgPFB.Namespaces[i]) assert.NoError(t, err) - assert.Equal(t, ns.ID, blob.NamespaceId) - assert.Equal(t, uint32(ns.Version), blob.NamespaceVersion) + assert.Equal(t, ns, blob.Namespace()) expectedCommitment, err := inclusion.CreateCommitment(blob, merkle.HashFromByteSlices, appconsts.DefaultSubtreeRootThreshold) require.NoError(t, err) @@ -349,52 +299,33 @@ func TestNewMsgPayForBlobs(t *testing.T) { } } +func mustNewBlob(t *testing.T, ns share.Namespace, data []byte, shareVersion uint8, signer []byte) *share.Blob { + blob, err := share.NewBlob(ns, data, shareVersion, signer) + require.NoError(t, err) + return blob +} + func TestValidateBlobs(t *testing.T) { type test struct { name string - blob *blob.Blob + blob *share.Blob expectError bool } tests := []test{ { - name: "valid blob", - blob: &blob.Blob{ - Data: []byte{1}, - NamespaceId: appns.RandomBlobNamespace().ID, - ShareVersion: uint32(appconsts.DefaultShareVersion), - NamespaceVersion: uint32(appns.NamespaceVersionZero), - }, + name: "valid blob", + blob: mustNewBlob(t, share.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion, nil), expectError: false, }, { - name: "invalid share version", - blob: &blob.Blob{ - Data: []byte{1}, - NamespaceId: appns.RandomBlobNamespace().ID, - ShareVersion: uint32(10000), - NamespaceVersion: uint32(appns.NamespaceVersionZero), - }, + name: "invalid share version", + blob: mustNewBlob(t, share.RandomBlobNamespace(), []byte{1}, 4, nil), expectError: true, }, { - name: "empty blob", - blob: &blob.Blob{ - Data: []byte{}, - NamespaceId: appns.RandomBlobNamespace().ID, - ShareVersion: uint32(appconsts.DefaultShareVersion), - NamespaceVersion: uint32(appns.NamespaceVersionZero), - }, - expectError: true, - }, - { - name: "invalid namespace", - blob: &blob.Blob{ - Data: []byte{1}, - NamespaceId: appns.TxNamespace.ID, - ShareVersion: uint32(appconsts.DefaultShareVersion), - NamespaceVersion: uint32(appns.NamespaceVersionZero), - }, + name: "invalid namespace", + blob: mustNewBlob(t, share.TxNamespace, []byte{1}, appconsts.DefaultShareVersion, nil), expectError: true, }, } diff --git a/x/blobstream/client/verify.go b/x/blobstream/client/verify.go index 8aa1896947..6cc392389f 100644 --- a/x/blobstream/client/verify.go +++ b/x/blobstream/client/verify.go @@ -9,13 +9,13 @@ import ( "os" "strconv" - "github.com/celestiaorg/go-square/merkle" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/tendermint/tendermint/crypto/merkle" wrapper "github.com/celestiaorg/blobstream-contracts/v3/wrappers/Blobstream.sol" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/x/blobstream/types" - "github.com/celestiaorg/go-square/square" + square "github.com/celestiaorg/go-square/v2" "github.com/ethereum/go-ethereum/ethclient" "github.com/spf13/cobra" tmlog "github.com/tendermint/tendermint/libs/log" From c11731d315b515252ebbf31877c8ad8329ccb52a Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 1 Aug 2024 18:01:09 +0200 Subject: [PATCH 2/9] make more fixes --- app/check_tx.go | 4 +- app/process_proposal.go | 3 +- app/test/check_tx_test.go | 7 +-- app/test/consistent_apphash_test.go | 3 +- app/test/process_proposal_test.go | 54 ++++++--------------- app/validate_txs.go | 16 +++--- go.mod | 3 +- go.sum | 2 - pkg/proof/proof.go | 7 +-- pkg/user/signer.go | 3 +- pkg/user/tx_client.go | 5 +- test/txsim/blob.go | 2 +- test/util/blobfactory/payforblob_factory.go | 3 +- test/util/direct_tx_gen.go | 8 +-- test/util/malicious/out_of_order_builder.go | 3 +- test/util/testnode/read.go | 4 +- x/blob/client/cli/payforblob.go | 3 +- x/blob/test/decode_blob_tx_test.go | 4 +- x/blob/types/blob_tx.go | 3 +- x/blob/types/blob_tx_test.go | 49 ++++++++++--------- x/blob/types/estimate_gas_test.go | 6 +-- 21 files changed, 88 insertions(+), 104 deletions(-) diff --git a/app/check_tx.go b/app/check_tx.go index b2e5103cf9..0867cd2436 100644 --- a/app/check_tx.go +++ b/app/check_tx.go @@ -5,7 +5,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/v2/share" + blobtx "github.com/celestiaorg/go-square/v2/tx" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" abci "github.com/tendermint/tendermint/abci/types" ) @@ -16,7 +16,7 @@ import ( func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { tx := req.Tx // check if the transaction contains blobs - btx, isBlob, err := share.UnmarshalBlobTx(tx) + btx, isBlob, err := blobtx.UnmarshalBlobTx(tx) if isBlob && err != nil { return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, []abci.Event{}, false) } diff --git a/app/process_proposal.go b/app/process_proposal.go index 668c80b4f2..d1b367179c 100644 --- a/app/process_proposal.go +++ b/app/process_proposal.go @@ -11,6 +11,7 @@ import ( blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2" "github.com/celestiaorg/go-square/v2/share" + blobtx "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -55,7 +56,7 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp // blobTxs have no PFBs present for idx, rawTx := range req.BlockData.Txs { tx := rawTx - blobTx, isBlobTx, err := share.UnmarshalBlobTx(rawTx) + blobTx, isBlobTx, err := blobtx.UnmarshalBlobTx(rawTx) if isBlobTx { if err != nil { logInvalidPropBlockError(app.Logger(), req.Header, fmt.Sprintf("err with blob tx %d", idx), err) diff --git a/app/test/check_tx_test.go b/app/test/check_tx_test.go index b582272ff7..14b7a40f89 100644 --- a/app/test/check_tx_test.go +++ b/app/test/check_tx_test.go @@ -16,6 +16,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -83,12 +84,12 @@ func TestCheckTx(t *testing.T) { []int{100}, )[0] - dtx, _, err := share.UnmarshalBlobTx(btx) + dtx, _, err := tx.UnmarshalBlobTx(btx) require.NoError(t, err) - newBlob, err := share.NewBlob(share.RandomBlobNamespace(), []byte{1}, appconsts.DefaultShareVersion, nil) + newBlob, err := share.NewBlob(share.RandomBlobNamespace(), dtx.Blobs[0].Data(), appconsts.DefaultShareVersion, nil) require.NoError(t, err) dtx.Blobs[0] = newBlob - bbtx, err := share.MarshalBlobTx(dtx.Tx, dtx.Blobs[0]) + bbtx, err := tx.MarshalBlobTx(dtx.Tx, dtx.Blobs[0]) require.NoError(t, err) return bbtx }, diff --git a/app/test/consistent_apphash_test.go b/app/test/consistent_apphash_test.go index 6193656f3d..20fef6cbf5 100644 --- a/app/test/consistent_apphash_test.go +++ b/app/test/consistent_apphash_test.go @@ -14,6 +14,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -433,7 +434,7 @@ func executeTxs(testApp *app.App, encodedBlobTx []byte, encodedSdkTxs [][]byte, // Deliver Blob Txs if len(encodedBlobTx) != 0 { // Deliver Blob Tx - blob, isBlobTx, err := share.UnmarshalBlobTx(encodedBlobTx) + blob, isBlobTx, err := tx.UnmarshalBlobTx(encodedBlobTx) if !isBlobTx { return nil, nil, fmt.Errorf("Not a valid BlobTx") } diff --git a/app/test/process_proposal_test.go b/app/test/process_proposal_test.go index 303ac85be8..49c6cec341 100644 --- a/app/test/process_proposal_test.go +++ b/app/test/process_proposal_test.go @@ -26,6 +26,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/go-square/v2" "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" ) func TestProcessProposal(t *testing.T) { @@ -74,9 +75,6 @@ func TestProcessProposal(t *testing.T) { )[0] ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) - invalidNamespace, err := share.NewNamespace(share.NamespaceVersionZero, bytes.Repeat([]byte{1}, share.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 { @@ -117,12 +115,12 @@ func TestProcessProposal(t *testing.T) { name: "modified a blobTx", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) require.NoError(t, err) newBlob, err := share.NewBlob(ns1, data, appconsts.ShareVersionZero, nil) require.NoError(t, err) blobTx.Blobs[0] = newBlob - blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -132,12 +130,12 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace TailPadding", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) require.NoError(t, err) newBlob, err := share.NewBlob(share.TailPaddingNamespace, data, appconsts.ShareVersionZero, nil) require.NoError(t, err) blobTx.Blobs[0] = newBlob - blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -147,12 +145,12 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace TxNamespace", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) require.NoError(t, err) newBlob, err := share.NewBlob(share.TxNamespace, data, appconsts.ShareVersionZero, nil) require.NoError(t, err) blobTx.Blobs[0] = newBlob - blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -162,36 +160,12 @@ func TestProcessProposal(t *testing.T) { name: "invalid namespace ParityShares", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) require.NoError(t, err) newBlob, err := share.NewBlob(share.ParitySharesNamespace, data, appconsts.ShareVersionZero, nil) require.NoError(t, err) blobTx.Blobs[0] = newBlob - blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) - d.Txs[0] = blobTxBytes - }, - appVersion: appconsts.LatestVersion, - expectedResult: abci.ResponseProcessProposal_REJECT, - }, - { - name: "invalid blob namespace", - input: validData(), - mutator: func(d *tmproto.Data) { - blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) - require.NoError(t, err) - newBlob, err := share.NewBlob(invalidNamespace, data, appconsts.ShareVersionZero, nil) - require.NoError(t, err) - if newBlob == nil { - t.Fatal("newBlob is nil") - } - blobTx.Blobs[0] = newBlob - for _, blob := range blobTx.Blobs { - if blob == nil { - t.Fatal("blob is nil") - } - } - blobTxBytes, err := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) - require.NoError(t, err) + blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes }, appVersion: appconsts.LatestVersion, @@ -201,14 +175,14 @@ func TestProcessProposal(t *testing.T) { name: "pfb namespace version does not match blob", input: validData(), mutator: func(d *tmproto.Data) { - blobTx, _, err := share.UnmarshalBlobTx(blobTxs[0]) + blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) require.NoError(t, err) nsMax, err := share.NewNamespace(share.NamespaceVersionMax, ns1.ID()) - require.Error(t, err) + require.NoError(t, err) newBlob, err := share.NewBlob(nsMax, data, appconsts.ShareVersionZero, nil) require.NoError(t, err) blobTx.Blobs[0] = newBlob - blobTxBytes, _ := share.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) + blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) d.Txs[0] = blobTxBytes d.Hash = calculateNewDataHash(t, d.Txs) }, @@ -220,8 +194,8 @@ func TestProcessProposal(t *testing.T) { input: validData(), mutator: func(d *tmproto.Data) { index := 4 - tx, b := blobfactory.IndexWrappedTxWithInvalidNamespace(t, tmrand.NewRand(), signer, uint32(index)) - blobTx, err := share.MarshalBlobTx(tx, b) + transaction, b := blobfactory.IndexWrappedTxWithInvalidNamespace(t, tmrand.NewRand(), signer, uint32(index)) + blobTx, err := tx.MarshalBlobTx(transaction, b) require.NoError(t, err) // Replace the data with new contents diff --git a/app/validate_txs.go b/app/validate_txs.go index e3a0557ee7..3538e221a0 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -1,7 +1,7 @@ package app import ( - "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,11 +11,11 @@ import ( ) // separateTxs decodes raw tendermint txs into normal and blob txs. -func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []*share.BlobTx) { +func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []*tx.BlobTx) { normalTxs := make([][]byte, 0, len(rawTxs)) - blobTxs := make([]*share.BlobTx, 0, len(rawTxs)) + blobTxs := make([]*tx.BlobTx, 0, len(rawTxs)) for _, rawTx := range rawTxs { - bTx, isBlob, err := share.UnmarshalBlobTx(rawTx) + bTx, isBlob, err := tx.UnmarshalBlobTx(rawTx) if isBlob { if err != nil { panic(err) @@ -75,7 +75,7 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler // filterBlobTxs applies the provided antehandler to each transaction // and removes transactions that return an error. Panics are caught by the checkTxValidity // function used to apply the ante handler. -func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []*share.BlobTx) ([]*share.BlobTx, sdk.Context) { +func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []*tx.BlobTx) ([]*tx.BlobTx, sdk.Context) { n := 0 for _, tx := range txs { sdkTx, err := dec(tx.Tx) @@ -111,11 +111,11 @@ func msgTypes(sdkTx sdk.Tx) []string { return msgNames } -func encodeBlobTxs(blobTxs []*share.BlobTx) [][]byte { +func encodeBlobTxs(blobTxs []*tx.BlobTx) [][]byte { txs := make([][]byte, len(blobTxs)) var err error - for i, tx := range blobTxs { - txs[i], err = share.MarshalBlobTx(tx.Tx, tx.Blobs...) + for i, blobTx := range blobTxs { + txs[i], err = tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index 2756ac0d6f..65d3c6bbb9 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( cosmossdk.io/math v1.3.0 github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 github.com/celestiaorg/go-square v1.1.0 - github.com/celestiaorg/go-square/v2 v2.0.0-rc0 + github.com/celestiaorg/go-square/v2 v2.0.0-rc1 github.com/celestiaorg/knuu v0.14.0 github.com/celestiaorg/nmt v0.22.0 github.com/celestiaorg/rsmt2d v0.14.0 @@ -247,6 +247,7 @@ require ( ) replace ( + github.com/celestiaorg/go-square/v2 => /Users/callum/Developer/go/src/github.com/celestiaorg/go-square github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16 // Pin to ledger-cosmos-go v0.12.4 to avoid a breaking change introduced in v0.13.0 // The following replace statement can be removed when we upgrade to cosmos-sdk >= v0.50.0 diff --git a/go.sum b/go.sum index 4132f2b266..196b3cb03f 100644 --- a/go.sum +++ b/go.sum @@ -324,8 +324,6 @@ github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16 h1:AlBZS4WykzrwfcNbKD+yQQ github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0= github.com/celestiaorg/go-square v1.1.0 h1:K4tBL5PCJwDtpBfyDxxZ3N962aC9VYb5/bw3LjagEtY= github.com/celestiaorg/go-square v1.1.0/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= -github.com/celestiaorg/go-square/v2 v2.0.0-rc0 h1:BNV50WdCcDhIhkgbZ3DGeVYuFePZ5Hu6AxjPWX7XVoI= -github.com/celestiaorg/go-square/v2 v2.0.0-rc0/go.mod h1:eeaU8f8jBpk3ZS/gaDZIlTesJR2F51QAmveNzWH6aEU= github.com/celestiaorg/knuu v0.14.0 h1:96uaDHTzlTfhDLrAiygq9Ewow7UzOzGAbUvMwws1S4A= github.com/celestiaorg/knuu v0.14.0/go.mod h1:5x/+tlLebBSfLmmSBm2ps6aLjnKLn5bOaZpUfI5FpsA= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= diff --git a/pkg/proof/proof.go b/pkg/proof/proof.go index 9a389bf88a..3bbe2d189c 100644 --- a/pkg/proof/proof.go +++ b/pkg/proof/proof.go @@ -13,6 +13,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/v2" "github.com/celestiaorg/go-square/v2/share" + blobtx "github.com/celestiaorg/go-square/v2/tx" "github.com/tendermint/tendermint/crypto/merkle" ) @@ -27,12 +28,12 @@ func NewTxInclusionProof(txs [][]byte, txIndex, appVersion uint64) (ShareProof, if err != nil { return ShareProof{}, err } - + dataSquare, err := builder.Export() if err != nil { return ShareProof{}, err } - + txIndexInt, err := safeConvertUint64ToInt(txIndex) if err != nil { return ShareProof{}, err @@ -47,7 +48,7 @@ func NewTxInclusionProof(txs [][]byte, txIndex, appVersion uint64) (ShareProof, } func getTxNamespace(tx []byte) (ns share.Namespace) { - _, isBlobTx, _ := share.UnmarshalBlobTx(tx) + _, isBlobTx, _ := blobtx.UnmarshalBlobTx(tx) if isBlobTx { return share.PayForBlobNamespace } diff --git a/pkg/user/signer.go b/pkg/user/signer.go index 4670f079aa..0340e3ad57 100644 --- a/pkg/user/signer.go +++ b/pkg/user/signer.go @@ -13,6 +13,7 @@ import ( blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" + blobtx "github.com/celestiaorg/go-square/v2/tx" ) // Signer is struct for building and signing Celestia transactions @@ -106,7 +107,7 @@ func (s *Signer) CreatePayForBlobs(accountName string, blobs []*share.Blob, opts return nil, 0, err } - blobTx, err := share.MarshalBlobTx(txBytes, blobs...) + blobTx, err := blobtx.MarshalBlobTx(txBytes, blobs...) return blobTx, sequence, err } diff --git a/pkg/user/tx_client.go b/pkg/user/tx_client.go index 77eaa06271..0d14128421 100644 --- a/pkg/user/tx_client.go +++ b/pkg/user/tx_client.go @@ -12,6 +12,7 @@ import ( "time" "github.com/celestiaorg/go-square/v2/share" + blobtx "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -355,7 +356,7 @@ func (client *TxClient) broadcastTx(ctx context.Context, txBytes []byte, signer // retryBroadcastingTx creates a new transaction by copying over an existing transaction but creates a new signature with the // new sequence number. It then calls `broadcastTx` and attempts to submit the transaction func (client *TxClient) retryBroadcastingTx(ctx context.Context, txBytes []byte) (*sdktypes.TxResponse, error) { - blobTx, isBlobTx, err := share.UnmarshalBlobTx(txBytes) + blobTx, isBlobTx, err := blobtx.UnmarshalBlobTx(txBytes) if isBlobTx { // only check the error if the bytes are supposed to be of type blob tx if err != nil { @@ -401,7 +402,7 @@ func (client *TxClient) retryBroadcastingTx(ctx context.Context, txBytes []byte) // rewrap the blob tx if it was originally a blob tx if isBlobTx { - newTxBytes, err = share.MarshalBlobTx(newTxBytes, blobTx.Blobs...) + newTxBytes, err = blobtx.MarshalBlobTx(newTxBytes, blobTx.Blobs...) if err != nil { return nil, err } diff --git a/test/txsim/blob.go b/test/txsim/blob.go index f6dc432be7..b03d725d4b 100644 --- a/test/txsim/blob.go +++ b/test/txsim/blob.go @@ -69,7 +69,7 @@ func (s *BlobSequence) Next(_ context.Context, _ grpc.ClientConn, rand *rand.Ran sizes := make([]int, numBlobs) namespaces := make([]share.Namespace, numBlobs) for i := range sizes { - if s.namespace.ID() != nil { + if s.namespace.Bytes() != nil { namespaces[i] = s.namespace } else { // generate a random namespace for the blob diff --git a/test/util/blobfactory/payforblob_factory.go b/test/util/blobfactory/payforblob_factory.go index c405c3ba75..3601ece8ef 100644 --- a/test/util/blobfactory/payforblob_factory.go +++ b/test/util/blobfactory/payforblob_factory.go @@ -11,6 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" @@ -304,7 +305,7 @@ func ComplexBlobTxWithOtherMsgs(t *testing.T, rand *tmrand.Rand, signer *user.Si require.NoError(t, err) - btx, err := share.MarshalBlobTx(rawTx, blobs...) + btx, err := tx.MarshalBlobTx(rawTx, blobs...) require.NoError(t, err) return btx } diff --git a/test/util/direct_tx_gen.go b/test/util/direct_tx_gen.go index 017359360e..f1225f416a 100644 --- a/test/util/direct_tx_gen.go +++ b/test/util/direct_tx_gen.go @@ -11,7 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" @@ -124,7 +124,7 @@ func RandBlobTxsWithManualSequence( } msg, blobs := blobfactory.RandMsgPayForBlobsWithSigner(tmrand.NewRand(), addr.String(), randomizedSize, randomizedBlobCount) - tx, err := signer.CreateTx([]sdk.Msg{msg}, opts...) + transaction, err := signer.CreateTx([]sdk.Msg{msg}, opts...) require.NoError(t, err) if invalidSignature { builder := cfg.NewTxBuilder() @@ -142,11 +142,11 @@ func RandBlobTxsWithManualSequence( }) require.NoError(t, err) - tx, err = signer.EncodeTx(builder.GetTx()) + transaction, err = signer.EncodeTx(builder.GetTx()) require.NoError(t, err) } - cTx, err := share.MarshalBlobTx(tx, blobs...) + cTx, err := tx.MarshalBlobTx(transaction, blobs...) if err != nil { panic(err) } diff --git a/test/util/malicious/out_of_order_builder.go b/test/util/malicious/out_of_order_builder.go index afad4aca45..f12ee03fd8 100644 --- a/test/util/malicious/out_of_order_builder.go +++ b/test/util/malicious/out_of_order_builder.go @@ -9,6 +9,7 @@ import ( "github.com/celestiaorg/go-square/v2" "github.com/celestiaorg/go-square/v2/inclusion" "github.com/celestiaorg/go-square/v2/share" + blobtx "github.com/celestiaorg/go-square/v2/tx" "google.golang.org/protobuf/proto" ) @@ -27,7 +28,7 @@ func Build(txs [][]byte, appVersion uint64, maxSquareSize int, efn ExportFn) (sq normalTxs := make([][]byte, 0, len(txs)) blobTxs := make([][]byte, 0, len(txs)) for idx, tx := range txs { - blobTx, isBlobTx, err := share.UnmarshalBlobTx(tx) + blobTx, isBlobTx, err := blobtx.UnmarshalBlobTx(tx) if isBlobTx { if err != nil { return nil, nil, fmt.Errorf("unmarshaling blob tx %d: %w", idx, err) diff --git a/test/util/testnode/read.go b/test/util/testnode/read.go index a5d0e2d46f..f4b5572a75 100644 --- a/test/util/testnode/read.go +++ b/test/util/testnode/read.go @@ -6,7 +6,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" - "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/rpc/client/http" "github.com/tendermint/tendermint/types" @@ -117,7 +117,7 @@ func DecodeBlockData(data types.Data) ([]sdk.Tx, error) { decoder := encCfg.TxConfig.TxDecoder() txs := make([]sdk.Tx, 0) for _, txBytes := range data.Txs { - blobTx, isBlobTx, err := share.UnmarshalBlobTx(txBytes) + blobTx, isBlobTx, err := tx.UnmarshalBlobTx(txBytes) if isBlobTx { if err != nil { return nil, fmt.Errorf("decoding blob tx: %w", err) diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 720b3cbc0c..cabfc5a0ee 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -14,6 +14,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" @@ -213,7 +214,7 @@ func broadcastPFB(cmd *cobra.Command, b ...*share.Blob) error { return err } - blobTx, err := share.MarshalBlobTx(txBytes, b...) + blobTx, err := tx.MarshalBlobTx(txBytes, b...) if err != nil { return err } diff --git a/x/blob/test/decode_blob_tx_test.go b/x/blob/test/decode_blob_tx_test.go index f58f73b642..9c21596bce 100644 --- a/x/blob/test/decode_blob_tx_test.go +++ b/x/blob/test/decode_blob_tx_test.go @@ -12,7 +12,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/proto/tendermint/blockchain" @@ -79,7 +79,7 @@ func getTestdataBlockResponse(t *testing.T) (resp blockchain.BlockResponse) { } func getTxBytes(txBytes []byte) []byte { - bTx, isBlob, err := share.UnmarshalBlobTx(txBytes) + bTx, isBlob, err := tx.UnmarshalBlobTx(txBytes) if isBlob { if err != nil { panic(err) diff --git a/x/blob/types/blob_tx.go b/x/blob/types/blob_tx.go index 35f9a07427..fb5e2af058 100644 --- a/x/blob/types/blob_tx.go +++ b/x/blob/types/blob_tx.go @@ -5,6 +5,7 @@ import ( "github.com/celestiaorg/go-square/v2/inclusion" "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/tendermint/tendermint/crypto/merkle" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -28,7 +29,7 @@ func NewBlob(ns share.Namespace, data []byte, shareVersion uint8) (*share.Blob, // ValidateBlobTx performs stateless checks on the BlobTx to ensure that the // blobs attached to the transaction are valid. -func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *share.BlobTx, subtreeRootThreshold int) error { +func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *tx.BlobTx, subtreeRootThreshold int) error { if bTx == nil { return ErrNoBlobs } diff --git a/x/blob/types/blob_tx_test.go b/x/blob/types/blob_tx_test.go index ca02ee19e2..b03a6239a7 100644 --- a/x/blob/types/blob_tx_test.go +++ b/x/blob/types/blob_tx_test.go @@ -13,6 +13,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/inclusion" "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/tx" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/assert" @@ -45,7 +46,7 @@ func TestValidateBlobTx(t *testing.T) { type test struct { name string - getTx func() *share.BlobTx + getTx func() *tx.BlobTx expectedErr error } @@ -61,9 +62,9 @@ func TestValidateBlobTx(t *testing.T) { tests := []test{ { name: "normal transaction", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { rawBtx := validRawBtx() - btx, _, err := share.UnmarshalBlobTx(rawBtx) + btx, _, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) return btx }, @@ -71,9 +72,9 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "invalid transaction, mismatched namespace", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { rawBtx := validRawBtx() - btx, _, err := share.UnmarshalBlobTx(rawBtx) + btx, _, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) originalBlob := btx.Blobs[0] @@ -87,11 +88,11 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "invalid transaction, no pfb", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { sendTx := blobfactory.GenerateManyRawSendTxs(signer, 1) b, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) - return &share.BlobTx{ + return &tx.BlobTx{ Tx: sendTx[0], Blobs: []*share.Blob{b}, } @@ -100,9 +101,9 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "mismatched number of pfbs and blobs", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { rawBtx := validRawBtx() - btx, _, err := share.UnmarshalBlobTx(rawBtx) + btx, _, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) blob, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) @@ -113,7 +114,7 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "invalid share commitment", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { b, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) require.NoError(t, err) msg, err := types.NewMsgPayForBlobs( @@ -137,7 +138,7 @@ func TestValidateBlobTx(t *testing.T) { rawTx, err := signer.CreateTx([]sdk.Msg{msg}) require.NoError(t, err) - btx := &share.BlobTx{ + btx := &tx.BlobTx{ Tx: rawTx, Blobs: []*share.Blob{b}, } @@ -147,15 +148,15 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "complex transaction with one send and one pfb", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { sendMsg := banktypes.NewMsgSend(addr, addr, sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))) - tx := blobfactory.ComplexBlobTxWithOtherMsgs( + transaction := blobfactory.ComplexBlobTxWithOtherMsgs( t, tmrand.NewRand(), signer, sendMsg, ) - btx, ok, err := share.UnmarshalBlobTx(tx) + btx, ok, err := tx.UnmarshalBlobTx(transaction) require.NoError(t, err) require.True(t, ok) return btx @@ -164,9 +165,9 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "only send tx", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { sendtx := blobfactory.GenerateManyRawSendTxs(signer, 1)[0] - return &share.BlobTx{ + return &tx.BlobTx{ Tx: sendtx, } }, @@ -174,13 +175,13 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two blobs w/ different namespaces", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), blobfactory.RandBlobsWithNamespace( []share.Namespace{share.RandomBlobNamespace(), share.RandomBlobNamespace()}, []int{100, 100})) require.NoError(t, err) - btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) require.True(t, isBlobTx) return btx @@ -189,14 +190,14 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two large blobs w/ different namespaces", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), blobfactory.RandBlobsWithNamespace( []share.Namespace{share.RandomBlobNamespace(), share.RandomBlobNamespace()}, []int{100000, 1000000}), ) require.NoError(t, err) - btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) require.True(t, isBlobTx) return btx @@ -205,7 +206,7 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with two blobs w/ same namespace", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { ns := share.RandomBlobNamespace() rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), blobfactory.RandBlobsWithNamespace( @@ -213,7 +214,7 @@ func TestValidateBlobTx(t *testing.T) { []int{100, 100}), ) require.NoError(t, err) - btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) require.True(t, isBlobTx) return btx @@ -222,7 +223,7 @@ func TestValidateBlobTx(t *testing.T) { }, { name: "normal transaction with one hundred blobs of the same namespace", - getTx: func() *share.BlobTx { + getTx: func() *tx.BlobTx { count := 100 ns := share.RandomBlobNamespace() sizes := make([]int, count) @@ -237,7 +238,7 @@ func TestValidateBlobTx(t *testing.T) { sizes, )) require.NoError(t, err) - btx, isBlobTx, err := share.UnmarshalBlobTx(rawBtx) + btx, isBlobTx, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) require.True(t, isBlobTx) return btx diff --git a/x/blob/types/estimate_gas_test.go b/x/blob/types/estimate_gas_test.go index 3eeeed1e10..67f67029ee 100644 --- a/x/blob/types/estimate_gas_test.go +++ b/x/blob/types/estimate_gas_test.go @@ -11,7 +11,7 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - "github.com/celestiaorg/go-square/v2/share" + blobtx "github.com/celestiaorg/go-square/v2/tx" "github.com/stretchr/testify/require" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" @@ -44,7 +44,7 @@ func TestPFBGasEstimation(t *testing.T) { gas := blobtypes.DefaultEstimateGas(toUint32(tc.blobSizes)) tx, _, err := signer.CreatePayForBlobs(accnts[0], blobs, user.SetGasLimitAndGasPrice(gas, appconsts.DefaultMinGasPrice)) require.NoError(t, err) - blobTx, ok, err := share.UnmarshalBlobTx(tx) + blobTx, ok, err := blobtx.UnmarshalBlobTx(tx) require.NoError(t, err) require.True(t, ok) resp := testApp.DeliverTx(abci.RequestDeliverTx{ @@ -88,7 +88,7 @@ func FuzzPFBGasEstimation(f *testing.F) { gas := blobtypes.DefaultEstimateGas(toUint32(blobSizes)) tx, _, err := signer.CreatePayForBlobs(accnts[0], blobs, user.SetGasLimitAndGasPrice(gas, appconsts.DefaultMinGasPrice)) require.NoError(t, err) - blobTx, ok, err := share.UnmarshalBlobTx(tx) + blobTx, ok, err := blobtx.UnmarshalBlobTx(tx) require.NoError(t, err) require.True(t, ok) resp := testApp.DeliverTx(abci.RequestDeliverTx{ From 1235a0d988cb3cba8784822aaa5aeed4ade236a3 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 6 Aug 2024 12:14:09 +0200 Subject: [PATCH 3/9] fix remaining tests --- app/test/process_proposal_test.go | 48 --------------------------- go.mod | 3 +- go.sum | 2 ++ x/blob/types/payforblob.go | 2 +- x/blob/types/payforblob_test.go | 55 +++---------------------------- 5 files changed, 8 insertions(+), 102 deletions(-) diff --git a/app/test/process_proposal_test.go b/app/test/process_proposal_test.go index 49c6cec341..c4492dc602 100644 --- a/app/test/process_proposal_test.go +++ b/app/test/process_proposal_test.go @@ -126,21 +126,6 @@ func TestProcessProposal(t *testing.T) { appVersion: appconsts.LatestVersion, expectedResult: abci.ResponseProcessProposal_REJECT, }, - { - name: "invalid namespace TailPadding", - input: validData(), - mutator: func(d *tmproto.Data) { - blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) - require.NoError(t, err) - newBlob, err := share.NewBlob(share.TailPaddingNamespace, data, appconsts.ShareVersionZero, nil) - require.NoError(t, err) - blobTx.Blobs[0] = newBlob - blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) - d.Txs[0] = blobTxBytes - }, - appVersion: appconsts.LatestVersion, - expectedResult: abci.ResponseProcessProposal_REJECT, - }, { name: "invalid namespace TxNamespace", input: validData(), @@ -156,39 +141,6 @@ func TestProcessProposal(t *testing.T) { appVersion: appconsts.LatestVersion, expectedResult: abci.ResponseProcessProposal_REJECT, }, - { - name: "invalid namespace ParityShares", - input: validData(), - mutator: func(d *tmproto.Data) { - blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) - require.NoError(t, err) - newBlob, err := share.NewBlob(share.ParitySharesNamespace, data, appconsts.ShareVersionZero, nil) - require.NoError(t, err) - blobTx.Blobs[0] = newBlob - blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) - d.Txs[0] = blobTxBytes - }, - appVersion: appconsts.LatestVersion, - expectedResult: abci.ResponseProcessProposal_REJECT, - }, - { - name: "pfb namespace version does not match blob", - input: validData(), - mutator: func(d *tmproto.Data) { - blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) - require.NoError(t, err) - nsMax, err := share.NewNamespace(share.NamespaceVersionMax, ns1.ID()) - require.NoError(t, err) - newBlob, err := share.NewBlob(nsMax, data, appconsts.ShareVersionZero, nil) - require.NoError(t, err) - blobTx.Blobs[0] = newBlob - blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) - d.Txs[0] = blobTxBytes - d.Hash = calculateNewDataHash(t, d.Txs) - }, - appVersion: appconsts.LatestVersion, - expectedResult: abci.ResponseProcessProposal_REJECT, - }, { name: "invalid namespace in index wrapper tx", input: validData(), diff --git a/go.mod b/go.mod index 65d3c6bbb9..085d247dc0 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( cosmossdk.io/math v1.3.0 github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 github.com/celestiaorg/go-square v1.1.0 - github.com/celestiaorg/go-square/v2 v2.0.0-rc1 + github.com/celestiaorg/go-square/v2 v2.0.0-rc2 github.com/celestiaorg/knuu v0.14.0 github.com/celestiaorg/nmt v0.22.0 github.com/celestiaorg/rsmt2d v0.14.0 @@ -247,7 +247,6 @@ require ( ) replace ( - github.com/celestiaorg/go-square/v2 => /Users/callum/Developer/go/src/github.com/celestiaorg/go-square github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16 // Pin to ledger-cosmos-go v0.12.4 to avoid a breaking change introduced in v0.13.0 // The following replace statement can be removed when we upgrade to cosmos-sdk >= v0.50.0 diff --git a/go.sum b/go.sum index 196b3cb03f..a5e7ca7552 100644 --- a/go.sum +++ b/go.sum @@ -324,6 +324,8 @@ github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16 h1:AlBZS4WykzrwfcNbKD+yQQ github.com/celestiaorg/cosmos-sdk v1.24.0-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0= github.com/celestiaorg/go-square v1.1.0 h1:K4tBL5PCJwDtpBfyDxxZ3N962aC9VYb5/bw3LjagEtY= github.com/celestiaorg/go-square v1.1.0/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= +github.com/celestiaorg/go-square/v2 v2.0.0-rc2 h1:4D+ASgZGYVCsffc2uhPagACrvNiLZu9/CqNYvnlHCgg= +github.com/celestiaorg/go-square/v2 v2.0.0-rc2/go.mod h1:eeaU8f8jBpk3ZS/gaDZIlTesJR2F51QAmveNzWH6aEU= github.com/celestiaorg/knuu v0.14.0 h1:96uaDHTzlTfhDLrAiygq9Ewow7UzOzGAbUvMwws1S4A= github.com/celestiaorg/knuu v0.14.0/go.mod h1:5x/+tlLebBSfLmmSBm2ps6aLjnKLn5bOaZpUfI5FpsA= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= diff --git a/x/blob/types/payforblob.go b/x/blob/types/payforblob.go index dbffa3432f..c8abc43745 100644 --- a/x/blob/types/payforblob.go +++ b/x/blob/types/payforblob.go @@ -210,7 +210,7 @@ func ValidateBlobs(blobs ...*share.Blob) error { return err } - if len(blob.Data()) == 0 { + if blob.IsEmpty() { return ErrZeroBlobSize } diff --git a/x/blob/types/payforblob_test.go b/x/blob/types/payforblob_test.go index 0b48759cb8..0e63b3c721 100644 --- a/x/blob/types/payforblob_test.go +++ b/x/blob/types/payforblob_test.go @@ -137,11 +137,6 @@ func TestValidateBasic(t *testing.T) { msg: noShareCommitments, wantErr: types.ErrNoShareCommitments, }, - { - name: "invalid namespace version", - msg: invalidNamespaceVersionMsgPayForBlobs(t), - wantErr: types.ErrInvalidNamespaceVersion, - }, } for _, tt := range tests { @@ -188,40 +183,6 @@ func validMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { return pfb } -func invalidNamespaceVersionMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { - signer, err := testnode.NewOfflineSigner() - require.NoError(t, err) - ns1 := share.NamespaceVersionZeroPrefix - ns1 = append(ns1, bytes.Repeat([]byte{0x01}, share.NamespaceVersionZeroIDSize)...) - ns := share.MustNewNamespace(255, ns1) - data := bytes.Repeat([]byte{2}, totalBlobSize(appconsts.ContinuationSparseShareContentSize*12)) - - blob, err := share.NewV0Blob(ns, data) - require.NoError(t, err) - blobs := []*share.Blob{blob} - - commitments, err := inclusion.CreateCommitments(blobs, merkle.HashFromByteSlices, appconsts.DefaultSubtreeRootThreshold) - require.NoError(t, err) - - namespaces, sizes, shareVersions := types.ExtractBlobComponents(blobs) - - namespacesBytes := make([][]byte, len(namespaces)) - for idx, namespace := range namespaces { - namespacesBytes[idx] = namespace.Bytes() - } - - addr := signer.Account(testfactory.TestAccName).Address() - pfb := &types.MsgPayForBlobs{ - Signer: addr.String(), - Namespaces: namespacesBytes, - ShareCommitments: commitments, - BlobSizes: sizes, - ShareVersions: shareVersions, - } - - return pfb -} - func TestNewMsgPayForBlobs(t *testing.T) { type testCase struct { name string @@ -252,14 +213,6 @@ func TestNewMsgPayForBlobs(t *testing.T) { }, expectedErr: false, }, - { - name: "unsupported share version returns an error", - signer: testfactory.TestAccAddr, - blobs: []*share.Blob{ - mustNewBlob(t, ns1, tmrand.Bytes(1000000), 10, nil), - }, - expectedErr: true, - }, { name: "msg PFB with tx namespace returns an error", signer: testfactory.TestAccAddr, @@ -319,13 +272,13 @@ func TestValidateBlobs(t *testing.T) { expectError: false, }, { - name: "invalid share version", - blob: mustNewBlob(t, share.RandomBlobNamespace(), []byte{1}, 4, nil), + name: "invalid namespace", + blob: mustNewBlob(t, share.TxNamespace, []byte{1}, appconsts.DefaultShareVersion, nil), expectError: true, }, { - name: "invalid namespace", - blob: mustNewBlob(t, share.TxNamespace, []byte{1}, appconsts.DefaultShareVersion, nil), + name: "empty blob", + blob: &share.Blob{}, expectError: true, }, } From 7f43c2bec7947ad357a079ee5580f784822955df Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 6 Aug 2024 13:59:18 +0200 Subject: [PATCH 4/9] resolve merge conflicts --- app/test/std_sdk_test.go | 4 ++-- go.mod | 1 - go.sum | 2 -- pkg/da/data_availability_header.go | 11 ++++++----- pkg/proof/proof.go | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/test/std_sdk_test.go b/app/test/std_sdk_test.go index 85be2e9d7d..b9d1c03af3 100644 --- a/app/test/std_sdk_test.go +++ b/app/test/std_sdk_test.go @@ -15,7 +15,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testnode" "github.com/celestiaorg/celestia-app/v3/x/minfee" signal "github.com/celestiaorg/celestia-app/v3/x/signal/types" - "github.com/celestiaorg/go-square/namespace" + "github.com/celestiaorg/go-square/v2/share" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -365,7 +365,7 @@ func (s *StandardSDKIntegrationTestSuite) TestGRPCQueries() { txSubmitter, err := user.SetupTxClient(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, s.ecfg) require.NoError(t, err) - blobs := blobfactory.RandBlobsWithNamespace([]namespace.Namespace{namespace.RandomNamespace()}, []int{1000}) + blobs := blobfactory.RandBlobsWithNamespace([]share.Namespace{share.RandomNamespace()}, []int{1000}) res, err := txSubmitter.SubmitPayForBlob(s.cctx.GoContext(), blobs, blobfactory.DefaultTxOpts()...) require.NoError(t, err) diff --git a/go.mod b/go.mod index e2e16354af..e5c8833f5b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 - github.com/celestiaorg/go-square v1.1.0 github.com/celestiaorg/go-square/v2 v2.0.0-rc2 github.com/celestiaorg/knuu v0.14.0 github.com/celestiaorg/nmt v0.22.1 diff --git a/go.sum b/go.sum index 4b670a8ff7..308c53e224 100644 --- a/go.sum +++ b/go.sum @@ -322,8 +322,6 @@ github.com/celestiaorg/celestia-core v1.39.0-tm-v0.34.29 h1:9Co/2peu4+9S6KMVNPFS github.com/celestiaorg/celestia-core v1.39.0-tm-v0.34.29/go.mod h1:5jJ5magtH7gQOwSYfS/m5fliIS7irKunLV7kLNaD8o0= github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16 h1:SeQ7Y/CyOcUMKo7mQiexaj/pZ/xIgyuZFIwYZwpSkWE= github.com/celestiaorg/cosmos-sdk v1.24.1-sdk-v0.46.16/go.mod h1:Bpl1LSWiDpQumgOhhMTZBMopqa0j7fRasIhvTZB44P0= -github.com/celestiaorg/go-square v1.1.0 h1:K4tBL5PCJwDtpBfyDxxZ3N962aC9VYb5/bw3LjagEtY= -github.com/celestiaorg/go-square v1.1.0/go.mod h1:1EXMErhDrWJM8B8V9hN7dqJ2kUTClfwdqMOmF9yQUa0= github.com/celestiaorg/go-square/v2 v2.0.0-rc2 h1:4D+ASgZGYVCsffc2uhPagACrvNiLZu9/CqNYvnlHCgg= github.com/celestiaorg/go-square/v2 v2.0.0-rc2/go.mod h1:eeaU8f8jBpk3ZS/gaDZIlTesJR2F51QAmveNzWH6aEU= github.com/celestiaorg/knuu v0.14.0 h1:96uaDHTzlTfhDLrAiygq9Ewow7UzOzGAbUvMwws1S4A= diff --git a/pkg/da/data_availability_header.go b/pkg/da/data_availability_header.go index 421efdaac6..9f32481571 100644 --- a/pkg/da/data_availability_header.go +++ b/pkg/da/data_availability_header.go @@ -6,7 +6,8 @@ import ( "fmt" "math" - "github.com/celestiaorg/go-square/shares" + "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/types" @@ -64,7 +65,7 @@ func NewDataAvailabilityHeader(eds *rsmt2d.ExtendedDataSquare) (DataAvailability func ExtendShares(s [][]byte) (*rsmt2d.ExtendedDataSquare, error) { // Check that the length of the square is a power of 2. - if !shares.IsPowerOfTwo(len(s)) { + if !square.IsPowerOfTwo(len(s)) { return nil, fmt.Errorf("number of shares is not a power of 2: got %d", len(s)) } squareSize := SquareSize(len(s)) @@ -191,13 +192,13 @@ func MinDataAvailabilityHeader() DataAvailabilityHeader { // MinShares returns one tail-padded share. func MinShares() [][]byte { - return shares.ToBytes(EmptySquareShares()) + return share.ToBytes(EmptySquareShares()) } // EmptySquare is a copy of the function defined in the square package to avoid // a circular dependency. TODO deduplicate -func EmptySquareShares() []shares.Share { - return shares.TailPaddingShares(appconsts.MinShareCount) +func EmptySquareShares() []share.Share { + return share.TailPaddingShares(appconsts.MinShareCount) } // SquareSize is a copy of the function defined in the square package to avoid diff --git a/pkg/proof/proof.go b/pkg/proof/proof.go index 48d82a36bc..fa6f66fcd9 100644 --- a/pkg/proof/proof.go +++ b/pkg/proof/proof.go @@ -28,12 +28,12 @@ func NewTxInclusionProof(txs [][]byte, txIndex, appVersion uint64) (ShareProof, if err != nil { return ShareProof{}, err } - + dataSquare, err := builder.Export() if err != nil { return ShareProof{}, err } - + txIndexInt, err := safeConvertUint64ToInt(txIndex) if err != nil { return ShareProof{}, err From 226a98c4cc5e5a7c7981b7e47cccf57d709e578a Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 6 Aug 2024 17:23:26 +0200 Subject: [PATCH 5/9] resolve comments --- proto/celestia/core/v1/blob/blob.proto | 24 ------------------------ specs/src/specs/namespace.md | 2 +- specs/src/specs/shares.md | 2 +- x/blob/ante/blob_share_decorator_test.go | 4 ++-- x/blob/client/cli/payforblob.go | 4 ++-- 5 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 proto/celestia/core/v1/blob/blob.proto diff --git a/proto/celestia/core/v1/blob/blob.proto b/proto/celestia/core/v1/blob/blob.proto deleted file mode 100644 index b4d67d04ec..0000000000 --- a/proto/celestia/core/v1/blob/blob.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; -package celestia.core.v1.blob; - -option go_package = "github.com/celestiaorg/go-square/v2/share"; - -// Blob (named after binary large object) is a chunk of data submitted by a user -// to be published to the Celestia blockchain. The data of a Blob is published -// to a namespace and is encoded into shares based on the format specified by -// share_version. -message Blob { - bytes namespace_id = 1; - bytes data = 2; - uint32 share_version = 3; - uint32 namespace_version = 4; -} - -// BlobTx wraps an encoded sdk.Tx with a second field to contain blobs of data. -// The raw bytes of the blobs are not signed over, instead we verify each blob -// using the relevant MsgPayForBlobs that is signed over in the encoded sdk.Tx. -message BlobTx { - bytes tx = 1; - repeated Blob blobs = 2; - string type_id = 3; -} \ No newline at end of file diff --git a/specs/src/specs/namespace.md b/specs/src/specs/namespace.md index c035bee215..ee761c327f 100644 --- a/specs/src/specs/namespace.md +++ b/specs/src/specs/namespace.md @@ -95,7 +95,7 @@ Among the potential consequences is the _Woods Attack_, as elaborated in this fo ## Implementation See the [namespace implementation in go-square](https://github.com/celestiaorg/go-square/v2/share/be3c2801e902a0f90f694c062b9c4e6a7e01154e/namespace/namespace.go). -For the most recent version, which may not reflect the current specifications, refer to [the latest namespace code](https://github.com/celestiaorg/go-square/v2/share/main/share/namespace.go). +For the most recent version, which may not reflect the current specifications, refer to [the latest namespace code](https://github.com/celestiaorg/go-square/main/share/namespace.go). ## Go Definition diff --git a/specs/src/specs/shares.md b/specs/src/specs/shares.md index f3139596e3..ee469f25f7 100644 --- a/specs/src/specs/shares.md +++ b/specs/src/specs/shares.md @@ -112,7 +112,7 @@ Share splitting is the process of converting a blob into a share sequence. The p ## Implementation -See [go-square/shares](https://github.com/celestiaorg/go-square/v2/tree/be3c2801e902a0f90f694c062b9c4e6a7e01154e/shares). +See [go-square/shares](https://github.com/celestiaorg/go-square/tree/be3c2801e902a0f90f694c062b9c4e6a7e01154e/shares). ## References diff --git a/x/blob/ante/blob_share_decorator_test.go b/x/blob/ante/blob_share_decorator_test.go index bfcf899f43..6c788e1935 100644 --- a/x/blob/ante/blob_share_decorator_test.go +++ b/x/blob/ante/blob_share_decorator_test.go @@ -83,7 +83,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with many single byte blobs should fit", pfb: &blob.MsgPayForBlobs{ - // 4095 blobs each of size 1 byte should occupy 4095 share. + // 4095 blobs each of size 1 byte should occupy 4095 shares. // When square size is 64, there are 4095 shares available to // blob shares so we don't expect an error for this test case. BlobSizes: repeat(4095, 1), @@ -93,7 +93,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with too many single byte blobs should not fit", pfb: &blob.MsgPayForBlobs{ - // 4096 blobs each of size 1 byte should occupy 4096 share. + // 4096 blobs each of size 1 byte should occupy 4096 shares. // When square size is 64, there are 4095 shares available to // blob shares so we expect an error for this test case. BlobSizes: repeat(4096, 1), diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index cabfc5a0ee..1439f92dde 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -24,11 +24,11 @@ import ( const ( // FlagShareVersion allows the user to override the share version when - // submitting a PayForshare. + // submitting a PayForBlob. FlagShareVersion = "share-version" // FlagNamespaceVersion allows the user to override the namespace version when - // submitting a PayForshare. + // submitting a PayForBlob. FlagNamespaceVersion = "namespace-version" // FlagFileInput allows the user to provide the path to a JSON file for From 521d7a299800ea3f94bbb746062a90221600d952 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 7 Aug 2024 17:15:22 +0200 Subject: [PATCH 6/9] feat!: support authored blobs --- app/default_overrides.go | 3 +- app/errors/insufficient_gas_price_test.go | 2 +- app/errors/nonce_mismatch_test.go | 2 +- app/test/check_tx_test.go | 30 ++++++++++- app/test/consistent_apphash_test.go | 3 ++ app/test/fuzz_abci_test.go | 7 +-- app/test/integration_test.go | 2 +- app/test/process_proposal_test.go | 44 +++++++++++++++- app/test/square_size_test.go | 3 +- app/test/std_sdk_test.go | 2 +- pkg/appconsts/global_consts.go | 57 ++------------------- pkg/appconsts/initial_consts.go | 8 ++- pkg/da/data_availability_header_test.go | 6 +-- pkg/inclusion/nmt_caching_test.go | 2 +- pkg/user/signer.go | 4 ++ pkg/wrapper/nmt_wrapper.go | 14 ++--- pkg/wrapper/nmt_wrapper_test.go | 8 +-- test/cmd/txsim/cli_test.go | 2 +- test/txsim/blob.go | 39 ++++++++++---- test/util/blobfactory/payforblob_factory.go | 28 +++++++--- test/util/malicious/out_of_order_builder.go | 4 +- test/util/malicious/tree.go | 5 +- test/util/test_app.go | 7 +-- test/util/testfactory/blob.go | 6 +-- test/util/testfactory/common.go | 3 +- test/util/testnode/config.go | 2 +- test/util/testnode/node_interaction_api.go | 2 +- x/blob/ante/ante_test.go | 11 ++-- x/blob/client/cli/payforblob.go | 27 ++++++---- x/blob/keeper/gas_test.go | 12 ++--- x/blob/keeper/keeper_test.go | 2 +- x/blob/types/blob_tx.go | 34 +++++++++--- x/blob/types/blob_tx_test.go | 32 ++++++------ x/blob/types/errors.go | 1 + x/blob/types/payforblob.go | 17 +++--- x/blob/types/payforblob_test.go | 23 ++++++--- 36 files changed, 277 insertions(+), 177 deletions(-) diff --git a/app/default_overrides.go b/app/default_overrides.go index eb21c62af4..0ceedaeee1 100644 --- a/app/default_overrides.go +++ b/app/default_overrides.go @@ -8,6 +8,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/x/mint" minttypes "github.com/celestiaorg/celestia-app/v3/x/mint/types" + "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/codec" serverconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" @@ -268,7 +269,7 @@ func DefaultConsensusConfig() *tmcfg.Config { // We set a loose upper bound on what we expect the transaction to // be based on the upper bound size of the entire block for the given // version. This acts as a first line of DoS protection - upperBoundBytes := appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * appconsts.ContinuationSparseShareContentSize + upperBoundBytes := appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize cfg.Mempool.MaxTxBytes = upperBoundBytes cfg.Mempool.MaxTxsBytes = int64(upperBoundBytes) * cfg.Mempool.TTLNumBlocks cfg.Mempool.Version = "v1" // prioritized mempool diff --git a/app/errors/insufficient_gas_price_test.go b/app/errors/insufficient_gas_price_test.go index 049f1afb00..473465ba23 100644 --- a/app/errors/insufficient_gas_price_test.go +++ b/app/errors/insufficient_gas_price_test.go @@ -40,7 +40,7 @@ func TestInsufficientMinGasPriceIntegration(t *testing.T) { signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence())) require.NoError(t, err) - b, err := blob.NewBlob(share.RandomNamespace(), []byte("hello world"), 0) + b, err := blob.NewV0Blob(share.RandomNamespace(), []byte("hello world")) require.NoError(t, err) msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, b) diff --git a/app/errors/nonce_mismatch_test.go b/app/errors/nonce_mismatch_test.go index 0f8744ae03..a61dacf6a6 100644 --- a/app/errors/nonce_mismatch_test.go +++ b/app/errors/nonce_mismatch_test.go @@ -35,7 +35,7 @@ func TestNonceMismatchIntegration(t *testing.T) { signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence()+1)) require.NoError(t, err) - b, err := blob.NewBlob(share.RandomNamespace(), []byte("hello world"), 0) + b, err := blob.NewV0Blob(share.RandomNamespace(), []byte("hello world")) require.NoError(t, err) msg, err := blob.NewMsgPayForBlobs(signer.Account(account).Address().String(), appconsts.LatestVersion, b) diff --git a/app/test/check_tx_test.go b/app/test/check_tx_test.go index 14b7a40f89..45ac426d88 100644 --- a/app/test/check_tx_test.go +++ b/app/test/check_tx_test.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto/keyring" + sdk "github.com/cosmos/cosmos-sdk/types" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/celestiaorg/celestia-app/v3/app" @@ -14,6 +15,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/user" testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/go-square/v2/tx" @@ -30,7 +32,7 @@ func TestCheckTx(t *testing.T) { ns1, err := share.NewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) require.NoError(t, err) - accs := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"} + accs := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"} testApp, kr := testutil.SetupTestAppWithGenesisValSet(app.DefaultConsensusParams(), accs...) testApp.Commit() @@ -182,6 +184,32 @@ func TestCheckTx(t *testing.T) { }, expectedABCICode: blobtypes.ErrBlobsTooLarge.ABCICode(), }, + { + name: "v1 blob with invalid signer", + checkType: abci.CheckTxType_New, + getTx: func() []byte { + signer := createSigner(t, kr, accs[10], encCfg.TxConfig, 11) + blob, err := share.NewV1Blob(share.RandomBlobNamespace(), []byte("data"), testnode.RandomAddress().(sdk.AccAddress)) + require.NoError(t, err) + blobTx, _, err := signer.CreatePayForBlobs(accs[10], []*share.Blob{blob}, opts...) + require.NoError(t, err) + return blobTx + }, + expectedABCICode: blobtypes.ErrInvalidBlobSigner.ABCICode(), + }, + { + name: "v1 blob with valid signer", + checkType: abci.CheckTxType_New, + getTx: func() []byte { + signer := createSigner(t, kr, accs[10], encCfg.TxConfig, 11) + blob, err := share.NewV1Blob(share.RandomBlobNamespace(), []byte("data"), signer.Account(accs[10]).Address()) + require.NoError(t, err) + blobTx, _, err := signer.CreatePayForBlobs(accs[10], []*share.Blob{blob}, opts...) + require.NoError(t, err) + return blobTx + }, + expectedABCICode: abci.CodeTypeOK, + }, } for _, tt := range tests { diff --git a/app/test/consistent_apphash_test.go b/app/test/consistent_apphash_test.go index 20fef6cbf5..972f42da58 100644 --- a/app/test/consistent_apphash_test.go +++ b/app/test/consistent_apphash_test.go @@ -381,6 +381,9 @@ func executeTxs(testApp *app.App, encodedBlobTx []byte, encodedSdkTxs [][]byte, // Dynamically increase time so the validator can be unjailed (1m duration) Time: genesisTime.Add(time.Duration(height) * time.Minute), }) + if len(resPrepareProposal.BlockData.Txs) != len(encodedSdkTxs) { + return nil, nil, fmt.Errorf("PrepareProposal removed transactions. Was %d, now %d", len(encodedSdkTxs), len(resPrepareProposal.BlockData.Txs)) + } dataHash := resPrepareProposal.BlockData.Hash diff --git a/app/test/fuzz_abci_test.go b/app/test/fuzz_abci_test.go index 96ec81b7ea..e6bd0127f0 100644 --- a/app/test/fuzz_abci_test.go +++ b/app/test/fuzz_abci_test.go @@ -9,6 +9,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/user" testutil "github.com/celestiaorg/celestia-app/v3/test/util" + "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmrand "github.com/tendermint/tendermint/libs/rand" @@ -62,17 +63,17 @@ func TestPrepareProposalConsistency(t *testing.T) { }, { "max", - maxShareCount * appconsts.ContinuationSparseShareContentSize, + maxShareCount * share.ContinuationSparseShareContentSize, appconsts.DefaultSquareSizeUpperBound, }, { "larger MaxBytes than SquareSize", - maxShareCount * appconsts.ContinuationSparseShareContentSize, + maxShareCount * share.ContinuationSparseShareContentSize, appconsts.DefaultGovMaxSquareSize, }, { "smaller MaxBytes than SquareSize", - 32 * 32 * appconsts.ContinuationSparseShareContentSize, + 32 * 32 * share.ContinuationSparseShareContentSize, appconsts.DefaultGovMaxSquareSize, }, } diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 6988843357..aec6d86e46 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -289,7 +289,7 @@ func (s *IntegrationTestSuite) TestEmptyBlock() { func newBlobWithSize(size int) *share.Blob { ns := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) data := tmrand.Bytes(size) - blob, err := share.NewBlob(ns, data, appconsts.ShareVersionZero, nil) + blob, err := share.NewBlob(ns, data, share.ShareVersionZero, nil) if err != nil { panic(err) } diff --git a/app/test/process_proposal_test.go b/app/test/process_proposal_test.go index c4492dc602..df390dcdfa 100644 --- a/app/test/process_proposal_test.go +++ b/app/test/process_proposal_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -24,6 +25,8 @@ import ( testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" + blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2" "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/go-square/v2/tx" @@ -117,7 +120,7 @@ func TestProcessProposal(t *testing.T) { mutator: func(d *tmproto.Data) { blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) require.NoError(t, err) - newBlob, err := share.NewBlob(ns1, data, appconsts.ShareVersionZero, nil) + newBlob, err := share.NewBlob(ns1, data, share.ShareVersionZero, nil) require.NoError(t, err) blobTx.Blobs[0] = newBlob blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) @@ -132,7 +135,7 @@ func TestProcessProposal(t *testing.T) { mutator: func(d *tmproto.Data) { blobTx, _, err := tx.UnmarshalBlobTx(blobTxs[0]) require.NoError(t, err) - newBlob, err := share.NewBlob(share.TxNamespace, data, appconsts.ShareVersionZero, nil) + newBlob, err := share.NewBlob(share.TxNamespace, data, share.ShareVersionZero, nil) require.NoError(t, err) blobTx.Blobs[0] = newBlob blobTxBytes, _ := tx.MarshalBlobTx(blobTx.Tx, blobTx.Blobs...) @@ -259,6 +262,43 @@ func TestProcessProposal(t *testing.T) { appVersion: appconsts.LatestVersion, expectedResult: abci.ResponseProcessProposal_REJECT, }, + { + name: "valid v1 authored blob", + input: validData(), + mutator: func(d *tmproto.Data) { + addr := signer.Account(accounts[0]).Address() + blob, err := share.NewV1Blob(ns1, data, addr) + require.NoError(t, err) + rawTx, _, err := signer.CreatePayForBlobs(accounts[0], []*share.Blob{blob}, user.SetGasLimit(100000), user.SetFee(100000)) + require.NoError(t, err) + d.Txs[0] = rawTx + d.Hash = calculateNewDataHash(t, d.Txs) + }, + appVersion: appconsts.LatestVersion, + expectedResult: abci.ResponseProcessProposal_ACCEPT, + }, + { + name: "v1 authored blob with invalid signer", + input: validData(), + mutator: func(d *tmproto.Data) { + addr := signer.Account(accounts[0]).Address() + falseAddr := testnode.RandomAddress().(sdk.AccAddress) + blob, err := share.NewV1Blob(ns1, data, falseAddr) + require.NoError(t, err) + msg, err := blobtypes.NewMsgPayForBlobs(addr.String(), appconsts.LatestVersion, blob) + require.NoError(t, err) + + rawTx, err := signer.CreateTx([]sdk.Msg{msg}, user.SetGasLimit(100000), user.SetFee(100000)) + require.NoError(t, err) + + blobTxBytes, err := tx.MarshalBlobTx(rawTx, blob) + require.NoError(t, err) + d.Txs[0] = blobTxBytes + d.Hash = calculateNewDataHash(t, d.Txs) + }, + appVersion: appconsts.LatestVersion, + expectedResult: abci.ResponseProcessProposal_REJECT, + }, } for _, tt := range tests { diff --git a/app/test/square_size_test.go b/app/test/square_size_test.go index fa529b519f..8e7a6643cc 100644 --- a/app/test/square_size_test.go +++ b/app/test/square_size_test.go @@ -16,6 +16,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" oldgov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -86,7 +87,7 @@ func (s *SquareSizeIntegrationTest) TestSquareSizeUpperBound() { { name: "gov square size == hardcoded max", govMaxSquareSize: appconsts.DefaultSquareSizeUpperBound, - maxBytes: appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * appconsts.ContinuationSparseShareContentSize, + maxBytes: appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize, expectedMaxSquareSize: appconsts.DefaultSquareSizeUpperBound, }, } diff --git a/app/test/std_sdk_test.go b/app/test/std_sdk_test.go index b9d1c03af3..1ef3766e8a 100644 --- a/app/test/std_sdk_test.go +++ b/app/test/std_sdk_test.go @@ -365,7 +365,7 @@ func (s *StandardSDKIntegrationTestSuite) TestGRPCQueries() { txSubmitter, err := user.SetupTxClient(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, s.ecfg) require.NoError(t, err) - blobs := blobfactory.RandBlobsWithNamespace([]share.Namespace{share.RandomNamespace()}, []int{1000}) + blobs := blobfactory.RandV0BlobsWithNamespace([]share.Namespace{share.RandomNamespace()}, []int{1000}) res, err := txSubmitter.SubmitPayForBlob(s.cctx.GoContext(), blobs, blobfactory.DefaultTxOpts()...) require.NoError(t, err) diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index a7004d0e4d..340f651840 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -1,9 +1,7 @@ package appconsts import ( - "math" - - ns "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/tendermint/tendermint/pkg/consts" ) @@ -13,55 +11,9 @@ import ( // // They can not change throughout the lifetime of a network. const ( - // NamespaceVersionSize is the size of a namespace version in bytes. - NamespaceVersionSize = ns.NamespaceVersionSize - // NamespaceVersionMaxValue is the maximum value a namespace version can be. - // This const must be updated if NamespaceVersionSize is changed. - NamespaceVersionMaxValue = math.MaxUint8 - - // NamespaceIDSize is the size of a namespace ID in bytes. - NamespaceIDSize = ns.NamespaceIDSize - - // NamespaceSize is the size of a namespace (version + ID) in bytes. - NamespaceSize = ns.NamespaceSize - - // ShareSize is the size of a share in bytes. - ShareSize = 512 - - // ShareInfoBytes is the number of bytes reserved for information. The info - // byte contains the share version and a sequence start indicator. - ShareInfoBytes = 1 - - // SequenceLenBytes is the number of bytes reserved for the sequence length - // that is present in the first share of a sequence. - SequenceLenBytes = 4 - - // ShareVersionZero is the first share version format. - ShareVersionZero = uint8(0) - // DefaultShareVersion is the defacto share version. Use this if you are // unsure of which version to use. - DefaultShareVersion = ShareVersionZero - - // CompactShareReservedBytes is the number of bytes reserved for the location of - // the first unit (transaction, ISR) in a compact share. - CompactShareReservedBytes = 4 - - // FirstCompactShareContentSize is the number of bytes usable for data in - // the first compact share of a sequence. - FirstCompactShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes - SequenceLenBytes - CompactShareReservedBytes - - // ContinuationCompactShareContentSize is the number of bytes usable for - // data in a continuation compact share of a sequence. - ContinuationCompactShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes - CompactShareReservedBytes - - // FirstSparseShareContentSize is the number of bytes usable for data in the - // first sparse share of a sequence. - FirstSparseShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes - SequenceLenBytes - - // ContinuationSparseShareContentSize is the number of bytes usable for data - // in a continuation sparse share of a sequence. - ContinuationSparseShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes + DefaultShareVersion = share.ShareVersionZero // MinSquareSize is the smallest original square width. MinSquareSize = 1 @@ -70,9 +22,6 @@ const ( // data square. MinShareCount = MinSquareSize * MinSquareSize - // MaxShareVersion is the maximum value a share version can be. - MaxShareVersion = 127 - // BondDenom defines the native staking denomination BondDenom = "utia" ) @@ -92,7 +41,7 @@ var ( DefaultCodec = rsmt2d.NewLeoRSCodec // SupportedShareVersions is a list of supported share versions. - SupportedShareVersions = []uint8{ShareVersionZero} + SupportedShareVersions = share.SupportedShareVersions ) // HashLength returns the length of a hash in bytes. diff --git a/pkg/appconsts/initial_consts.go b/pkg/appconsts/initial_consts.go index 09e3a164a4..12a660dfbc 100644 --- a/pkg/appconsts/initial_consts.go +++ b/pkg/appconsts/initial_consts.go @@ -1,6 +1,10 @@ package appconsts -import "time" +import ( + "time" + + "github.com/celestiaorg/go-square/v2/share" +) // The following defaults correspond to initial parameters of the network that can be changed, not via app versions // but other means such as on-chain governance, or the nodes local config @@ -11,7 +15,7 @@ const ( // DefaultMaxBytes is the default value for the governance modifiable // maximum number of bytes allowed in a valid block. - DefaultMaxBytes = DefaultGovMaxSquareSize * DefaultGovMaxSquareSize * ContinuationSparseShareContentSize + DefaultMaxBytes = DefaultGovMaxSquareSize * DefaultGovMaxSquareSize * share.ContinuationSparseShareContentSize // DefaultGasPerBlobByte is the default gas cost deducted per byte of blob // included in a PayForBlobs txn diff --git a/pkg/da/data_availability_header_test.go b/pkg/da/data_availability_header_test.go index 7bd38addb5..fa73aeaa5e 100644 --- a/pkg/da/data_availability_header_test.go +++ b/pkg/da/data_availability_header_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/go-square/v2/share" + sh "github.com/celestiaorg/go-square/v2/share" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -245,7 +245,7 @@ func TestSquareSize(t *testing.T) { // generateShares generates count number of shares with a constant namespace and // share contents. func generateShares(count int) (shares [][]byte) { - ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) + ns1 := sh.MustNewV0Namespace(bytes.Repeat([]byte{1}, sh.NamespaceVersionZeroIDSize)) for i := 0; i < count; i++ { share := generateShare(ns1.Bytes()) @@ -256,7 +256,7 @@ func generateShares(count int) (shares [][]byte) { } func generateShare(namespace []byte) (share []byte) { - remainder := bytes.Repeat([]byte{0xFF}, appconsts.ShareSize-len(namespace)) + remainder := bytes.Repeat([]byte{0xFF}, sh.ShareSize-len(namespace)) share = append(share, namespace...) share = append(share, remainder...) return share diff --git a/pkg/inclusion/nmt_caching_test.go b/pkg/inclusion/nmt_caching_test.go index 80bb19d5b6..5e47ecf36f 100644 --- a/pkg/inclusion/nmt_caching_test.go +++ b/pkg/inclusion/nmt_caching_test.go @@ -190,7 +190,7 @@ func chunkSlice(slice [][]byte, chunkSize int) [][][]byte { // namespace. func generateRandNamespacedRawData(count int) (result [][]byte) { for i := 0; i < count; i++ { - rawData := tmrand.Bytes(appconsts.ShareSize) + rawData := tmrand.Bytes(share.ShareSize) namespace := share.RandomBlobNamespace().Bytes() copy(rawData, namespace) result = append(result, rawData) diff --git a/pkg/user/signer.go b/pkg/user/signer.go index 0340e3ad57..4b39c9bd31 100644 --- a/pkg/user/signer.go +++ b/pkg/user/signer.go @@ -92,6 +92,10 @@ func (s *Signer) CreatePayForBlobs(accountName string, blobs []*share.Blob, opts return nil, 0, fmt.Errorf("account %s not found", accountName) } + if err := blobtypes.ValidateBlobs(blobs...); err != nil { + return nil, 0, err + } + msg, err := blobtypes.NewMsgPayForBlobs(acc.address.String(), s.appVersion, blobs...) if err != nil { return nil, 0, err diff --git a/pkg/wrapper/nmt_wrapper.go b/pkg/wrapper/nmt_wrapper.go index 82ad3ad94b..0da772db25 100644 --- a/pkg/wrapper/nmt_wrapper.go +++ b/pkg/wrapper/nmt_wrapper.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - appns "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" @@ -56,7 +56,7 @@ func NewErasuredNamespacedMerkleTree(squareSize uint64, axisIndex uint, options if squareSize == 0 { panic("cannot create a ErasuredNamespacedMerkleTree of squareSize == 0") } - options = append(options, nmt.NamespaceIDSize(appconsts.NamespaceSize)) + options = append(options, nmt.NamespaceIDSize(share.NamespaceSize)) options = append(options, nmt.IgnoreMaxNamespace(true)) tree := nmt.New(appconsts.NewBaseHashFunc(), options...) return ErasuredNamespacedMerkleTree{squareSize: squareSize, options: options, tree: tree, axisIndex: uint64(axisIndex), shareIndex: 0} @@ -94,16 +94,16 @@ func (w *ErasuredNamespacedMerkleTree) Push(data []byte) error { if w.axisIndex+1 > 2*w.squareSize || w.shareIndex+1 > 2*w.squareSize { return fmt.Errorf("pushed past predetermined square size: boundary at %d index at %d %d", 2*w.squareSize, w.axisIndex, w.shareIndex) } - if len(data) < appconsts.NamespaceSize { + if len(data) < share.NamespaceSize { return fmt.Errorf("data is too short to contain namespace ID") } - nidAndData := make([]byte, appconsts.NamespaceSize+len(data)) - copy(nidAndData[appconsts.NamespaceSize:], data) + nidAndData := make([]byte, share.NamespaceSize+len(data)) + copy(nidAndData[share.NamespaceSize:], data) // use the parity namespace if the cell is not in Q0 of the extended data square if w.isQuadrantZero() { - copy(nidAndData[:appconsts.NamespaceSize], data[:appconsts.NamespaceSize]) + copy(nidAndData[:share.NamespaceSize], data[:share.NamespaceSize]) } else { - copy(nidAndData[:appconsts.NamespaceSize], appns.ParitySharesNamespace.Bytes()) + copy(nidAndData[:share.NamespaceSize], share.ParitySharesNamespace.Bytes()) } err := w.tree.Push(nidAndData) if err != nil { diff --git a/pkg/wrapper/nmt_wrapper_test.go b/pkg/wrapper/nmt_wrapper_test.go index ea807fe90f..0686d59e52 100644 --- a/pkg/wrapper/nmt_wrapper_test.go +++ b/pkg/wrapper/nmt_wrapper_test.go @@ -9,7 +9,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" - appns "github.com/celestiaorg/go-square/v2/share" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" nmtnamespace "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" @@ -50,7 +50,7 @@ func TestRootErasuredNamespacedMerkleTree(t *testing.T) { size := 8 data := testfactory.GenerateRandNamespacedRawData(size) nmtErasured := wrapper.NewErasuredNamespacedMerkleTree(uint64(size), 0) - nmtStandard := nmt.New(sha256.New(), nmt.NamespaceIDSize(appns.NamespaceSize), nmt.IgnoreMaxNamespace(true)) + nmtStandard := nmt.New(sha256.New(), nmt.NamespaceIDSize(share.NamespaceSize), nmt.IgnoreMaxNamespace(true)) for _, d := range data { err := nmtErasured.Push(d) @@ -169,9 +169,9 @@ func TestErasuredNamespacedMerkleTree_ProveRange(t *testing.T) { var namespaceID nmtnamespace.ID if i < sqaureSize { - namespaceID = data[i][:appconsts.NamespaceSize] + namespaceID = data[i][:share.NamespaceSize] } else { - namespaceID = appns.ParitySharesNamespace.Bytes() + namespaceID = share.ParitySharesNamespace.Bytes() } verified := proof.VerifyInclusion(appconsts.NewBaseHashFunc(), namespaceID, [][]byte{data[i]}, root) assert.True(t, verified) diff --git a/test/cmd/txsim/cli_test.go b/test/cmd/txsim/cli_test.go index bf637dfb06..3520221af0 100644 --- a/test/cmd/txsim/cli_test.go +++ b/test/cmd/txsim/cli_test.go @@ -62,7 +62,7 @@ func setup(t testing.TB) (keyring.Keyring, string, string) { // set the consensus params to allow for the max square size cparams := testnode.DefaultConsensusParams() - cparams.Block.MaxBytes = int64(appconsts.DefaultSquareSizeUpperBound*appconsts.DefaultSquareSizeUpperBound) * appconsts.ContinuationSparseShareContentSize + cparams.Block.MaxBytes = int64(appconsts.DefaultMaxBytes) cfg := testnode.DefaultConfig(). WithConsensusParams(cparams). diff --git a/test/txsim/blob.go b/test/txsim/blob.go index b03d725d4b..90b410eb59 100644 --- a/test/txsim/blob.go +++ b/test/txsim/blob.go @@ -21,9 +21,10 @@ const fundsForGas int = 1e9 // 1000 TIA // BlobSequence defines a pattern whereby a single user repeatedly sends a pay for blob // message roughly every height. The PFB may consist of several blobs type BlobSequence struct { - namespace share.Namespace - sizes Range - blobsPerPFB Range + namespace share.Namespace + sizes Range + blobsPerPFB Range + shareVersions []uint8 account types.AccAddress useFeegrant bool @@ -31,8 +32,9 @@ type BlobSequence struct { func NewBlobSequence(sizes, blobsPerPFB Range) *BlobSequence { return &BlobSequence{ - sizes: sizes, - blobsPerPFB: blobsPerPFB, + sizes: sizes, + blobsPerPFB: blobsPerPFB, + shareVersions: []uint8{share.ShareVersionZero, share.ShareVersionOne}, } } @@ -43,13 +45,24 @@ func (s *BlobSequence) WithNamespace(namespace share.Namespace) *BlobSequence { return s } +// WithShareVersion provides the option of fixing a predefined share version for +// all blobs else it will randomly select a share version for each blob. +func (s *BlobSequence) WithShareVersion(version uint8) *BlobSequence { + if version != share.ShareVersionZero && version != share.ShareVersionOne { + panic(fmt.Sprintf("invalid share version %d", version)) + } + s.shareVersions = []uint8{version} + return s +} + func (s *BlobSequence) Clone(n int) []Sequence { sequenceGroup := make([]Sequence, n) for i := 0; i < n; i++ { sequenceGroup[i] = &BlobSequence{ - namespace: s.namespace, - sizes: s.sizes, - blobsPerPFB: s.blobsPerPFB, + namespace: s.namespace, + sizes: s.sizes, + blobsPerPFB: s.blobsPerPFB, + shareVersions: s.shareVersions, } } return sequenceGroup @@ -83,7 +96,15 @@ func (s *BlobSequence) Next(_ context.Context, _ grpc.ClientConn, rand *rand.Ran sizes[i] = s.sizes.Rand(rand) } // generate the blobs - blobs := blobfactory.RandBlobsWithNamespace(namespaces, sizes) + var blobs []*share.Blob + switch s.shareVersions[rand.Intn(len(s.shareVersions))] { + case share.ShareVersionZero: + blobs = blobfactory.RandV0BlobsWithNamespace(namespaces, sizes) + case share.ShareVersionOne: + blobs = blobfactory.RandV1BlobsWithNamespace(namespaces, sizes, s.account) + default: + return Operation{}, fmt.Errorf("invalid share version: %d", s.shareVersions[rand.Intn(len(s.shareVersions))]) + } // derive the pay for blob message msg, err := blob.NewMsgPayForBlobs(s.account.String(), appconsts.LatestVersion, blobs...) if err != nil { diff --git a/test/util/blobfactory/payforblob_factory.go b/test/util/blobfactory/payforblob_factory.go index 3601ece8ef..1a4aa6d10c 100644 --- a/test/util/blobfactory/payforblob_factory.go +++ b/test/util/blobfactory/payforblob_factory.go @@ -23,7 +23,7 @@ import ( var ( // TestMaxBlobSize is the maximum size of each blob in a blob transaction, for testing purposes - TestMaxBlobSize = appconsts.ShareSize * 2 * appconsts.DefaultSquareSizeUpperBound + TestMaxBlobSize = share.ShareSize * 2 * appconsts.DefaultSquareSizeUpperBound // TestMaxBlobCount is the maximum number of blobs in a blob transaction, for testing purposes TestMaxBlobCount = 5 ) @@ -31,7 +31,7 @@ var ( func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCount int) (*blobtypes.MsgPayForBlobs, []*share.Blob) { blobs := make([]*share.Blob, blobCount) for i := 0; i < blobCount; i++ { - blob, err := blobtypes.NewBlob(testfactory.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero) + blob, err := blobtypes.NewV0Blob(testfactory.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size)) if err != nil { panic(err) } @@ -45,11 +45,23 @@ func RandMsgPayForBlobsWithSigner(rand *tmrand.Rand, signer string, size, blobCo return msg, blobs } -func RandBlobsWithNamespace(namespaces []share.Namespace, sizes []int) []*share.Blob { +func RandV0BlobsWithNamespace(namespaces []share.Namespace, sizes []int) []*share.Blob { blobs := make([]*share.Blob, len(namespaces)) var err error for i, ns := range namespaces { - blobs[i], err = share.NewBlob(ns, tmrand.Bytes(sizes[i]), appconsts.ShareVersionZero, nil) + blobs[i], err = share.NewV0Blob(ns, tmrand.Bytes(sizes[i])) + if err != nil { + panic(err) + } + } + return blobs +} + +func RandV1BlobsWithNamespace(namespaces []share.Namespace, sizes []int, signer sdk.AccAddress) []*share.Blob { + blobs := make([]*share.Blob, len(namespaces)) + var err error + for i, ns := range namespaces { + blobs[i], err = share.NewV1Blob(ns, tmrand.Bytes(sizes[i]), signer) if err != nil { panic(err) } @@ -58,7 +70,7 @@ func RandBlobsWithNamespace(namespaces []share.Namespace, sizes []int) []*share. } func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns share.Namespace, size int) (*blobtypes.MsgPayForBlobs, *share.Blob) { - blob, err := blobtypes.NewBlob(ns, tmrand.Bytes(size), appconsts.ShareVersionZero) + blob, err := blobtypes.NewV0Blob(ns, tmrand.Bytes(size)) if err != nil { panic(err) } @@ -74,7 +86,7 @@ func RandMsgPayForBlobsWithNamespaceAndSigner(signer string, ns share.Namespace, } func RandMsgPayForBlobs(rand *tmrand.Rand, size int) (*blobtypes.MsgPayForBlobs, *share.Blob) { - blob, err := share.NewBlob(testfactory.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), appconsts.ShareVersionZero, nil) + blob, err := share.NewBlob(testfactory.RandomBlobNamespaceWithPRG(rand), tmrand.Bytes(size), share.ShareVersionZero, nil) if err != nil { panic(err) } @@ -202,7 +214,7 @@ func Repeat[T any](s T, count int) []T { func ManyBlobs(rand *tmrand.Rand, namespaces []share.Namespace, sizes []int) []*share.Blob { blobs := make([]*share.Blob, len(namespaces)) for i, ns := range namespaces { - blob, err := share.NewBlob(ns, rand.Bytes(sizes[i]), appconsts.ShareVersionZero, nil) + blob, err := share.NewBlob(ns, rand.Bytes(sizes[i]), share.ShareVersionZero, nil) if err != nil { panic(err) } @@ -216,7 +228,7 @@ func NestedBlobs(t *testing.T, namespaces []share.Namespace, sizes [][]int) [][] counter := 0 for i, set := range sizes { for _, size := range set { - blob, err := blobtypes.NewBlob(namespaces[counter], tmrand.Bytes(size), appconsts.ShareVersionZero) + blob, err := blobtypes.NewV0Blob(namespaces[counter], tmrand.Bytes(size)) require.NoError(t, err) blobs[i] = append(blobs[i], blob) counter++ diff --git a/test/util/malicious/out_of_order_builder.go b/test/util/malicious/out_of_order_builder.go index f12ee03fd8..a501f9c8cf 100644 --- a/test/util/malicious/out_of_order_builder.go +++ b/test/util/malicious/out_of_order_builder.go @@ -89,7 +89,7 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) { } // write all the regular transactions into compact shares - txWriter := share.NewCompactShareSplitter(share.TxNamespace, appconsts.ShareVersionZero) + txWriter := share.NewCompactShareSplitter(share.TxNamespace, share.ShareVersionZero) for _, tx := range b.Txs { if err := txWriter.WriteTx(tx); err != nil { return nil, fmt.Errorf("writing tx into compact shares: %w", err) @@ -135,7 +135,7 @@ func OutOfOrderExport(b *square.Builder) (square.Square, error) { // write all the pay for blob transactions into compact shares. We need to do this after allocating the blobs to their // appropriate shares as the starting index of each blob needs to be included in the PFB transaction - pfbWriter := share.NewCompactShareSplitter(share.PayForBlobNamespace, appconsts.ShareVersionZero) + pfbWriter := share.NewCompactShareSplitter(share.PayForBlobNamespace, share.ShareVersionZero) for _, iw := range b.Pfbs { iwBytes, err := proto.Marshal(iw) if err != nil { diff --git a/test/util/malicious/tree.go b/test/util/malicious/tree.go index 4a1107e144..0efa14ec08 100644 --- a/test/util/malicious/tree.go +++ b/test/util/malicious/tree.go @@ -6,6 +6,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" "github.com/celestiaorg/go-square/v2" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/nmt" "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" @@ -43,10 +44,10 @@ func NewConstructor(squareSize uint64, opts ...nmt.Option) rsmt2d.TreeConstructo // wrapper.ErasuredNamespacedMerkleTree with predefined square size and // nmt.Options. func (c constructor) NewTree(_ rsmt2d.Axis, axisIndex uint) rsmt2d.Tree { - hasher := NewNmtHasher(appconsts.NewBaseHashFunc(), appconsts.NamespaceSize, true) + hasher := NewNmtHasher(appconsts.NewBaseHashFunc(), share.NamespaceSize, true) copts := []nmt.Option{ nmt.CustomHasher(hasher), - nmt.NamespaceIDSize(appconsts.NamespaceSize), + nmt.NamespaceIDSize(share.NamespaceSize), nmt.IgnoreMaxNamespace(true), } copts = append(copts, c.opts...) diff --git a/test/util/test_app.go b/test/util/test_app.go index 2a9acf2bab..a9b9f57d49 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -3,6 +3,7 @@ package util import ( "encoding/json" "fmt" + "os" "testing" "time" @@ -89,7 +90,7 @@ func NewTestApp() *app.App { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) return app.New( - log.NewNopLogger(), db, nil, + log.NewTMLogger(os.Stdout), db, nil, cast.ToUint(emptyOpts.Get(server.FlagInvCheckPeriod)), encCfg, 0, @@ -138,7 +139,7 @@ func SetupDeterministicGenesisState(testApp *app.App, pubKeys []cryptotypes.PubK Block: &abci.BlockParams{ // Choose some value large enough to not bottleneck the max square // size - MaxBytes: int64(appconsts.DefaultSquareSizeUpperBound*appconsts.DefaultSquareSizeUpperBound) * appconsts.ContinuationSparseShareContentSize, + MaxBytes: appconsts.DefaultMaxBytes, MaxGas: cparams.Block.MaxGas, }, Evidence: &cparams.Evidence, @@ -187,7 +188,7 @@ func NewTestAppWithGenesisSet(cparams *tmproto.ConsensusParams, genAccounts ...s Block: &abci.BlockParams{ // choose some value large enough to not bottleneck the max square // size - MaxBytes: int64(appconsts.DefaultSquareSizeUpperBound*appconsts.DefaultSquareSizeUpperBound) * appconsts.ContinuationSparseShareContentSize, + MaxBytes: appconsts.DefaultMaxBytes, MaxGas: cparams.Block.MaxGas, }, Evidence: &cparams.Evidence, diff --git a/test/util/testfactory/blob.go b/test/util/testfactory/blob.go index 52b452562a..460814f23a 100644 --- a/test/util/testfactory/blob.go +++ b/test/util/testfactory/blob.go @@ -31,7 +31,7 @@ func GenerateRandomlySizedBlobs(count, maxBlobSize int) []*share.Blob { func GenerateBlobsWithNamespace(count int, blobSize int, ns share.Namespace) []*share.Blob { blobs := make([]*share.Blob, count) for i := 0; i < count; i++ { - blob, err := share.NewBlob(ns, tmrand.Bytes(blobSize), appconsts.ShareVersionZero, nil) + blob, err := share.NewBlob(ns, tmrand.Bytes(blobSize), appconsts.DefaultShareVersion, nil) if err != nil { panic(err) } @@ -48,7 +48,7 @@ func GenerateBlobsWithNamespace(count int, blobSize int, ns share.Namespace) []* func GenerateRandomBlob(dataSize int) *share.Blob { ns := share.MustNewV0Namespace(bytes.Repeat([]byte{0x1}, share.NamespaceVersionZeroIDSize)) - blob, err := share.NewBlob(ns, tmrand.Bytes(dataSize), appconsts.ShareVersionZero, nil) + blob, err := share.NewBlob(ns, tmrand.Bytes(dataSize), appconsts.DefaultShareVersion, nil) if err != nil { panic(err) } @@ -58,7 +58,7 @@ func GenerateRandomBlob(dataSize int) *share.Blob { // GenerateRandomBlobOfShareCount returns a blob that spans the given // number of shares func GenerateRandomBlobOfShareCount(count int) *share.Blob { - size := rawBlobSize(appconsts.FirstSparseShareContentSize * count) + size := rawBlobSize(share.FirstSparseShareContentSize * count) return GenerateRandomBlob(size) } diff --git a/test/util/testfactory/common.go b/test/util/testfactory/common.go index f37d4e4439..7e5fe37997 100644 --- a/test/util/testfactory/common.go +++ b/test/util/testfactory/common.go @@ -4,7 +4,6 @@ import ( "bytes" "sort" - "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/go-square/v2/share" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" @@ -35,7 +34,7 @@ func Repeat[T any](s T, count int) []T { // namespace. func GenerateRandNamespacedRawData(count int) (result [][]byte) { for i := 0; i < count; i++ { - rawData := tmrand.Bytes(appconsts.ShareSize) + rawData := tmrand.Bytes(share.ShareSize) namespace := share.RandomBlobNamespace().Bytes() copy(rawData, namespace) result = append(result, rawData) diff --git a/test/util/testnode/config.go b/test/util/testnode/config.go index cbeaf22d2a..49b7ef7d30 100644 --- a/test/util/testnode/config.go +++ b/test/util/testnode/config.go @@ -153,7 +153,7 @@ func DefaultTendermintConfig() *tmconfig.Config { // Override the mempool's MaxTxBytes to allow the testnode to accept a // transaction that fills the entire square. Any blob transaction larger // than the square size will still fail no matter what. - maxTxBytes := appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * appconsts.ContinuationSparseShareContentSize + maxTxBytes := appconsts.DefaultMaxBytes tmCfg.Mempool.MaxTxBytes = maxTxBytes // Override the MaxBodyBytes to allow the testnode to accept very large diff --git a/test/util/testnode/node_interaction_api.go b/test/util/testnode/node_interaction_api.go index 4a041503e4..3695ee2a99 100644 --- a/test/util/testnode/node_interaction_api.go +++ b/test/util/testnode/node_interaction_api.go @@ -242,7 +242,7 @@ func (c *Context) PostData(account, broadcastMode string, ns share.Namespace, bl return nil, err } - b, err := types.NewBlob(ns, blobData, appconsts.ShareVersionZero) + b, err := types.NewV0Blob(ns, blobData) if err != nil { return nil, err } diff --git a/x/blob/ante/ante_test.go b/x/blob/ante/ante_test.go index c5fefd3d93..e1f16e2b7a 100644 --- a/x/blob/ante/ante_test.go +++ b/x/blob/ante/ante_test.go @@ -5,7 +5,6 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" - "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" ante "github.com/celestiaorg/celestia-app/v3/x/blob/ante" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" @@ -33,7 +32,7 @@ func TestPFBAnteHandler(t *testing.T) { // 1 share = 512 bytes = 5120 gas BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1))}, }, - txGas: appconsts.ShareSize * testGasPerBlobByte, + txGas: share.ShareSize * testGasPerBlobByte, gasConsumed: 0, wantErr: false, }, @@ -42,7 +41,7 @@ func TestPFBAnteHandler(t *testing.T) { pfb: &blob.MsgPayForBlobs{ BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1)), uint32(share.AvailableBytesFromSparseShares(2))}, }, - txGas: 3 * appconsts.ShareSize * testGasPerBlobByte, + txGas: 3 * share.ShareSize * testGasPerBlobByte, gasConsumed: 0, wantErr: false, }, @@ -52,7 +51,7 @@ func TestPFBAnteHandler(t *testing.T) { // 2 share = 1024 bytes = 10240 gas BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1) + 1)}, }, - txGas: 2*appconsts.ShareSize*testGasPerBlobByte - 1, + txGas: 2*share.ShareSize*testGasPerBlobByte - 1, gasConsumed: 0, wantErr: true, }, @@ -61,7 +60,7 @@ func TestPFBAnteHandler(t *testing.T) { pfb: &blob.MsgPayForBlobs{ BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1)), uint32(share.AvailableBytesFromSparseShares(2))}, }, - txGas: 3*appconsts.ShareSize*testGasPerBlobByte - 1, + txGas: 3*share.ShareSize*testGasPerBlobByte - 1, gasConsumed: 0, wantErr: true, }, @@ -71,7 +70,7 @@ func TestPFBAnteHandler(t *testing.T) { // 1 share = 512 bytes = 5120 gas BlobSizes: []uint32{uint32(share.AvailableBytesFromSparseShares(1))}, }, - txGas: appconsts.ShareSize*testGasPerBlobByte + 10000 - 1, + txGas: share.ShareSize*testGasPerBlobByte + 10000 - 1, gasConsumed: 10000, wantErr: true, }, diff --git a/x/blob/client/cli/payforblob.go b/x/blob/client/cli/payforblob.go index 1439f92dde..a5263814a8 100644 --- a/x/blob/client/cli/payforblob.go +++ b/x/blob/client/cli/payforblob.go @@ -115,9 +115,16 @@ The blob must be a hex encoded string of non-zero length. return err } + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + signer := clientCtx.FromAddress + // In case of no file input, get the namespaceID and blob from the arguments if path == "" { - blob, err := getBlobFromArguments(args[0], args[1], namespaceVersion, shareVersion) + blob, err := getBlobFromArguments(args[0], args[1], namespaceVersion, shareVersion, signer) if err != nil { return err } @@ -132,7 +139,7 @@ The blob must be a hex encoded string of non-zero length. var blobs []*share.Blob for _, paresdBlob := range paresdBlobs { - blob, err := getBlobFromArguments(paresdBlob.NamespaceID, paresdBlob.Blob, namespaceVersion, shareVersion) + blob, err := getBlobFromArguments(paresdBlob.NamespaceID, paresdBlob.Blob, namespaceVersion, shareVersion, signer) if err != nil { return err } @@ -151,7 +158,7 @@ The blob must be a hex encoded string of non-zero length. return cmd } -func getBlobFromArguments(namespaceIDArg, blobArg string, namespaceVersion, shareVersion uint8) (*share.Blob, error) { +func getBlobFromArguments(namespaceIDArg, blobArg string, namespaceVersion, shareVersion uint8, signer sdk.AccAddress) (*share.Blob, error) { namespaceID, err := hex.DecodeString(strings.TrimPrefix(namespaceIDArg, "0x")) if err != nil { return nil, fmt.Errorf("failed to decode hex namespace ID: %w", err) @@ -166,12 +173,14 @@ func getBlobFromArguments(namespaceIDArg, blobArg string, namespaceVersion, shar return nil, fmt.Errorf("failure to decode hex blob value %s: %s", hexStr, err.Error()) } - blob, err := types.NewBlob(namespace, rawblob, shareVersion) - if err != nil { - return nil, fmt.Errorf("failure to create blob with hex blob value %s: %s", hexStr, err.Error()) + switch shareVersion { + case share.ShareVersionZero: + return types.NewV0Blob(namespace, rawblob) + case share.ShareVersionOne: + return types.NewV1Blob(namespace, rawblob, signer) + default: + return nil, fmt.Errorf("share version %d is not supported", shareVersion) } - - return blob, nil } func getNamespace(namespaceID []byte, namespaceVersion uint8) (share.Namespace, error) { @@ -197,8 +206,6 @@ func broadcastPFB(cmd *cobra.Command, b ...*share.Blob) error { return err } - // TODO: allow the user to override the share version via a new flag - // See https://github.com/celestiaorg/celestia-app/issues/1041 pfbMsg, err := types.NewMsgPayForBlobs(clientCtx.FromAddress.String(), appconsts.LatestVersion, b...) if err != nil { return err diff --git a/x/blob/keeper/gas_test.go b/x/blob/keeper/gas_test.go index 8c3b6c1c8c..8c7bd534ff 100644 --- a/x/blob/keeper/gas_test.go +++ b/x/blob/keeper/gas_test.go @@ -3,8 +3,8 @@ package keeper_test import ( "testing" - "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/celestia-app/v3/x/blob/types" + "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -23,27 +23,27 @@ func TestPayForBlobGas(t *testing.T) { { name: "1 byte blob", // occupies 1 share msg: types.MsgPayForBlobs{BlobSizes: []uint32{1}}, - wantGasConsumed: uint64(1*appconsts.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 1 share * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 5156 gas + wantGasConsumed: uint64(1*share.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 1 share * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 5156 gas }, { name: "100 byte blob", // occupies 1 share msg: types.MsgPayForBlobs{BlobSizes: []uint32{100}}, - wantGasConsumed: uint64(1*appconsts.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), + wantGasConsumed: uint64(1*share.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), }, { name: "1024 byte blob", // occupies 3 shares because share prefix (e.g. namespace, info byte) msg: types.MsgPayForBlobs{BlobSizes: []uint32{1024}}, - wantGasConsumed: uint64(3*appconsts.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 3 shares * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 13348 gas + wantGasConsumed: uint64(3*share.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 3 shares * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 13348 gas }, { name: "3 blobs, 1 share each", msg: types.MsgPayForBlobs{BlobSizes: []uint32{1, 1, 1}}, - wantGasConsumed: uint64(3*appconsts.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 3 shares * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 13348 gas + wantGasConsumed: uint64(3*share.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 3 shares * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 13348 gas }, { name: "3 blobs, 6 shares total", msg: types.MsgPayForBlobs{BlobSizes: []uint32{1024, 800, 100}}, - wantGasConsumed: uint64(6*appconsts.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 6 shares * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 25636 gas + wantGasConsumed: uint64(6*share.ShareSize*types.DefaultGasPerBlobByte + paramLookUpCost), // 6 shares * 512 bytes per share * 8 gas per byte + 1060 gas for fetching param = 25636 gas }, } diff --git a/x/blob/keeper/keeper_test.go b/x/blob/keeper/keeper_test.go index b42aea310c..e3da5cb12a 100644 --- a/x/blob/keeper/keeper_test.go +++ b/x/blob/keeper/keeper_test.go @@ -65,7 +65,7 @@ func convertToEventPayForBlobs(message proto.Message) (*types.EventPayForBlobs, } func createMsgPayForBlob(t *testing.T, signer string, namespace share.Namespace, blobData []byte) *types.MsgPayForBlobs { - blob, err := share.NewBlob(namespace, blobData, appconsts.ShareVersionZero, nil) + blob, err := share.NewBlob(namespace, blobData, share.ShareVersionZero, nil) require.NoError(t, err) msg, err := types.NewMsgPayForBlobs(signer, appconsts.LatestVersion, blob) require.NoError(t, err) diff --git a/x/blob/types/blob_tx.go b/x/blob/types/blob_tx.go index fb5e2af058..1f6273f10c 100644 --- a/x/blob/types/blob_tx.go +++ b/x/blob/types/blob_tx.go @@ -7,24 +7,30 @@ import ( "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/crypto/merkle" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) -// NewBlob creates a new coretypes.Blob from the provided data after performing -// basic stateless checks over it. -func NewBlob(ns share.Namespace, data []byte, shareVersion uint8) (*share.Blob, error) { +// NewV0Blob creates a new V0 Blob from a provided namespace and data. +func NewV0Blob(ns share.Namespace, data []byte) (*share.Blob, error) { // checks that it is a non reserved, valid namespace err := ValidateBlobNamespace(ns) if err != nil { return nil, err } - if len(data) == 0 { - return nil, ErrZeroBlobSize - } + return share.NewV0Blob(ns, data) +} - return share.NewBlob(ns, data, shareVersion, nil) +// NewV1Blob creates a new V1 Blob from the provided namespace, data and the signer +// that will pay for the blob. +func NewV1Blob(ns share.Namespace, data []byte, signer sdk.AccAddress) (*share.Blob, error) { + err := ValidateBlobNamespace(ns) + if err != nil { + return nil, err + } + return share.NewV1Blob(ns, data, signer) } // ValidateBlobTx performs stateless checks on the BlobTx to ensure that the @@ -65,6 +71,20 @@ func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx *tx.BlobTx, subtreeRootTh return err } + signer, err := sdk.AccAddressFromBech32(msgPFB.Signer) + if err != nil { + return err + } + for _, blob := range bTx.Blobs { + // If share version is 1, assert that the signer in the blob + // matches the signer in the msgPFB. + if blob.ShareVersion() == share.ShareVersionOne { + if !bytes.Equal(blob.Signer(), signer) { + return ErrInvalidBlobSigner.Wrapf("blob signer %s does not match msgPFB signer %s", sdk.AccAddress(blob.Signer()).String(), msgPFB.Signer) + } + } + } + // check that the sizes in the blobTx match the sizes in the msgPFB if !equalSlices(sizes, msgPFB.BlobSizes) { return ErrBlobSizeMismatch.Wrapf("actual %v declared %v", sizes, msgPFB.BlobSizes) diff --git a/x/blob/types/blob_tx_test.go b/x/blob/types/blob_tx_test.go index b03a6239a7..1a2d8295dc 100644 --- a/x/blob/types/blob_tx_test.go +++ b/x/blob/types/blob_tx_test.go @@ -22,16 +22,16 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" ) -func TestNewBlob(t *testing.T) { +func TestNewV0Blob(t *testing.T) { rawBlob := []byte{1} - validBlob, err := types.NewBlob(share.RandomBlobNamespace(), rawBlob, appconsts.ShareVersionZero) + validBlob, err := types.NewV0Blob(share.RandomBlobNamespace(), rawBlob) require.NoError(t, err) require.Equal(t, validBlob.Data(), rawBlob) - _, err = types.NewBlob(share.TxNamespace, rawBlob, appconsts.ShareVersionZero) + _, err = types.NewV0Blob(share.TxNamespace, rawBlob) require.Error(t, err) - _, err = types.NewBlob(share.RandomBlobNamespace(), []byte{}, appconsts.ShareVersionZero) + _, err = types.NewV0Blob(share.RandomBlobNamespace(), []byte{}) require.Error(t, err) } @@ -78,7 +78,7 @@ func TestValidateBlobTx(t *testing.T) { require.NoError(t, err) originalBlob := btx.Blobs[0] - differentBlob, err := share.NewBlob(share.RandomBlobNamespace(), originalBlob.Data(), originalBlob.ShareVersion(), nil) + differentBlob, err := share.NewBlob(share.RandomBlobNamespace(), originalBlob.Data(), originalBlob.ShareVersion(), originalBlob.Signer()) require.NoError(t, err) btx.Blobs[0] = differentBlob @@ -90,7 +90,7 @@ func TestValidateBlobTx(t *testing.T) { name: "invalid transaction, no pfb", getTx: func() *tx.BlobTx { sendTx := blobfactory.GenerateManyRawSendTxs(signer, 1) - b, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + b, err := types.NewV0Blob(share.RandomBlobNamespace(), tmrand.Bytes(100)) require.NoError(t, err) return &tx.BlobTx{ Tx: sendTx[0], @@ -105,7 +105,7 @@ func TestValidateBlobTx(t *testing.T) { rawBtx := validRawBtx() btx, _, err := tx.UnmarshalBlobTx(rawBtx) require.NoError(t, err) - blob, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + blob, err := types.NewV0Blob(share.RandomBlobNamespace(), tmrand.Bytes(100)) require.NoError(t, err) btx.Blobs = append(btx.Blobs, blob) return btx @@ -115,7 +115,7 @@ func TestValidateBlobTx(t *testing.T) { { name: "invalid share commitment", getTx: func() *tx.BlobTx { - b, err := types.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(100), appconsts.ShareVersionZero) + b, err := types.NewV0Blob(share.RandomBlobNamespace(), tmrand.Bytes(100)) require.NoError(t, err) msg, err := types.NewMsgPayForBlobs( addr.String(), @@ -124,7 +124,7 @@ func TestValidateBlobTx(t *testing.T) { ) require.NoError(t, err) - anotherBlob, err := share.NewBlob(share.RandomBlobNamespace(), tmrand.Bytes(99), appconsts.ShareVersionZero, nil) + anotherBlob, err := share.NewV0Blob(share.RandomBlobNamespace(), tmrand.Bytes(99)) require.NoError(t, err) badCommit, err := inclusion.CreateCommitment( anotherBlob, @@ -177,7 +177,7 @@ func TestValidateBlobTx(t *testing.T) { name: "normal transaction with two blobs w/ different namespaces", getTx: func() *tx.BlobTx { rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), - blobfactory.RandBlobsWithNamespace( + blobfactory.RandV0BlobsWithNamespace( []share.Namespace{share.RandomBlobNamespace(), share.RandomBlobNamespace()}, []int{100, 100})) require.NoError(t, err) @@ -192,9 +192,10 @@ func TestValidateBlobTx(t *testing.T) { name: "normal transaction with two large blobs w/ different namespaces", getTx: func() *tx.BlobTx { rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), - blobfactory.RandBlobsWithNamespace( + blobfactory.RandV0BlobsWithNamespace( []share.Namespace{share.RandomBlobNamespace(), share.RandomBlobNamespace()}, - []int{100000, 1000000}), + []int{100000, 1000000}, + ), ) require.NoError(t, err) btx, isBlobTx, err := tx.UnmarshalBlobTx(rawBtx) @@ -209,9 +210,10 @@ func TestValidateBlobTx(t *testing.T) { getTx: func() *tx.BlobTx { ns := share.RandomBlobNamespace() rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), - blobfactory.RandBlobsWithNamespace( + blobfactory.RandV0BlobsWithNamespace( []share.Namespace{ns, ns}, - []int{100, 100}), + []int{100, 100}, + ), ) require.NoError(t, err) btx, isBlobTx, err := tx.UnmarshalBlobTx(rawBtx) @@ -233,7 +235,7 @@ func TestValidateBlobTx(t *testing.T) { namespaces[i] = ns } rawBtx, _, err := signer.CreatePayForBlobs(acc.Name(), - blobfactory.RandBlobsWithNamespace( + blobfactory.RandV0BlobsWithNamespace( namespaces, sizes, )) diff --git a/x/blob/types/errors.go b/x/blob/types/errors.go index fd97105532..92735e0578 100644 --- a/x/blob/types/errors.go +++ b/x/blob/types/errors.go @@ -36,4 +36,5 @@ var ( // ErrTotalBlobSize is deprecated, use ErrBlobsTooLarge instead. ErrTotalBlobSizeTooLarge = errors.Register(ModuleName, 11138, "total blob size too large") ErrBlobsTooLarge = errors.Register(ModuleName, 11139, "blob(s) too large") + ErrInvalidBlobSigner = errors.Register(ModuleName, 11140, "invalid blob signer") ) diff --git a/x/blob/types/payforblob.go b/x/blob/types/payforblob.go index c8abc43745..92eca0a4d7 100644 --- a/x/blob/types/payforblob.go +++ b/x/blob/types/payforblob.go @@ -119,7 +119,7 @@ func (msg *MsgPayForBlobs) ValidateBasic() error { } for _, v := range msg.ShareVersions { - if v != uint32(appconsts.ShareVersionZero) { + if v != uint32(share.ShareVersionZero) && v != uint32(share.ShareVersionOne) { return ErrUnsupportedShareVersion } } @@ -151,7 +151,7 @@ func GasToConsume(blobSizes []uint32, gasPerByte uint32) uint64 { totalSharesUsed += uint64(share.SparseSharesNeeded(size)) } - return totalSharesUsed * appconsts.ShareSize * uint64(gasPerByte) + return totalSharesUsed * share.ShareSize * uint64(gasPerByte) } // EstimateGas estimates the total gas required to pay for a set of blobs in a PFB. @@ -198,24 +198,21 @@ func (msg *MsgPayForBlobs) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{address} } -// ValidateBlobs performs basic checks over the components of one or more PFBs. +// ValidateBlobs performs checks that each blob is non-empty and has a valid namespace. +// Other checks are done in the construction of the Blob. func ValidateBlobs(blobs ...*share.Blob) error { if len(blobs) == 0 { return ErrNoBlobs } for _, blob := range blobs { - err := ValidateBlobNamespace(blob.Namespace()) - if err != nil { - return err - } - if blob.IsEmpty() { return ErrZeroBlobSize } - if !slices.Contains(appconsts.SupportedShareVersions, blob.ShareVersion()) { - return ErrUnsupportedShareVersion + err := ValidateBlobNamespace(blob.Namespace()) + if err != nil { + return err } } diff --git a/x/blob/types/payforblob_test.go b/x/blob/types/payforblob_test.go index 0e63b3c721..86d8a544f1 100644 --- a/x/blob/types/payforblob_test.go +++ b/x/blob/types/payforblob_test.go @@ -171,7 +171,7 @@ func validMsgPayForBlobs(t *testing.T) *types.MsgPayForBlobs { ns1 := share.NamespaceVersionZeroPrefix ns1 = append(ns1, bytes.Repeat([]byte{0x01}, share.NamespaceVersionZeroIDSize)...) ns := share.MustNewNamespace(share.NamespaceVersionZero, ns1) - data := bytes.Repeat([]byte{2}, totalBlobSize(appconsts.ContinuationSparseShareContentSize*12)) + data := bytes.Repeat([]byte{2}, totalBlobSize(share.ContinuationSparseShareContentSize*12)) blob, err := share.NewV0Blob(ns, data) require.NoError(t, err) @@ -192,24 +192,33 @@ func TestNewMsgPayForBlobs(t *testing.T) { } ns1 := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) ns2 := share.MustNewV0Namespace(bytes.Repeat([]byte{2}, share.NamespaceVersionZeroIDSize)) + address := sdk.MustAccAddressFromBech32(testfactory.TestAccAddr) testCases := []testCase{ { name: "valid msg PFB with small blob", signer: testfactory.TestAccAddr, - blobs: []*share.Blob{mustNewBlob(t, ns1, []byte{1}, appconsts.ShareVersionZero, nil)}, + blobs: []*share.Blob{mustNewBlob(t, ns1, []byte{1}, share.ShareVersionZero, nil)}, }, { name: "valid msg PFB with large blob", signer: testfactory.TestAccAddr, - blobs: []*share.Blob{mustNewBlob(t, ns1, tmrand.Bytes(1000000), appconsts.ShareVersionZero, nil)}, + blobs: []*share.Blob{mustNewBlob(t, ns1, tmrand.Bytes(1000000), share.ShareVersionZero, nil)}, }, { name: "valid msg PFB with two blobs", signer: testfactory.TestAccAddr, blobs: []*share.Blob{ - mustNewBlob(t, ns1, []byte{1}, appconsts.ShareVersionZero, nil), - mustNewBlob(t, ns2, []byte{2}, appconsts.ShareVersionZero, nil), + mustNewBlob(t, ns1, []byte{1}, share.ShareVersionZero, nil), + mustNewBlob(t, ns2, []byte{2}, share.ShareVersionZero, nil), + }, + expectedErr: false, + }, + { + name: "valid msg PFB with share version 1", + signer: testfactory.TestAccAddr, + blobs: []*share.Blob{ + mustNewBlob(t, ns1, tmrand.Bytes(10000), share.ShareVersionOne, address), }, expectedErr: false, }, @@ -217,7 +226,7 @@ func TestNewMsgPayForBlobs(t *testing.T) { name: "msg PFB with tx namespace returns an error", signer: testfactory.TestAccAddr, blobs: []*share.Blob{ - mustNewBlob(t, share.TxNamespace, tmrand.Bytes(1000000), appconsts.ShareVersionZero, nil), + mustNewBlob(t, share.TxNamespace, tmrand.Bytes(1000000), share.ShareVersionZero, nil), }, expectedErr: true, }, @@ -225,7 +234,7 @@ func TestNewMsgPayForBlobs(t *testing.T) { name: "msg PFB with invalid signer returns an error", signer: testfactory.TestAccAddr[:10], blobs: []*share.Blob{ - mustNewBlob(t, ns1, []byte{1}, appconsts.ShareVersionZero, nil), + mustNewBlob(t, ns1, []byte{1}, share.ShareVersionZero, nil), }, expectedErr: true, }, From 2571c23f4026e6b667234e5a3d95db85692c9881 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 7 Aug 2024 18:02:50 +0200 Subject: [PATCH 7/9] fix app hash mismatch --- app/test/square_size_test.go | 3 +-- pkg/appconsts/initial_consts.go | 4 ++++ test/util/test_app.go | 4 ++-- test/util/testnode/config.go | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/test/square_size_test.go b/app/test/square_size_test.go index 8e7a6643cc..e8082b17f5 100644 --- a/app/test/square_size_test.go +++ b/app/test/square_size_test.go @@ -16,7 +16,6 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - "github.com/celestiaorg/go-square/v2/share" sdk "github.com/cosmos/cosmos-sdk/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" oldgov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -87,7 +86,7 @@ func (s *SquareSizeIntegrationTest) TestSquareSizeUpperBound() { { name: "gov square size == hardcoded max", govMaxSquareSize: appconsts.DefaultSquareSizeUpperBound, - maxBytes: appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize, + maxBytes: appconsts.DefaultUpperBoundMaxBytes, expectedMaxSquareSize: appconsts.DefaultSquareSizeUpperBound, }, } diff --git a/pkg/appconsts/initial_consts.go b/pkg/appconsts/initial_consts.go index 12a660dfbc..72907940c3 100644 --- a/pkg/appconsts/initial_consts.go +++ b/pkg/appconsts/initial_consts.go @@ -31,3 +31,7 @@ const ( // time can be subject to slashing under conditions of misbehavior. DefaultUnbondingTime = 3 * 7 * 24 * time.Hour ) + +var ( + DefaultUpperBoundMaxBytes = DefaultSquareSizeUpperBound * DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize +) diff --git a/test/util/test_app.go b/test/util/test_app.go index a9b9f57d49..8b4a433e9c 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -139,7 +139,7 @@ func SetupDeterministicGenesisState(testApp *app.App, pubKeys []cryptotypes.PubK Block: &abci.BlockParams{ // Choose some value large enough to not bottleneck the max square // size - MaxBytes: appconsts.DefaultMaxBytes, + MaxBytes: int64(appconsts.DefaultUpperBoundMaxBytes), MaxGas: cparams.Block.MaxGas, }, Evidence: &cparams.Evidence, @@ -188,7 +188,7 @@ func NewTestAppWithGenesisSet(cparams *tmproto.ConsensusParams, genAccounts ...s Block: &abci.BlockParams{ // choose some value large enough to not bottleneck the max square // size - MaxBytes: appconsts.DefaultMaxBytes, + MaxBytes: int64(appconsts.DefaultUpperBoundMaxBytes), MaxGas: cparams.Block.MaxGas, }, Evidence: &cparams.Evidence, diff --git a/test/util/testnode/config.go b/test/util/testnode/config.go index 49b7ef7d30..7054d8e7ec 100644 --- a/test/util/testnode/config.go +++ b/test/util/testnode/config.go @@ -139,7 +139,7 @@ func DefaultConfig() *Config { func DefaultConsensusParams() *tmproto.ConsensusParams { cparams := types.DefaultConsensusParams() cparams.Block.TimeIotaMs = 1 - cparams.Block.MaxBytes = appconsts.DefaultMaxBytes + cparams.Block.MaxBytes = int64(appconsts.DefaultUpperBoundMaxBytes) cparams.Version.AppVersion = appconsts.LatestVersion return cparams } @@ -153,7 +153,7 @@ func DefaultTendermintConfig() *tmconfig.Config { // Override the mempool's MaxTxBytes to allow the testnode to accept a // transaction that fills the entire square. Any blob transaction larger // than the square size will still fail no matter what. - maxTxBytes := appconsts.DefaultMaxBytes + maxTxBytes := appconsts.DefaultUpperBoundMaxBytes tmCfg.Mempool.MaxTxBytes = maxTxBytes // Override the MaxBodyBytes to allow the testnode to accept very large From b684acd65178df2361c0bce6f7cab29fcc142b25 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 8 Aug 2024 11:18:09 +0200 Subject: [PATCH 8/9] lint --- pkg/appconsts/initial_consts.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/appconsts/initial_consts.go b/pkg/appconsts/initial_consts.go index 72907940c3..1f97adf951 100644 --- a/pkg/appconsts/initial_consts.go +++ b/pkg/appconsts/initial_consts.go @@ -32,6 +32,4 @@ const ( DefaultUnbondingTime = 3 * 7 * 24 * time.Hour ) -var ( - DefaultUpperBoundMaxBytes = DefaultSquareSizeUpperBound * DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize -) +var DefaultUpperBoundMaxBytes = DefaultSquareSizeUpperBound * DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize From 08de9e38fd3cfd18369a0628b355bfedc5ce8f27 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 9 Aug 2024 13:22:22 +0200 Subject: [PATCH 9/9] make a few fixes from suggestions --- specs/src/specs/namespace.md | 2 +- test/txsim/blob.go | 5 +++-- test/util/testnode/config.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/specs/src/specs/namespace.md b/specs/src/specs/namespace.md index ee761c327f..916605e96e 100644 --- a/specs/src/specs/namespace.md +++ b/specs/src/specs/namespace.md @@ -95,7 +95,7 @@ Among the potential consequences is the _Woods Attack_, as elaborated in this fo ## Implementation See the [namespace implementation in go-square](https://github.com/celestiaorg/go-square/v2/share/be3c2801e902a0f90f694c062b9c4e6a7e01154e/namespace/namespace.go). -For the most recent version, which may not reflect the current specifications, refer to [the latest namespace code](https://github.com/celestiaorg/go-square/main/share/namespace.go). +For the most recent version, which may not reflect the current specifications, refer to [the latest namespace code](https://github.com/celestiaorg/go-square/blob/main/share/namespace.go). ## Go Definition diff --git a/test/txsim/blob.go b/test/txsim/blob.go index 90b410eb59..3fcef2fa33 100644 --- a/test/txsim/blob.go +++ b/test/txsim/blob.go @@ -97,13 +97,14 @@ func (s *BlobSequence) Next(_ context.Context, _ grpc.ClientConn, rand *rand.Ran } // generate the blobs var blobs []*share.Blob - switch s.shareVersions[rand.Intn(len(s.shareVersions))] { + shareVersion := s.shareVersions[rand.Intn(len(s.shareVersions))] + switch shareVersion { case share.ShareVersionZero: blobs = blobfactory.RandV0BlobsWithNamespace(namespaces, sizes) case share.ShareVersionOne: blobs = blobfactory.RandV1BlobsWithNamespace(namespaces, sizes, s.account) default: - return Operation{}, fmt.Errorf("invalid share version: %d", s.shareVersions[rand.Intn(len(s.shareVersions))]) + return Operation{}, fmt.Errorf("invalid share version: %d", shareVersion) } // derive the pay for blob message msg, err := blob.NewMsgPayForBlobs(s.account.String(), appconsts.LatestVersion, blobs...) diff --git a/test/util/testnode/config.go b/test/util/testnode/config.go index 7054d8e7ec..947df61fa9 100644 --- a/test/util/testnode/config.go +++ b/test/util/testnode/config.go @@ -139,7 +139,7 @@ func DefaultConfig() *Config { func DefaultConsensusParams() *tmproto.ConsensusParams { cparams := types.DefaultConsensusParams() cparams.Block.TimeIotaMs = 1 - cparams.Block.MaxBytes = int64(appconsts.DefaultUpperBoundMaxBytes) + cparams.Block.MaxBytes = appconsts.DefaultMaxBytes cparams.Version.AppVersion = appconsts.LatestVersion return cparams }