Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

revert!: multi share commitment #1275

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/estimate_square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_estimateSquareSize_MultiBlob(t *testing.T) {
"100 multiblob single share transaction", func() [][]int {
return [][]int{blobfactory.Repeat(int(100), 100)}
},
16, 5,
16, 11,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[simple comment]
perhaps we can eventually include some some option to use a multiblob commit and no namespaces to be more efficient in the future

},
}
for _, tt := range tests {
Expand Down
23 changes: 12 additions & 11 deletions app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,19 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) abci.ResponsePr
}
}

commitment, err := inclusion.GetMultiCommit(cacher, dah, wrappedTx.ShareIndexes, pfb.BlobSizes)
if err != nil {
logInvalidPropBlockError(app.Logger(), req.Header, "commitment not found", err)
return abci.ResponseProcessProposal{
Result: abci.ResponseProcessProposal_REJECT,
for i, shareIndex := range wrappedTx.ShareIndexes {
commitment, err := inclusion.GetCommit(cacher, dah, int(shareIndex), shares.SparseSharesNeeded(pfb.BlobSizes[i]))
if err != nil {
logInvalidPropBlockError(app.Logger(), req.Header, "commitment not found", err)
return abci.ResponseProcessProposal{
Result: abci.ResponseProcessProposal_REJECT,
}
}
}

if !bytes.Equal(pfb.ShareCommitment, commitment) {
logInvalidPropBlock(app.Logger(), req.Header, "found commitment does not match user's")
return abci.ResponseProcessProposal{
Result: abci.ResponseProcessProposal_REJECT,
if !bytes.Equal(pfb.ShareCommitments[i], commitment) {
logInvalidPropBlock(app.Logger(), req.Header, "found commitment does not match user's")
return abci.ResponseProcessProposal{
Result: abci.ResponseProcessProposal_REJECT,
}
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions pkg/inclusion/get_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@ import (
"errors"

"github.com/celestiaorg/celestia-app/pkg/da"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/tendermint/tendermint/crypto/merkle"
)

func GetMultiCommit(cacher *EDSSubTreeRootCacher, dah da.DataAvailabilityHeader, startIndexes, lengths []uint32) ([]byte, error) {
shareCounts := make([]int, len(lengths))
for i := range lengths {
shareCounts[i] = shares.SparseSharesNeeded(uint32(lengths[i]))
}
commitments := make([][]byte, len(startIndexes))
for i := range startIndexes {
commitment, err := GetCommit(cacher, dah, int(startIndexes[i]), shareCounts[i])
if err != nil {
return nil, err
}
commitments[i] = commitment
}
return merkle.HashFromByteSlices(commitments), nil
}

func GetCommit(cacher *EDSSubTreeRootCacher, dah da.DataAvailabilityHeader, start, blobShareLen int) ([]byte, error) {
squareSize := len(dah.RowsRoots) / 2
if start+blobShareLen > squareSize*squareSize {
Expand Down
5 changes: 2 additions & 3 deletions proto/blob/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ message MsgPayForBlob {
string signer = 1;
repeated bytes namespace_ids = 2;
repeated uint32 blob_sizes = 3;
// share_commitment is a commitment to the blob shares associated with this
// MsgPayForBlob.
bytes share_commitment = 4;
// share_commitments is a list of share commitments (one per blob).
repeated bytes share_commitments = 4;
// share_versions are the versions of the share format that the blobs
// associated with this message should use when included in a block. The
// share_versions specified must match the share_versions used to generate the
Expand Down
14 changes: 8 additions & 6 deletions x/blob/types/blob_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func ValidateBlobTx(txcfg client.TxEncodingConfig, bTx tmproto.BlobTx) error {
}

// verify that the commitment of the blob matches that of the PFB
calculatedCommit, err := CreateMultiShareCommitment(bTx.Blobs...)
if err != nil {
return ErrCalculateCommit
}
if !bytes.Equal(calculatedCommit, pfb.ShareCommitment) {
return ErrInvalidShareCommit
for i, commitment := range pfb.ShareCommitments {
calculatedCommit, err := CreateCommitment(bTx.Blobs[i])
if err != nil {
return ErrCalculateCommit
}
if !bytes.Equal(calculatedCommit, commitment) {
return ErrInvalidShareCommit
}
}

return nil
Expand Down
36 changes: 17 additions & 19 deletions x/blob/types/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ func NewMsgPayForBlob(signer string, blobs ...*Blob) (*MsgPayForBlob, error) {
return nil, err
}

commitment, err := CreateMultiShareCommitment(blobs...)
commitments, err := CreateCommitments(blobs)
if err != nil {
return nil, err
}

msg := &MsgPayForBlob{
Signer: signer,
NamespaceIds: nsIDs,
ShareCommitment: commitment,
BlobSizes: sizes,
ShareVersions: versions,
Signer: signer,
NamespaceIds: nsIDs,
ShareCommitments: commitments,
BlobSizes: sizes,
ShareVersions: versions,
}

return msg, msg.ValidateBasic()
Expand All @@ -61,10 +61,10 @@ func (msg *MsgPayForBlob) Type() string {
// ValidateBasic fulfills the sdk.Msg interface by performing stateless
// validity checks on the msg that also don't require having the actual blob
func (msg *MsgPayForBlob) ValidateBasic() error {
if len(msg.NamespaceIds) != len(msg.ShareVersions) || len(msg.NamespaceIds) != len(msg.BlobSizes) {
if len(msg.NamespaceIds) != len(msg.ShareVersions) || len(msg.NamespaceIds) != len(msg.BlobSizes) || len(msg.NamespaceIds) != len(msg.ShareCommitments) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also want to add a check that this length is not zero?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this length are you referring to msg.ShareCommitments or msg.NamespaceIds? So something like this:

	if len(msg.NamespaceIds) == 0 {
		return ErrNoNamespaceIds
	}

or

	if len(msg.ShareCommitments) == 0 {
		return ErrNoShareCommitments
	}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO both would work. We could include checks that all of these fields are non-zero: NamespaceIds, ShareVersions, BlobSizes, and ShareCommitments. Will do in a follow-up PR.

return ErrMismatchedNumberOfPFBComponent.Wrapf(
"namespaces %d blob sizes %d versions %d",
len(msg.NamespaceIds), len(msg.BlobSizes), len(msg.ShareVersions),
"namespaces %d blob sizes %d versions %d share commitments %d",
len(msg.NamespaceIds), len(msg.BlobSizes), len(msg.ShareVersions), len(msg.ShareCommitments),
)
}

Expand All @@ -86,8 +86,10 @@ func (msg *MsgPayForBlob) ValidateBasic() error {
return err
}

if len(msg.ShareCommitment) == 0 {
return ErrEmptyShareCommitment
for _, commitment := range msg.ShareCommitments {
if len(commitment) == 0 {
return ErrEmptyShareCommitment
}
}

return nil
Expand Down Expand Up @@ -164,20 +166,16 @@ func CreateCommitment(blob *Blob) ([]byte, error) {
return merkle.HashFromByteSlices(subTreeRoots), nil
}

// CreateMultiShareCommitment generates a commitment over multiple blobs at
// arbitrary points in the square. It uses the normal commitment creation
// function per blob, and then creates a merkle root of those commitments.
func CreateMultiShareCommitment(blobs ...*Blob) ([]byte, error) {
func CreateCommitments(blobs []*Blob) ([][]byte, error) {
commitments := make([][]byte, len(blobs))
for i, blob := range blobs {
c, err := CreateCommitment(blob)
commitment, err := CreateCommitment(blob)
if err != nil {
return nil, err
}
commitments[i] = c
commitments[i] = commitment
}

return merkle.HashFromByteSlices(commitments), nil
return commitments, nil
}

// ValidatePFBComponents performs basic checks over the components of one or more PFBs.
Expand Down
9 changes: 5 additions & 4 deletions x/blob/types/payforblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestValidateBasic(t *testing.T) {

// MsgPayForBlob that has an empty share commitment
emptyShareCommitment := validMsgPayForBlob(t)
emptyShareCommitment.ShareCommitment = []byte{}
emptyShareCommitment.ShareCommitments[0] = []byte{}

tests := []test{
{
Expand Down Expand Up @@ -284,15 +284,16 @@ func TestNewMsgPayForBlob(t *testing.T) {
}
for _, tt := range tests {
blob := &Blob{NamespaceId: tt.nids[0], Data: tt.blobs[0], ShareVersion: uint32(appconsts.DefaultShareVersion)}
res, err := NewMsgPayForBlob(tt.signer, blob)
mpfb, err := NewMsgPayForBlob(tt.signer, blob)
if tt.expectedErr {
assert.Error(t, err)
continue
}

expectedCommitment, err := CreateMultiShareCommitment(blob)
expectedCommitment, err := CreateCommitment(blob)
require.NoError(t, err)
assert.Equal(t, expectedCommitment, res.ShareCommitment)
assert.Equal(t, expectedCommitment, mpfb.ShareCommitments[0])
assert.Equal(t, uint32(len(tt.blobs[0])), mpfb.BlobSizes[0])
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/blob/types/test/blob_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestValidateBlobTx(t *testing.T) {
})
require.NoError(t, err)

msg.ShareCommitment = badCommit
msg.ShareCommitments[0] = badCommit

builder := signer.NewTxBuilder()
stx, err := signer.BuildSignedTx(builder, msg)
Expand Down
83 changes: 42 additions & 41 deletions x/blob/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.