Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in the EmptyRoot values #196

Closed
staheri14 opened this issue May 12, 2023 · 0 comments · Fixed by #197
Closed

Inconsistency in the EmptyRoot values #196

staheri14 opened this issue May 12, 2023 · 0 comments · Fixed by #197
Assignees
Labels
bug Something isn't working
Milestone

Comments

@staheri14
Copy link
Contributor

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:

nIDSzie := 1
ignoreMaxNS := true
nIDList := []byte{1, 2, 3, 4}

// Create an nmt using the above configs
tree := New(sha256.New(), NamespaceIDSize(nIDSzie), IgnoreMaxNamespace(ignoreMaxNS))
	for i, nid := range nIDList {
		namespace := bytes.Repeat([]byte{nid}, nIDSzie)
		d := append(namespace, []byte(fmt.Sprintf("leaf_%d", i))...)
		if err := tree.Push(d); err != nil {
			panic(fmt.Sprintf("unexpected error: %v", err))
		}
	}
// Calculate the empty root by accessing the `Hasher` field of the tree
expectedEmptyRoot := tree.treeHasher.EmptyRoot()

// Create  a hasher identical to the one used for the tree
hasher := NewNmtHasher(sha256.New(), namespace.IDSize(nIDSzie), ignoreMaxNS)
gotEmptyRoot := hasher.EmptyRoot()

assert.True(t, bytes.Equal(gotEmptyRoot, expectedEmptyRoot)) // it panics, they are not equal
@staheri14 staheri14 self-assigned this May 12, 2023
@staheri14 staheri14 added the bug Something isn't working label May 12, 2023
@staheri14 staheri14 added this to the Mainnet milestone May 12, 2023
staheri14 added a commit that referenced this issue May 16, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant