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

chore!: replace NMTProof with Proof in nmt #1432

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions proto/buf.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: celestia
repository: nmt
commit: 686a5caececf476e8b8e26994f837778
digest: shake256:30dc63aaf2ba645c37e0d369029bdf3a8c97663eb1ef37548a62bfd48dd7904abd3ecd8ef7e92b3c3cae3eba3360ca73c81558c807ff03c1953a944c251c75e9
- remote: buf.build
owner: gogo
repository: protobuf
Expand Down
1 change: 1 addition & 0 deletions proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: v1
deps:
- buf.build/gogo/protobuf
- buf.build/celestia/nmt:v0.22.2
breaking:
use:
- FILE
Expand Down
3 changes: 2 additions & 1 deletion proto/tendermint/store/types.pb.go

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

527 changes: 107 additions & 420 deletions proto/tendermint/types/types.pb.go

Large diffs are not rendered by default.

35 changes: 7 additions & 28 deletions proto/tendermint/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ option go_package = "github.com/cometbft/cometbft/proto/tendermint/types";

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "proof.proto";
import "tendermint/crypto/proof.proto";
import "tendermint/version/types.proto";
import "tendermint/types/validator.proto";
Expand Down Expand Up @@ -93,7 +94,7 @@ message Data {
// field number 2 is reserved for intermediate state roots
// field number 3 is reserved for evidence
// field number 4 is reserved for blobs

// SquareSize is the number of rows or columns in the original data square.
uint64 square_size = 5;

Expand Down Expand Up @@ -211,11 +212,11 @@ message BlobTx {
// ShareProof is an NMT proof that a set of shares exist in a set of rows and a
// Merkle proof that those rows exist in a Merkle tree with a given data root.
message ShareProof {
repeated bytes data = 1;
repeated NMTProof share_proofs = 2;
bytes namespace_id = 3;
RowProof row_proof = 4;
uint32 namespace_version = 5;
repeated bytes data = 1;
repeated proof.pb.Proof share_proofs = 2;
bytes namespace_id = 3;
RowProof row_proof = 4;
uint32 namespace_version = 5;
}

// RowProof is a Merkle proof that a set of rows exist in a Merkle tree with a
Expand All @@ -227,25 +228,3 @@ message RowProof {
uint32 start_row = 4;
uint32 end_row = 5;
}

// NMTProof is a proof of a namespace.ID in an NMT.
// In case this proof proves the absence of a namespace.ID
// in a tree it also contains the leaf hashes of the range
// where that namespace would be.
message NMTProof {
// Start index of this proof.
int32 start = 1;
// End index of this proof.
int32 end = 2;
// Nodes that together with the corresponding leaf values can be used to
// recompute the root and verify this proof. Nodes should consist of the max
// and min namespaces along with the actual hash, resulting in each being 48
// bytes each
repeated bytes nodes = 3;
// leafHash are nil if the namespace is present in the NMT. In case the
// namespace to be proved is in the min/max range of the tree but absent, this
// will contain the leaf hash necessary to verify the proof of absence. Leaf
// hashes should consist of the namespace along with the actual hash,
// resulting 40 bytes total.
bytes leaf_hash = 4;
}
7 changes: 4 additions & 3 deletions types/share_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math"

"github.com/celestiaorg/nmt"
"github.com/celestiaorg/nmt/pb"
"github.com/cometbft/cometbft/pkg/consts"
"github.com/cometbft/cometbft/proto/tendermint/crypto"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand All @@ -18,7 +19,7 @@ type ShareProof struct {
Data [][]byte `json:"data"`
// ShareProofs are NMT proofs that the shares in Data exist in a set of
// rows. There will be one ShareProof per row that the shares occupy.
ShareProofs []*tmproto.NMTProof `json:"share_proofs"`
ShareProofs []*pb.Proof `json:"share_proofs"`
// NamespaceID is the namespace id of the shares being proven. This
// namespace id is used when verifying the proof. If the namespace id doesn't
// match the namespace of the shares, the proof will fail verification.
Expand Down Expand Up @@ -67,7 +68,7 @@ func ShareProofFromProto(pb tmproto.ShareProof) (ShareProof, error) {
// If the proof is not correctly constructed, it returns a sensible error.
// Note: these proofs are tested on the app side.
func (sp ShareProof) Validate() error {
numberOfSharesInProofs := int32(0)
numberOfSharesInProofs := int64(0)
for _, proof := range sp.ShareProofs {
// the range is not inclusive from the left.
numberOfSharesInProofs += proof.End - proof.Start
Expand Down Expand Up @@ -103,7 +104,7 @@ func (sp ShareProof) VerifyProof(root []byte) bool {
if err := sp.Validate(); err != nil {
return false
}
cursor := int32(0)
cursor := int64(0)
for i, proof := range sp.ShareProofs {
nmtProof := nmt.NewInclusionProof(
int(proof.Start),
Expand Down
6 changes: 3 additions & 3 deletions types/share_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package types
import (
"testing"

"github.com/celestiaorg/nmt/pb"
"github.com/cometbft/cometbft/pkg/consts"
"github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -100,7 +100,7 @@ func TestShareProofVerify(t *testing.T) {

func mismatchedShareProofs() ShareProof {
sp := validShareProof()
sp.ShareProofs = []*types.NMTProof{}
sp.ShareProofs = []*pb.Proof{}
return sp
}

Expand All @@ -116,7 +116,7 @@ func mismatchedShares() ShareProof {
func validShareProof() ShareProof {
return ShareProof{
Data: [][]uint8{{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x62, 0xc, 0x0, 0x0, 0x0, 0x2a, 0xf4, 0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, 0x3f, 0x11, 0x17, 0x9e, 0x54, 0x66, 0xb6, 0xc4, 0x9a, 0xb8, 0x59, 0xb9, 0x13, 0x4e, 0xed, 0x8, 0xe5, 0x99, 0x27, 0xa0, 0x6b, 0x1, 0x6c, 0x8a, 0xbf, 0x20, 0x3d, 0x75, 0xd5, 0x7e, 0xea, 0xe0, 0xef, 0x7f, 0xfe, 0xa8, 0xaf, 0x76, 0xad, 0x30, 0x55, 0x65, 0x9d, 0xbe, 0x30, 0x32, 0x9f, 0x3b, 0xb7, 0xa1, 0x5c, 0x98, 0xef, 0xe1, 0xe4, 0x33, 0x1a, 0x56, 0x5a, 0x22, 0xd1, 0x38, 0x9b, 0xee, 0xfa, 0x11, 0x6f, 0xa7, 0xd7, 0x6, 0x17, 0xdc, 0xc6, 0x4d, 0xbd, 0x3f, 0x3c, 0xe6, 0xac, 0x54, 0x70, 0xda, 0x11, 0xdb, 0x87, 0xe2, 0xc2, 0x26, 0x7e, 0x48, 0x3b, 0xda, 0xf4, 0x98, 0x3c, 0x51}},
ShareProofs: []*types.NMTProof{
ShareProofs: []*pb.Proof{
{
Start: 0,
End: 1,
Expand Down
Loading