diff --git a/go.mod b/go.mod index aef1171617..a269795630 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/celestiaorg/celestia-app go 1.20 require ( - github.com/celestiaorg/nmt v0.15.0 + github.com/celestiaorg/nmt v0.16.0 github.com/celestiaorg/quantum-gravity-bridge v1.3.0 github.com/ethereum/go-ethereum v1.11.6 github.com/gogo/protobuf v1.3.3 diff --git a/go.sum b/go.sum index 65f2582b61..8fb96694d8 100644 --- a/go.sum +++ b/go.sum @@ -175,8 +175,8 @@ github.com/celestiaorg/cosmos-sdk v1.13.0-sdk-v0.46.11 h1:Rd5EvJx1nG3KurBspVN51R github.com/celestiaorg/cosmos-sdk v1.13.0-sdk-v0.46.11/go.mod h1:xCG6OUkJy5KUMEg20Zk010lra9XjkmKS3+bk0wp7bd8= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4/go.mod h1:fzuHnhzj1pUygGz+1ZkB3uQbEUL4htqCGJ4Qs2LwMZA= -github.com/celestiaorg/nmt v0.15.0 h1:ID9QlMIeP6WK/iiGcfnYLu2qqVIq0UYe/dc3TVPt6EA= -github.com/celestiaorg/nmt v0.15.0/go.mod h1:GfwIvQPhUakn1modWxJ+rv8dUjJzuXg5H+MLFM1o7nY= +github.com/celestiaorg/nmt v0.16.0 h1:4CX6d1Uwf1C+tGcAWskPve0HCDTnI4Ey8ffjiDwcGH0= +github.com/celestiaorg/nmt v0.16.0/go.mod h1:GfwIvQPhUakn1modWxJ+rv8dUjJzuXg5H+MLFM1o7nY= github.com/celestiaorg/quantum-gravity-bridge v1.3.0 h1:9zPIp7w1FWfkPnn16y3S4FpFLnQtS7rm81CUVcHEts0= github.com/celestiaorg/quantum-gravity-bridge v1.3.0/go.mod h1:6WOajINTDEUXpSj5UZzod16UZ96ZVB/rFNKyM+Mt1gI= github.com/celestiaorg/rsmt2d v0.9.0 h1:kon78I748ZqjNzI8OAqPN+2EImuZuanj/6gTh8brX3o= diff --git a/pkg/wrapper/nmt_wrapper_test.go b/pkg/wrapper/nmt_wrapper_test.go index 092550c608..38d00a6c2f 100644 --- a/pkg/wrapper/nmt_wrapper_test.go +++ b/pkg/wrapper/nmt_wrapper_test.go @@ -10,6 +10,7 @@ import ( "github.com/celestiaorg/celestia-app/pkg/namespace" appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/nmt" + nmtnamespace "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" "github.com/stretchr/testify/assert" tmrand "github.com/tendermint/tendermint/libs/rand" @@ -71,6 +72,22 @@ func TestRootErasuredNamespacedMerkleTree(t *testing.T) { assert.NotEqual(t, rootStandard, rootErasured) } +// TestErasuredNamespacedMerkleTreeEmptyRoot checks that the root of an empty erasured NMT is always the same +func TestErasuredNamespacedMerkleTreeEmptyRoot(t *testing.T) { + // set up a first tree with some parameters + tree1 := NewErasuredNamespacedMerkleTree(1, 0) + r1, err := tree1.Root() + assert.NoError(t, err) + + // set up a second tree with different parameters + tree2 := NewErasuredNamespacedMerkleTree(2, 1) + r2, err := tree2.Root() + assert.NoError(t, err) + + // as they are empty, the roots should be the same + assert.True(t, bytes.Equal(r1, r2)) +} + func TestErasureNamespacedMerkleTreePushErrors(t *testing.T) { squareSize := 16 @@ -149,3 +166,34 @@ func generateRandNamespacedRawData(count int) (result [][]byte) { func sortByteArrays(src [][]byte) { sort.Slice(src, func(i, j int) bool { return bytes.Compare(src[i], src[j]) < 0 }) } + +// TestErasuredNamespacedMerkleTree_ProveRange checks that the proof returned by the ProveRange for all the shares within the erasured data is non-empty. +func TestErasuredNamespacedMerkleTree_ProveRange(t *testing.T) { + for sqaureSize := 1; sqaureSize <= 16; sqaureSize++ { + tree := NewErasuredNamespacedMerkleTree(uint64(sqaureSize), 0, nmt.IgnoreMaxNamespace(true)) + data := generateErasuredData(t, sqaureSize, appconsts.DefaultCodec()) + for _, d := range data { + err := tree.Push(d) + assert.NoError(t, err) + } + + root, err := tree.Root() + assert.NoError(t, err) + // iterate over all the shares and check that the proof is non-empty and can be verified + for i := 0; i < len(data); i++ { + proof, err := tree.ProveRange(i, i+1) + assert.NoError(t, err) + assert.NotEmpty(t, proof.Nodes()) + assert.False(t, proof.IsEmptyProof()) + + var namespaceID nmtnamespace.ID + if i < sqaureSize { + namespaceID = data[i][:appconsts.NamespaceSize] + } else { + namespaceID = appns.ParitySharesNamespace.Bytes() + } + verfied := proof.VerifyInclusion(appconsts.NewBaseHashFunc(), namespaceID, [][]byte{data[i]}, root) + assert.True(t, verfied) + } + } +}