Skip to content

Commit

Permalink
feat: bumps the nmt version to v0.16.0 (#1793)
Browse files Browse the repository at this point in the history
## Overview
Integrates the latest NMT release.

## Checklist
- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords

---------

Co-authored-by: Evan Forbes <42654277+evan-forbes@users.noreply.github.com>
  • Loading branch information
staheri14 and evan-forbes committed May 22, 2023
1 parent ddaa261 commit 8541211
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
48 changes: 48 additions & 0 deletions pkg/wrapper/nmt_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 8541211

Please sign in to comment.