You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An empty root represents the root of a tree with no leaves. It is obtained using the EmptyRoot() method of the Hasher type. However, the root generated by this method may not be consistent, even when the hasher is configured identically.
Below, this inconsistency is shown by an example:
nIDSzie:=1ignoreMaxNS:=truenIDList:= []byte{1, 2, 3, 4}
// Create an nmt using the above configstree:=New(sha256.New(), NamespaceIDSize(nIDSzie), IgnoreMaxNamespace(ignoreMaxNS))
fori, nid:=rangenIDList {
namespace:=bytes.Repeat([]byte{nid}, nIDSzie)
d:=append(namespace, []byte(fmt.Sprintf("leaf_%d", i))...)
iferr:=tree.Push(d); err!=nil {
panic(fmt.Sprintf("unexpected error: %v", err))
}
}
// Calculate the empty root by accessing the `Hasher` field of the treeexpectedEmptyRoot:=tree.treeHasher.EmptyRoot()
// Create a hasher identical to the one used for the treehasher:=NewNmtHasher(sha256.New(), namespace.IDSize(nIDSzie), ignoreMaxNS)
gotEmptyRoot:=hasher.EmptyRoot()
assert.True(t, bytes.Equal(gotEmptyRoot, expectedEmptyRoot)) // it panics, they are not equal
The text was updated successfully, but these errors were encountered:
…the EmptyRoot (#197)
## Overview
Closes#196
## 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
Problem
An empty root represents the root of a tree with no leaves. It is obtained using the EmptyRoot() method of the Hasher type. However, the root generated by this method may not be consistent, even when the hasher is configured identically.
Below, this inconsistency is shown by an example:
The text was updated successfully, but these errors were encountered: