-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Misc] Integration fixes after the v0.11.0 release (#49)
- Exposing `NewTrieSpec` publically - Adding back `Sum` function to the `MerkleRoot` type - Adding a new `Count` function to the `MerkleRoot` type - Adding back `PathHasherSize` --- Signed-off-by: Daniel Olshansky <olshansky.daniel@gmail.com> Co-authored-by: Redouane Lakrache <r3d0ne@gmail.com>
- Loading branch information
Showing
4 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package smt | ||
|
||
import "encoding/binary" | ||
|
||
const ( | ||
// These are intentionally exposed to allow for for testing and custom | ||
// implementations of downstream applications. | ||
SmtRootSizeBytes = 32 | ||
SmstRootSizeBytes = SmtRootSizeBytes + sumSizeBytes + countSizeBytes | ||
) | ||
|
||
// Sum returns the uint64 sum of the merkle root, it checks the length of the | ||
// merkle root and if it is no the same as the size of the SMST's expected | ||
// root hash it will panic. | ||
func (r MerkleRoot) Sum() uint64 { | ||
if len(r)%SmtRootSizeBytes == 0 { | ||
panic("root#sum: not a merkle sum trie") | ||
} | ||
|
||
firstSumByteIdx, firstCountByteIdx := getFirstMetaByteIdx([]byte(r)) | ||
|
||
var sumBz [sumSizeBytes]byte | ||
copy(sumBz[:], []byte(r)[firstSumByteIdx:firstCountByteIdx]) | ||
return binary.BigEndian.Uint64(sumBz[:]) | ||
} | ||
|
||
// Count returns the uint64 count of the merkle root, a cryptographically secure | ||
// count of the number of non-empty leafs in the tree. | ||
func (r MerkleRoot) Count() uint64 { | ||
if len(r)%SmtRootSizeBytes == 0 { | ||
panic("root#sum: not a merkle sum trie") | ||
} | ||
|
||
_, firstCountByteIdx := getFirstMetaByteIdx([]byte(r)) | ||
|
||
var countBz [countSizeBytes]byte | ||
copy(countBz[:], []byte(r)[firstCountByteIdx:]) | ||
return binary.BigEndian.Uint64(countBz[:]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters