From 16fb2d6ff460d66d518c1e48171b5c8a0e0acdf2 Mon Sep 17 00:00:00 2001 From: sanaz Date: Fri, 23 Jun 2023 15:33:14 -0700 Subject: [PATCH 01/21] adds some tests --- proof_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/proof_test.go b/proof_test.go index 291de09..b321462 100644 --- a/proof_test.go +++ b/proof_test.go @@ -3,6 +3,7 @@ package nmt import ( "bytes" "crypto/sha256" + "fmt" "hash" "testing" @@ -683,3 +684,68 @@ func TestIsEmptyProofOverlapAbsenceProof(t *testing.T) { }) } } + +func Test_ShortAbsenceProof(t *testing.T) { + // create a Merkle tree with 8 leaves + tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 7, 8, 9) + qNID := []byte{5} + root, err := tree.Root() + assert.NoError(t, err) + + subtreeHash_4_9, err := tree.computeRoot(4, 8) + assert.NoError(t, err) + subtreeHash_0_4, err := tree.computeRoot(0, 4) + nodes := [][]byte{subtreeHash_0_4} + + proof := Proof{ + leafHash: subtreeHash_4_9, + nodes: nodes, + start: 1, + end: 2, + } + + res := proof.VerifyNamespace(sha256.New(), qNID, nil, root) + assert.True(t, res) +} + +func Test_ShortAbsenceProof2(t *testing.T) { + nID := namespace.ID{1} + // create a tree with 4 leaves, variables names match the figure above + n := New(sha256.New(), NamespaceIDSize(1)) + d0 := append([]byte{0}, []byte("data0")...) + d1 := append([]byte{2}, []byte("data1")...) + d2 := append([]byte{3}, []byte("data2")...) + d3 := append([]byte{4}, []byte("data3")...) + + n.Push(d0) + n.Push(d1) + n.Push(d2) + n.Push(d3) + + root, err := n.Root() + assert.NoError(t, err) + + hash1, err := n.computeRoot(0, 2) + assert.NoError(t, err) + hash2, err := n.computeRoot(2, 4) + assert.NoError(t, err) + leaf0 := n.leafHashes[0] + leaf1 := n.leafHashes[1] + + // attack scenario: create a partial proof from hash1 to the root instead of leaf1 to the root + partialProof := Proof{start: 0, end: 1, leafHash: hash1, nodes: [][]byte{hash2}, isMaxNamespaceIDIgnored: true} + // run VerifyNamespace for the fabricated absence proof and see if it can pass + if partialProof.VerifyNamespace(sha256.New(), nID, nil, root) { + fmt.Println("partial proof is successfully verified") // this will be executed + } else { + fmt.Println("verification of the partial proof failed") + } + + // correct scenario: create a full proof from leaf1 to the root + fullProof := Proof{start: 1, end: 2, leafHash: leaf1, nodes: [][]byte{leaf0, hash2}} + if fullProof.VerifyNamespace(sha256.New(), nID, nil, root) { + fmt.Println("full proof is successfully verified") // this will be executed + } else { + fmt.Println("verification of the full proof failed") + } +} From 93def73562f1fe99e0d702909520f9e50c435e80 Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 28 Jun 2023 13:33:29 -0700 Subject: [PATCH 02/21] adds more tests for different short absence proofs --- proof_test.go | 68 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/proof_test.go b/proof_test.go index 9c41bfa..03cf04b 100644 --- a/proof_test.go +++ b/proof_test.go @@ -716,20 +716,70 @@ func Test_ShortAbsenceProof(t *testing.T) { root, err := tree.Root() assert.NoError(t, err) - subtreeHash_4_9, err := tree.computeRoot(4, 8) + // create full absence proof + proof_full, err := tree.ProveNamespace(qNID) + assert.NoError(t, err) + leafHash := tree.leafHashes[proof_full.start] + + // prepare supporting data for short absence proof for one level higher than the leafHash + subtreeHash_4_6, err := tree.computeRoot(4, 6) + assert.NoError(t, err) + subtreeHash_6_8, err := tree.computeRoot(6, 8) assert.NoError(t, err) subtreeHash_0_4, err := tree.computeRoot(0, 4) - nodes := [][]byte{subtreeHash_0_4} + assert.NoError(t, err) + + // supporting data for the short absence proof two levels higher than the leafHash + subtreeHash_4_8, err := tree.computeRoot(4, 8) + assert.NoError(t, err) - proof := Proof{ - leafHash: subtreeHash_4_9, - nodes: nodes, - start: 1, - end: 2, + tests := []struct { + name string + qNID []byte + leafHash []byte + nodes [][]byte + start int + end int + }{ + { + name: "valid full absence proof", + qNID: qNID, + leafHash: leafHash, + nodes: proof_full.nodes, + start: proof_full.start, + end: proof_full.end, + }, + { + name: "valid short absence proof: one level higher", + qNID: qNID, + leafHash: subtreeHash_4_6, + nodes: [][]byte{subtreeHash_0_4, subtreeHash_6_8}, + start: 2, + end: 3, + }, + { + name: "valid short absence proof: two levels higher", + qNID: qNID, + leafHash: subtreeHash_4_8, + nodes: [][]byte{subtreeHash_0_4}, + start: 1, + end: 2, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + proof := Proof{ + leafHash: tt.leafHash, + nodes: tt.nodes, + start: tt.start, + end: tt.end, + } + + res := proof.VerifyNamespace(sha256.New(), qNID, nil, root) + assert.True(t, res) + }) } - res := proof.VerifyNamespace(sha256.New(), qNID, nil, root) - assert.True(t, res) } func Test_ShortAbsenceProof2(t *testing.T) { From 5bad12322d3cc49950701babea500cb15eaa77bc Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 28 Jun 2023 13:40:19 -0700 Subject: [PATCH 03/21] adds comment visualizing the tree structure --- proof_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/proof_test.go b/proof_test.go index 03cf04b..f10a9c5 100644 --- a/proof_test.go +++ b/proof_test.go @@ -716,6 +716,17 @@ func Test_ShortAbsenceProof(t *testing.T) { root, err := tree.Root() assert.NoError(t, err) + // N_0_8 Tree Root + // / \ + // / \ + // N_0_4 N_4_8 Non-Leaf Nodes + // / \ / \ + // / \ / \ + // N_0_2 N_2_4 N_4_4 N_6_8 Non-Leaf Nodes + // / \ / \ / \ / \ + // N_0_1 N_1_2 N_2_3 N_3_4 N_4_5 N_5_6 N_6_7 N_7_8 Leaf Hashes + // 1 2 3 4 6 7 8 9 Leaf namespaces + // create full absence proof proof_full, err := tree.ProveNamespace(qNID) assert.NoError(t, err) From d319f064069c8e06aaef13aab9b42315477f8cbd Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:20:44 -0700 Subject: [PATCH 04/21] makes further improvements to the test w.r.t. readability --- proof_test.go | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/proof_test.go b/proof_test.go index f10a9c5..f58be07 100644 --- a/proof_test.go +++ b/proof_test.go @@ -712,7 +712,7 @@ func TestIsEmptyProofOverlapAbsenceProof(t *testing.T) { func Test_ShortAbsenceProof(t *testing.T) { // create a Merkle tree with 8 leaves tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 7, 8, 9) - qNID := []byte{5} + qNS := []byte{5} // does not belong to the tree root, err := tree.Root() assert.NoError(t, err) @@ -722,26 +722,26 @@ func Test_ShortAbsenceProof(t *testing.T) { // N_0_4 N_4_8 Non-Leaf Nodes // / \ / \ // / \ / \ - // N_0_2 N_2_4 N_4_4 N_6_8 Non-Leaf Nodes + // N_0_2 N_2_4 N_4_6 N_6_8 Non-Leaf Nodes // / \ / \ / \ / \ // N_0_1 N_1_2 N_2_3 N_3_4 N_4_5 N_5_6 N_6_7 N_7_8 Leaf Hashes // 1 2 3 4 6 7 8 9 Leaf namespaces + // 0 1 2 3 4 5 6 7 Leaf indexes - // create full absence proof - proof_full, err := tree.ProveNamespace(qNID) + // nodes needed for the full absence proof of qNS + N_4_5 := tree.leafHashes[4] + N_5_6 := tree.leafHashes[5] + N_6_8, err := tree.computeRoot(6, 8) assert.NoError(t, err) - leafHash := tree.leafHashes[proof_full.start] - - // prepare supporting data for short absence proof for one level higher than the leafHash - subtreeHash_4_6, err := tree.computeRoot(4, 6) - assert.NoError(t, err) - subtreeHash_6_8, err := tree.computeRoot(6, 8) + N_0_4, err := tree.computeRoot(0, 4) assert.NoError(t, err) - subtreeHash_0_4, err := tree.computeRoot(0, 4) + + // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of N_4_5 + N_4_6, err := tree.computeRoot(4, 6) assert.NoError(t, err) - // supporting data for the short absence proof two levels higher than the leafHash - subtreeHash_4_8, err := tree.computeRoot(4, 8) + // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of N_4_5 + N_4_8, err := tree.computeRoot(4, 8) assert.NoError(t, err) tests := []struct { @@ -754,26 +754,26 @@ func Test_ShortAbsenceProof(t *testing.T) { }{ { name: "valid full absence proof", - qNID: qNID, - leafHash: leafHash, - nodes: proof_full.nodes, - start: proof_full.start, - end: proof_full.end, + qNID: qNS, + leafHash: N_4_5, + nodes: [][]byte{N_0_4, N_5_6, N_6_8}, + start: 4, // N_4_5 is at index position 4 (from left to right) at its respective level + end: 5, }, { name: "valid short absence proof: one level higher", - qNID: qNID, - leafHash: subtreeHash_4_6, - nodes: [][]byte{subtreeHash_0_4, subtreeHash_6_8}, - start: 2, + qNID: qNS, + leafHash: N_4_6, + nodes: [][]byte{N_0_4, N_6_8}, + start: 2, // N_4_6 is at index position 2 (from left to right) at its respective level end: 3, }, { name: "valid short absence proof: two levels higher", - qNID: qNID, - leafHash: subtreeHash_4_8, - nodes: [][]byte{subtreeHash_0_4}, - start: 1, + qNID: qNS, + leafHash: N_4_8, + nodes: [][]byte{N_0_4}, + start: 1, // N_4_8 is at index position 1 (from left to right) at its respective level end: 2, }, } @@ -786,7 +786,7 @@ func Test_ShortAbsenceProof(t *testing.T) { end: tt.end, } - res := proof.VerifyNamespace(sha256.New(), qNID, nil, root) + res := proof.VerifyNamespace(sha256.New(), qNS, nil, root) assert.True(t, res) }) } From 1bf8b75c57254bdd3d89d5c953f9e178cb511188 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:32:36 -0700 Subject: [PATCH 05/21] revises the test docs and resolves linter bugs --- proof_test.go | 59 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/proof_test.go b/proof_test.go index f58be07..df8f195 100644 --- a/proof_test.go +++ b/proof_test.go @@ -709,39 +709,40 @@ func TestIsEmptyProofOverlapAbsenceProof(t *testing.T) { } } -func Test_ShortAbsenceProof(t *testing.T) { +// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace can correctly verify short namespace absence proofs +func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { // create a Merkle tree with 8 leaves tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 7, 8, 9) qNS := []byte{5} // does not belong to the tree root, err := tree.Root() assert.NoError(t, err) - // N_0_8 Tree Root - // / \ - // / \ - // N_0_4 N_4_8 Non-Leaf Nodes - // / \ / \ - // / \ / \ - // N_0_2 N_2_4 N_4_6 N_6_8 Non-Leaf Nodes - // / \ / \ / \ / \ - // N_0_1 N_1_2 N_2_3 N_3_4 N_4_5 N_5_6 N_6_7 N_7_8 Leaf Hashes - // 1 2 3 4 6 7 8 9 Leaf namespaces - // 0 1 2 3 4 5 6 7 Leaf indexes + // Node_0_8 Tree Root + // / \ + // / \ + // Node_0_4 Node_4_8 Non-Leaf Node + // / \ / \ + // / \ / \ + // Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node + // / \ / \ / \ / \ + // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash + // 1 2 3 4 6 7 8 9 Leaf namespace + // 0 1 2 3 4 5 6 7 Leaf index // nodes needed for the full absence proof of qNS - N_4_5 := tree.leafHashes[4] - N_5_6 := tree.leafHashes[5] - N_6_8, err := tree.computeRoot(6, 8) + Node_4_5 := tree.leafHashes[4] + Node_5_6 := tree.leafHashes[5] + Node_6_8, err := tree.computeRoot(6, 8) assert.NoError(t, err) - N_0_4, err := tree.computeRoot(0, 4) + Node_0_4, err := tree.computeRoot(0, 4) assert.NoError(t, err) - // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of N_4_5 - N_4_6, err := tree.computeRoot(4, 6) + // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node_4_5 + Node_4_6, err := tree.computeRoot(4, 6) assert.NoError(t, err) - // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of N_4_5 - N_4_8, err := tree.computeRoot(4, 8) + // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node_4_5 + Node_4_8, err := tree.computeRoot(4, 8) assert.NoError(t, err) tests := []struct { @@ -755,25 +756,25 @@ func Test_ShortAbsenceProof(t *testing.T) { { name: "valid full absence proof", qNID: qNS, - leafHash: N_4_5, - nodes: [][]byte{N_0_4, N_5_6, N_6_8}, - start: 4, // N_4_5 is at index position 4 (from left to right) at its respective level + leafHash: Node_4_5, + nodes: [][]byte{Node_0_4, Node_5_6, Node_6_8}, + start: 4, // Node_4_5 is at index position 4 (from left to right) at its respective level end: 5, }, { name: "valid short absence proof: one level higher", qNID: qNS, - leafHash: N_4_6, - nodes: [][]byte{N_0_4, N_6_8}, - start: 2, // N_4_6 is at index position 2 (from left to right) at its respective level + leafHash: Node_4_6, + nodes: [][]byte{Node_0_4, Node_6_8}, + start: 2, // Node_4_6 is at index position 2 (from left to right) at its respective level end: 3, }, { name: "valid short absence proof: two levels higher", qNID: qNS, - leafHash: N_4_8, - nodes: [][]byte{N_0_4}, - start: 1, // N_4_8 is at index position 1 (from left to right) at its respective level + leafHash: Node_4_8, + nodes: [][]byte{Node_0_4}, + start: 1, // Node_4_8 is at index position 1 (from left to right) at its respective level end: 2, }, } From 53a96e2b930ee9f58a1da306fd20353860034d82 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:34:05 -0700 Subject: [PATCH 06/21] fixes spacing misalignment --- proof_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proof_test.go b/proof_test.go index df8f195..81e459a 100644 --- a/proof_test.go +++ b/proof_test.go @@ -726,7 +726,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { // Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node // / \ / \ / \ / \ // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash - // 1 2 3 4 6 7 8 9 Leaf namespace + // 1 2 3 4 6 7 8 9 Leaf namespace // 0 1 2 3 4 5 6 7 Leaf index // nodes needed for the full absence proof of qNS From e3242c9979df4c11da9854658288d76651be6861 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:35:14 -0700 Subject: [PATCH 07/21] updates namespaces --- proof_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proof_test.go b/proof_test.go index 81e459a..6200701 100644 --- a/proof_test.go +++ b/proof_test.go @@ -726,7 +726,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { // Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node // / \ / \ / \ / \ // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash - // 1 2 3 4 6 7 8 9 Leaf namespace + // 1 2 3 4 6 7 8 9 Leaf index // 0 1 2 3 4 5 6 7 Leaf index // nodes needed for the full absence proof of qNS From 43cc59ff49b024486afbaf71b8c7c55195fa1c40 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:35:47 -0700 Subject: [PATCH 08/21] fixes a typo --- proof_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proof_test.go b/proof_test.go index 6200701..6064a65 100644 --- a/proof_test.go +++ b/proof_test.go @@ -726,7 +726,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { // Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node // / \ / \ / \ / \ // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash - // 1 2 3 4 6 7 8 9 Leaf index + // 1 2 3 4 6 7 8 9 Leaf namespace // 0 1 2 3 4 5 6 7 Leaf index // nodes needed for the full absence proof of qNS From c72bf971412d58b1793667221e38f25cd01e2dd0 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:36:41 -0700 Subject: [PATCH 09/21] removes unused tests --- proof_test.go | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/proof_test.go b/proof_test.go index 6064a65..5b4f789 100644 --- a/proof_test.go +++ b/proof_test.go @@ -3,7 +3,6 @@ package nmt import ( "bytes" "crypto/sha256" - "fmt" "hash" "testing" @@ -793,45 +792,3 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { } } - -func Test_ShortAbsenceProof2(t *testing.T) { - nID := namespace.ID{1} - // create a tree with 4 leaves, variables names match the figure above - n := New(sha256.New(), NamespaceIDSize(1)) - d0 := append([]byte{0}, []byte("data0")...) - d1 := append([]byte{2}, []byte("data1")...) - d2 := append([]byte{3}, []byte("data2")...) - d3 := append([]byte{4}, []byte("data3")...) - - n.Push(d0) - n.Push(d1) - n.Push(d2) - n.Push(d3) - - root, err := n.Root() - assert.NoError(t, err) - - hash1, err := n.computeRoot(0, 2) - assert.NoError(t, err) - hash2, err := n.computeRoot(2, 4) - assert.NoError(t, err) - leaf0 := n.leafHashes[0] - leaf1 := n.leafHashes[1] - - // attack scenario: create a partial proof from hash1 to the root instead of leaf1 to the root - partialProof := Proof{start: 0, end: 1, leafHash: hash1, nodes: [][]byte{hash2}, isMaxNamespaceIDIgnored: true} - // run VerifyNamespace for the fabricated absence proof and see if it can pass - if partialProof.VerifyNamespace(sha256.New(), nID, nil, root) { - fmt.Println("partial proof is successfully verified") // this will be executed - } else { - fmt.Println("verification of the partial proof failed") - } - - // correct scenario: create a full proof from leaf1 to the root - fullProof := Proof{start: 1, end: 2, leafHash: leaf1, nodes: [][]byte{leaf0, hash2}} - if fullProof.VerifyNamespace(sha256.New(), nID, nil, root) { - fmt.Println("full proof is successfully verified") // this will be executed - } else { - fmt.Println("verification of the full proof failed") - } -} From 7eb4aef4f83a44623f8609a00dfa4ea2ee877323 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:45:50 -0700 Subject: [PATCH 10/21] adds invalid short absence proof tests --- proof_test.go | 97 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/proof_test.go b/proof_test.go index 5b4f789..9849579 100644 --- a/proof_test.go +++ b/proof_test.go @@ -757,7 +757,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { qNID: qNS, leafHash: Node_4_5, nodes: [][]byte{Node_0_4, Node_5_6, Node_6_8}, - start: 4, // Node_4_5 is at index position 4 (from left to right) at its respective level + start: 4, // the index position of leafHash at its respective level end: 5, }, { @@ -765,7 +765,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { qNID: qNS, leafHash: Node_4_6, nodes: [][]byte{Node_0_4, Node_6_8}, - start: 2, // Node_4_6 is at index position 2 (from left to right) at its respective level + start: 2, // the index position of leafHash at its respective level end: 3, }, { @@ -773,7 +773,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { qNID: qNS, leafHash: Node_4_8, nodes: [][]byte{Node_0_4}, - start: 1, // Node_4_8 is at index position 1 (from left to right) at its respective level + start: 1, // the index position of leafHash at its respective level end: 2, }, } @@ -792,3 +792,94 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { } } + +// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace can correctly verify short namespace absence proofs +func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { + // create a Merkle tree with 8 leaves + tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 8, 8, 8) + qNS := []byte{7} // does not belong to the tree + root, err := tree.Root() + assert.NoError(t, err) + + // Node_0_8 Tree Root + // / \ + // / \ + // Node_0_4 Node_4_8 Non-Leaf Node + // / \ / \ + // / \ / \ + // Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node + // / \ / \ / \ / \ + // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash + // 1 2 3 4 6 8 8 8 Leaf namespace + // 0 1 2 3 4 5 6 7 Leaf index + + // nodes needed for the full absence proof of qNS + Node_5_6 := tree.leafHashes[5] + Node_4_5 := tree.leafHashes[4] + Node_6_8, err := tree.computeRoot(6, 8) + assert.NoError(t, err) + Node_0_4, err := tree.computeRoot(0, 4) + assert.NoError(t, err) + + // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node_4_5; + // this case should not work since the namespace range o Node_4_6, the parent, has overlap with the qNS i.e., 7 + Node_4_6, err := tree.computeRoot(4, 6) + assert.NoError(t, err) + + // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node_4_5 + // this case should not work since the namespace range of Node_4_8, the grandparent, has overlap with the qNS i.e., 7 + Node_4_8, err := tree.computeRoot(4, 8) + assert.NoError(t, err) + + tests := []struct { + name string + qNID []byte + leafHash []byte + nodes [][]byte + start int + end int + want bool + }{ + { + name: "valid full absence proof", + qNID: qNS, + leafHash: Node_5_6, + nodes: [][]byte{Node_0_4, Node_4_5, Node_6_8}, + start: 5, // the index position of leafHash at its respective level + end: 6, + want: true, + }, + { + name: "invalid short absence proof: one level higher", + qNID: qNS, + leafHash: Node_4_6, + nodes: [][]byte{Node_0_4, Node_6_8}, + start: 2, // the index position of leafHash at its respective level + end: 3, + want: false, + }, + { + name: "invalid short absence proof: two levels higher", + qNID: qNS, + leafHash: Node_4_8, + nodes: [][]byte{Node_0_4}, + start: 1, // the index position of leafHash at its respective level + end: 2, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + proof := Proof{ + leafHash: tt.leafHash, + nodes: tt.nodes, + start: tt.start, + end: tt.end, + } + + res := proof.VerifyNamespace(sha256.New(), qNS, nil, root) + assert.Equal(t, tt.want, res) + }) + } + +} From d54fdfc1b4307f1978833135d3858c3e10889c71 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:48:38 -0700 Subject: [PATCH 11/21] clarifies the result of verification --- proof_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proof_test.go b/proof_test.go index 9849579..12409ff 100644 --- a/proof_test.go +++ b/proof_test.go @@ -821,13 +821,13 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { Node_0_4, err := tree.computeRoot(0, 4) assert.NoError(t, err) - // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node_4_5; - // this case should not work since the namespace range o Node_4_6, the parent, has overlap with the qNS i.e., 7 + // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node_5_6; + // the verification should fail since the namespace range o Node_4_6, the parent, has overlap with the qNS i.e., 7 Node_4_6, err := tree.computeRoot(4, 6) assert.NoError(t, err) - // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node_4_5 - // this case should not work since the namespace range of Node_4_8, the grandparent, has overlap with the qNS i.e., 7 + // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node_5_6 + // the verification should fail since the namespace range of Node_4_8, the grandparent, has overlap with the qNS i.e., 7 Node_4_8, err := tree.computeRoot(4, 8) assert.NoError(t, err) From 91350bfece6693e208c0418a10e86107c2812c6c Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:49:52 -0700 Subject: [PATCH 12/21] adds godoc --- proof_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proof_test.go b/proof_test.go index 12409ff..ce36bad 100644 --- a/proof_test.go +++ b/proof_test.go @@ -793,7 +793,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { } -// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace can correctly verify short namespace absence proofs +// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace rejects invalid short absence proofs. func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { // create a Merkle tree with 8 leaves tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 8, 8, 8) From b524c73e05b4096420107b7ed23925b1bf2b4af5 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:50:43 -0700 Subject: [PATCH 13/21] fixes the mismatch bw func name and the godoc --- proof_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proof_test.go b/proof_test.go index ce36bad..5f3cc3b 100644 --- a/proof_test.go +++ b/proof_test.go @@ -793,7 +793,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { } -// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace rejects invalid short absence proofs. +// TestVerifyNamespace_ShortAbsenceProof_Invalid checks whether VerifyNamespace rejects invalid short absence proofs. func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { // create a Merkle tree with 8 leaves tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 8, 8, 8) From 5c26003b168cca4a93a8f5e0fe1c2bd113e1d47d Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 11:55:03 -0700 Subject: [PATCH 14/21] removes underscore from var names due to linter complaints --- proof_test.go | 74 +++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/proof_test.go b/proof_test.go index 5f3cc3b..0a732bd 100644 --- a/proof_test.go +++ b/proof_test.go @@ -719,29 +719,29 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { // Node_0_8 Tree Root // / \ // / \ - // Node_0_4 Node_4_8 Non-Leaf Node + // Node0_4 Node4_8 Non-Leaf Node // / \ / \ // / \ / \ - // Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node + // Node_0_2 Node_2_4 Node4_6 Node6_8 Non-Leaf Node // / \ / \ / \ / \ - // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash + // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node4_5 Node5_6 Node_6_7 Node_7_8 Leaf Hash // 1 2 3 4 6 7 8 9 Leaf namespace // 0 1 2 3 4 5 6 7 Leaf index // nodes needed for the full absence proof of qNS - Node_4_5 := tree.leafHashes[4] - Node_5_6 := tree.leafHashes[5] - Node_6_8, err := tree.computeRoot(6, 8) + Node4_5 := tree.leafHashes[4] + Node5_6 := tree.leafHashes[5] + Node6_8, err := tree.computeRoot(6, 8) assert.NoError(t, err) - Node_0_4, err := tree.computeRoot(0, 4) + Node0_4, err := tree.computeRoot(0, 4) assert.NoError(t, err) - // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node_4_5 - Node_4_6, err := tree.computeRoot(4, 6) + // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node4_5 + Node4_6, err := tree.computeRoot(4, 6) assert.NoError(t, err) - // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node_4_5 - Node_4_8, err := tree.computeRoot(4, 8) + // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node4_5 + Node4_8, err := tree.computeRoot(4, 8) assert.NoError(t, err) tests := []struct { @@ -755,24 +755,24 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { { name: "valid full absence proof", qNID: qNS, - leafHash: Node_4_5, - nodes: [][]byte{Node_0_4, Node_5_6, Node_6_8}, + leafHash: Node4_5, + nodes: [][]byte{Node0_4, Node5_6, Node6_8}, start: 4, // the index position of leafHash at its respective level end: 5, }, { name: "valid short absence proof: one level higher", qNID: qNS, - leafHash: Node_4_6, - nodes: [][]byte{Node_0_4, Node_6_8}, + leafHash: Node4_6, + nodes: [][]byte{Node0_4, Node6_8}, start: 2, // the index position of leafHash at its respective level end: 3, }, { name: "valid short absence proof: two levels higher", qNID: qNS, - leafHash: Node_4_8, - nodes: [][]byte{Node_0_4}, + leafHash: Node4_8, + nodes: [][]byte{Node0_4}, start: 1, // the index position of leafHash at its respective level end: 2, }, @@ -790,7 +790,6 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { assert.True(t, res) }) } - } // TestVerifyNamespace_ShortAbsenceProof_Invalid checks whether VerifyNamespace rejects invalid short absence proofs. @@ -804,31 +803,31 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { // Node_0_8 Tree Root // / \ // / \ - // Node_0_4 Node_4_8 Non-Leaf Node + // Node0_4 Node4_8 Non-Leaf Node // / \ / \ // / \ / \ - // Node_0_2 Node_2_4 Node_4_6 Node_6_8 Non-Leaf Node + // Node_0_2 Node_2_4 Node4_6 Node6_8 Non-Leaf Node // / \ / \ / \ / \ - // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node_4_5 Node_5_6 Node_6_7 Node_7_8 Leaf Hash + // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node4_5 Node5_6 Node_6_7 Node_7_8 Leaf Hash // 1 2 3 4 6 8 8 8 Leaf namespace // 0 1 2 3 4 5 6 7 Leaf index // nodes needed for the full absence proof of qNS - Node_5_6 := tree.leafHashes[5] - Node_4_5 := tree.leafHashes[4] - Node_6_8, err := tree.computeRoot(6, 8) + Node5_6 := tree.leafHashes[5] + Node4_5 := tree.leafHashes[4] + Node6_8, err := tree.computeRoot(6, 8) assert.NoError(t, err) - Node_0_4, err := tree.computeRoot(0, 4) + Node0_4, err := tree.computeRoot(0, 4) assert.NoError(t, err) - // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node_5_6; - // the verification should fail since the namespace range o Node_4_6, the parent, has overlap with the qNS i.e., 7 - Node_4_6, err := tree.computeRoot(4, 6) + // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node5_6; + // the verification should fail since the namespace range o Node4_6, the parent, has overlap with the qNS i.e., 7 + Node4_6, err := tree.computeRoot(4, 6) assert.NoError(t, err) - // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node_5_6 - // the verification should fail since the namespace range of Node_4_8, the grandparent, has overlap with the qNS i.e., 7 - Node_4_8, err := tree.computeRoot(4, 8) + // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node5_6 + // the verification should fail since the namespace range of Node4_8, the grandparent, has overlap with the qNS i.e., 7 + Node4_8, err := tree.computeRoot(4, 8) assert.NoError(t, err) tests := []struct { @@ -843,8 +842,8 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { { name: "valid full absence proof", qNID: qNS, - leafHash: Node_5_6, - nodes: [][]byte{Node_0_4, Node_4_5, Node_6_8}, + leafHash: Node5_6, + nodes: [][]byte{Node0_4, Node4_5, Node6_8}, start: 5, // the index position of leafHash at its respective level end: 6, want: true, @@ -852,8 +851,8 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { { name: "invalid short absence proof: one level higher", qNID: qNS, - leafHash: Node_4_6, - nodes: [][]byte{Node_0_4, Node_6_8}, + leafHash: Node4_6, + nodes: [][]byte{Node0_4, Node6_8}, start: 2, // the index position of leafHash at its respective level end: 3, want: false, @@ -861,8 +860,8 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { { name: "invalid short absence proof: two levels higher", qNID: qNS, - leafHash: Node_4_8, - nodes: [][]byte{Node_0_4}, + leafHash: Node4_8, + nodes: [][]byte{Node0_4}, start: 1, // the index position of leafHash at its respective level end: 2, want: false, @@ -881,5 +880,4 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { assert.Equal(t, tt.want, res) }) } - } From fb9c288d3ce3579c997513c4cb8324f1bd821bd3 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 12:15:41 -0700 Subject: [PATCH 15/21] updates VerifyNamespace description --- proof.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/proof.go b/proof.go index de307db..b28219d 100644 --- a/proof.go +++ b/proof.go @@ -146,22 +146,22 @@ func (proof Proof) IsEmptyProof() bool { } // VerifyNamespace verifies a whole namespace, i.e. 1) it verifies inclusion of -// the provided `data` in the tree (or the proof.leafHash in case of absence -// proof) 2) it verifies that the namespace is complete i.e., the data items -// matching the namespace ID `nID` are within the range [`proof.start`, -// `proof.end`) and no data of that namespace was left out. VerifyNamespace +// the provided `leaves` in the tree (or the proof.leafHash in case of +// full/short absence proof) 2) it verifies that the namespace is complete +// i.e., the data items matching the namespace ID `nID` are within the range +// [`proof.start`, `proof.end`) and no data of that namespace was left out. VerifyNamespace // deems an empty `proof` valid if the queried `nID` falls outside the namespace // range of the supplied `root` or if the `root` is empty // // `h` MUST be the same as the underlying hash function used to generate the // proof. Otherwise, the verification will fail. `nID` is the namespace ID for -// which the namespace `proof` is generated. `data` contains the namespaced data -// items (but not namespace hash) underlying the leaves of the tree in the -// range of [`proof.start`, `proof.end`). For an absence `proof`, the `data` is -// empty. `data` items MUST be ordered according to their index in the tree, -// with `data[0]` corresponding to the namespaced data at index `start`, +// which the namespace `proof` is generated. `leaves` contains the namespaced +// leaves of the tree in the range of [`proof.start`, `proof.end`). +// For an absence `proof`, the `leaves` is empty. +// `leaves` items MUST be ordered according to their index in the tree, +// with `data[0]` corresponding to the namespaced leaf at index `start`, // -// and the last element in `data` corresponding to the data item at index +// and the last element in `leaves` corresponding to the leaf at index // `end-1` of the tree. // // `root` is the root of the NMT against which the `proof` is verified. From 8674eecbab59b67119ba2b5c63e7e035b730be1e Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 12:21:59 -0700 Subject: [PATCH 16/21] wraps lines to 80 chars --- proof.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/proof.go b/proof.go index b28219d..09aab16 100644 --- a/proof.go +++ b/proof.go @@ -149,9 +149,9 @@ func (proof Proof) IsEmptyProof() bool { // the provided `leaves` in the tree (or the proof.leafHash in case of // full/short absence proof) 2) it verifies that the namespace is complete // i.e., the data items matching the namespace ID `nID` are within the range -// [`proof.start`, `proof.end`) and no data of that namespace was left out. VerifyNamespace -// deems an empty `proof` valid if the queried `nID` falls outside the namespace -// range of the supplied `root` or if the `root` is empty +// [`proof.start`, `proof.end`) and no data of that namespace was left out. +// VerifyNamespace deems an empty `proof` valid if the queried `nID` falls +// outside the namespace range of the supplied `root` or if the `root` is empty // // `h` MUST be the same as the underlying hash function used to generate the // proof. Otherwise, the verification will fail. `nID` is the namespace ID for @@ -160,9 +160,8 @@ func (proof Proof) IsEmptyProof() bool { // For an absence `proof`, the `leaves` is empty. // `leaves` items MUST be ordered according to their index in the tree, // with `data[0]` corresponding to the namespaced leaf at index `start`, -// -// and the last element in `leaves` corresponding to the leaf at index -// `end-1` of the tree. +// and the last element in `leaves` corresponding to the leaf at index `end-1` +// of the tree. // // `root` is the root of the NMT against which the `proof` is verified. func (proof Proof) VerifyNamespace(h hash.Hash, nID namespace.ID, leaves [][]byte, root []byte) bool { From 2adf16f1c5bdab99eb6e83692a71692c2fc967e2 Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 29 Jun 2023 12:38:36 -0700 Subject: [PATCH 17/21] minor revisions --- proof_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/proof_test.go b/proof_test.go index 0a732bd..af77a97 100644 --- a/proof_test.go +++ b/proof_test.go @@ -708,7 +708,8 @@ func TestIsEmptyProofOverlapAbsenceProof(t *testing.T) { } } -// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace can correctly verify short namespace absence proofs +// TestVerifyNamespace_ShortAbsenceProof_Valid checks whether VerifyNamespace +// can correctly verify short namespace absence proofs func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { // create a Merkle tree with 8 leaves tree := exampleNMT(1, true, 1, 2, 3, 4, 6, 7, 8, 9) @@ -736,11 +737,14 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { Node0_4, err := tree.computeRoot(0, 4) assert.NoError(t, err) - // nodes needed for the short absence proof of qNS; the proof of inclusion of the parent of Node4_5 + // nodes needed for the short absence proof of qNS; the proof of inclusion + // of the parent of Node4_5 + Node4_6, err := tree.computeRoot(4, 6) assert.NoError(t, err) - // nodes needed for another short absence parent of qNS; the proof of inclusion of the grandparent of Node4_5 + // nodes needed for another short absence parent of qNS; the proof of + // inclusion of the grandparent of Node4_5 Node4_8, err := tree.computeRoot(4, 8) assert.NoError(t, err) From b763911192552410e6dcbe2d7666263bc47c0e9a Mon Sep 17 00:00:00 2001 From: sanaz Date: Mon, 3 Jul 2023 10:37:36 -0700 Subject: [PATCH 18/21] elaborates on the nodes' suffix format --- proof_test.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/proof_test.go b/proof_test.go index af77a97..70dd259 100644 --- a/proof_test.go +++ b/proof_test.go @@ -716,16 +716,20 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { qNS := []byte{5} // does not belong to the tree root, err := tree.Root() assert.NoError(t, err) - + // In the following illustration, nodes are suffixed with the range + // of leaves they cover, with the upper bound being non-inclusive. + // For example, Node3_4 denotes a node that covers the 3rd leaf (excluding the 4th leaf), + // while Node4_6 represents the node that covers the 4th and 5th leaves. + // // Node_0_8 Tree Root // / \ // / \ - // Node0_4 Node4_8 Non-Leaf Node + // Node0_4 Node4_8 Non-Leaf Node // / \ / \ // / \ / \ - // Node_0_2 Node_2_4 Node4_6 Node6_8 Non-Leaf Node + // Node_0_2 Node_2_4 Node4_6 Node6_8 Non-Leaf Node // / \ / \ / \ / \ - // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node4_5 Node5_6 Node_6_7 Node_7_8 Leaf Hash + // Node0_1 Node1_2 Node2_3 Node3_4 Node4_5 Node5_6 Node6_7 Node7_8 Leaf Hash // 1 2 3 4 6 7 8 9 Leaf namespace // 0 1 2 3 4 5 6 7 Leaf index @@ -803,16 +807,20 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { qNS := []byte{7} // does not belong to the tree root, err := tree.Root() assert.NoError(t, err) - + // In the following illustration, nodes are suffixed with the range + // of leaves they cover, with the upper bound being non-inclusive. + // For example, Node3_4 denotes a node that covers the 3rd leaf (excluding the 4th leaf), + // while Node4_6 represents the node that covers the 4th and 5th leaves. + // // Node_0_8 Tree Root // / \ // / \ - // Node0_4 Node4_8 Non-Leaf Node + // Node0_4 Node4_8 Non-Leaf Node // / \ / \ // / \ / \ - // Node_0_2 Node_2_4 Node4_6 Node6_8 Non-Leaf Node + // Node0_2 Node2_4 Node4_6 Node6_8 Non-Leaf Node // / \ / \ / \ / \ - // Node_0_1 Node_1_2 Node_2_3 Node_3_4 Node4_5 Node5_6 Node_6_7 Node_7_8 Leaf Hash + // Node0_1 Node1_2 Node2_3 Node_3_4 Node4_5 Node5_6 Node6_7 Node7_8 Leaf Hash // 1 2 3 4 6 8 8 8 Leaf namespace // 0 1 2 3 4 5 6 7 Leaf index From 5c67fe47f0e66f592acab664760bad48442a270c Mon Sep 17 00:00:00 2001 From: sanaz Date: Mon, 3 Jul 2023 10:39:44 -0700 Subject: [PATCH 19/21] fixes the parameter name --- proof.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proof.go b/proof.go index 09aab16..966bab9 100644 --- a/proof.go +++ b/proof.go @@ -159,7 +159,7 @@ func (proof Proof) IsEmptyProof() bool { // leaves of the tree in the range of [`proof.start`, `proof.end`). // For an absence `proof`, the `leaves` is empty. // `leaves` items MUST be ordered according to their index in the tree, -// with `data[0]` corresponding to the namespaced leaf at index `start`, +// with `leaves[0]` corresponding to the namespaced leaf at index `start`, // and the last element in `leaves` corresponding to the leaf at index `end-1` // of the tree. // From 3b33555ecb8eeacafdb085541debd57efd36a2fe Mon Sep 17 00:00:00 2001 From: sanaz Date: Mon, 3 Jul 2023 10:40:46 -0700 Subject: [PATCH 20/21] removes ID --- proof.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proof.go b/proof.go index 966bab9..eea0730 100644 --- a/proof.go +++ b/proof.go @@ -148,7 +148,7 @@ func (proof Proof) IsEmptyProof() bool { // VerifyNamespace verifies a whole namespace, i.e. 1) it verifies inclusion of // the provided `leaves` in the tree (or the proof.leafHash in case of // full/short absence proof) 2) it verifies that the namespace is complete -// i.e., the data items matching the namespace ID `nID` are within the range +// i.e., the data items matching the namespace `nID` are within the range // [`proof.start`, `proof.end`) and no data of that namespace was left out. // VerifyNamespace deems an empty `proof` valid if the queried `nID` falls // outside the namespace range of the supplied `root` or if the `root` is empty From 1e56c61cce1da94de94841728079635f45db847a Mon Sep 17 00:00:00 2001 From: sanaz Date: Mon, 3 Jul 2023 10:58:54 -0700 Subject: [PATCH 21/21] removes leading _ --- proof_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proof_test.go b/proof_test.go index 70dd259..9d308c3 100644 --- a/proof_test.go +++ b/proof_test.go @@ -721,13 +721,13 @@ func TestVerifyNamespace_ShortAbsenceProof_Valid(t *testing.T) { // For example, Node3_4 denotes a node that covers the 3rd leaf (excluding the 4th leaf), // while Node4_6 represents the node that covers the 4th and 5th leaves. // - // Node_0_8 Tree Root + // Node0_8 Tree Root // / \ // / \ // Node0_4 Node4_8 Non-Leaf Node // / \ / \ // / \ / \ - // Node_0_2 Node_2_4 Node4_6 Node6_8 Non-Leaf Node + // Node0_2 Node2_4 Node4_6 Node6_8 Non-Leaf Node // / \ / \ / \ / \ // Node0_1 Node1_2 Node2_3 Node3_4 Node4_5 Node5_6 Node6_7 Node7_8 Leaf Hash // 1 2 3 4 6 7 8 9 Leaf namespace @@ -812,7 +812,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { // For example, Node3_4 denotes a node that covers the 3rd leaf (excluding the 4th leaf), // while Node4_6 represents the node that covers the 4th and 5th leaves. // - // Node_0_8 Tree Root + // Node0_8 Tree Root // / \ // / \ // Node0_4 Node4_8 Non-Leaf Node @@ -820,7 +820,7 @@ func TestVerifyNamespace_ShortAbsenceProof_Invalid(t *testing.T) { // / \ / \ // Node0_2 Node2_4 Node4_6 Node6_8 Non-Leaf Node // / \ / \ / \ / \ - // Node0_1 Node1_2 Node2_3 Node_3_4 Node4_5 Node5_6 Node6_7 Node7_8 Leaf Hash + // Node0_1 Node1_2 Node2_3 Node3_4 Node4_5 Node5_6 Node6_7 Node7_8 Leaf Hash // 1 2 3 4 6 8 8 8 Leaf namespace // 0 1 2 3 4 5 6 7 Leaf index