celestiaorg / nmt

Namespaced Merkle Tree
Apache License 2.0
112 stars 39 forks source link

feat!: add an additional constraint of empty leafHash field to the empty proof definition #192

Closed staheri14 closed 1 year ago

staheri14 commented 1 year ago

Overview

Closes #181 The updates made by this PR will result in a breaking change, as empty proofs with a non-empty leafHash field will no longer be considered valid. This means that their verification through VerifyNamespace will fail. Example:

nIDSize := 1
tree := exampleNMT(nIDSize, 1, 2, 3, 4)
root, err := tree.Root()
require.NoError(t, err)
hasher := 
proof := Proof{
        start:    0,
        end:      0,
        nodes:    nil,
        leafHash: tree.leafHashes[0],
    }

res := proof.VerifyNamespace(tree.treeHasher.baseHasher, []byte{0}, [][]byte{}, root)
require.True(res) // this is false with the changes in this PR, however, previously, it was true

Checklist

codecov[bot] commented 1 year ago

Codecov Report

Merging #192 (aeee501) into master (4b97a09) will not change coverage. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #192   +/-   ##
=======================================
  Coverage   95.71%   95.71%           
=======================================
  Files           5        5           
  Lines         560      560           
=======================================
  Hits          536      536           
  Misses         14       14           
  Partials       10       10           
Impacted Files Coverage Δ
proof.go 93.70% <100.00%> (ø)