Skip to content

Commit

Permalink
Updated constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk committed Jun 14, 2024
1 parent f805bd9 commit 9f16b5e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package smt
import "encoding/binary"

const (
nonSumRootSizeBytes = 32
// 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)%nonSumRootSizeBytes == 0 {
if len(r)%SmtRootSizeBytes == 0 {
panic("root#sum: not a merkle sum trie")
}

Expand All @@ -24,8 +27,8 @@ func (r MerkleRoot) Sum() uint64 {
// 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)%nonSumRootSizeBytes == 0 {
panic("root#count: not a merkle sum trie")
if len(r)%SmtRootSizeBytes == 0 {
panic("root#sum: not a merkle sum trie")
}

_, firstCountByteIdx := getFirstMetaByteIdx([]byte(r))
Expand Down

0 comments on commit 9f16b5e

Please sign in to comment.