celestiaorg / celestiaorg/nmt

NmtHasher.EmptyRoot has unnecessary double append instead of creating slice with double capacity

Open Beginner friendly
#273 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
122
Forks
53
Avg merge
1d 15h
Merged PRs (30d)
5

Description

If we look at https://github.com/celestiaorg/nmt/blob/29e9433bd79eed40462000626ef987c91b0cf523/hasher.go#L157-L159

we notice this code https://github.com/celestiaorg/nmt/blob/29e9433bd79eed40462000626ef987c91b0cf523/hasher.go#L159

but that code could be made clearer, simpler and even faster (if in hot loop) by

```go
emptyNs2X := bytes.Repeat([]byte{0}, int(n.NamespaceLen)*2)
h := n.baseHasher.Sum(nil)
digest := append(emptyNs2X, h...)
```

Contributor guide

Open the contributing guide

Research direction

Read NmtHasher.EmptyRoot in hasher.go around lines 157-159 and compare the current double-append allocation with the proposed slice construction. Verify the change against the existing test suite and confirm that EmptyRoot preserves its current digest while avoiding the unnecessary append.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cryptography, performance
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.