chore: refine - 3

This commit is contained in:
darshankabariya 2025-04-24 03:36:11 +05:30
parent 0572d5ec37
commit 9f8a5e45a3
2 changed files with 7 additions and 13 deletions

View File

@ -122,35 +122,29 @@ method onWithdraw*(g: GroupManager, cb: OnWithdrawCallback) {.base, gcsafe.} =
proc slideRootQueue*(
rootQueue: var Deque[MerkleNode], root: MerkleNode
): seq[MerkleNode] =
## updates the root queue with the latest root and pops the oldest one when the capacity of `AcceptableRootWindowSize` is reached
let overflowCount = rootQueue.len - AcceptableRootWindowSize + 1
var overflowedRoots = newSeq[MerkleNode]()
if overflowCount > 0:
# Delete the oldest `overflowCount` roots in the deque (index 0..`overflowCount`)
# insert into overflowedRoots seq and return
for i in 0 ..< overflowCount:
overFlowedRoots.add(rootQueue.popFirst())
# Push the next root into the queue
rootQueue.addLast(root)
return overFlowedRoots
method indexOfRoot*(
g: GroupManager, root: MerkleNode
): int {.base, gcsafe, raises: [].} =
## returns the index of the root in the merkle tree.
## returns -1 if the root is not found
return g.validRoots.find(root)
method validateRoot*(
g: GroupManager, root: MerkleNode
): bool {.base, gcsafe, raises: [].} =
## validates the root against the valid roots queue
# Print all validRoots in one line with square brackets
var rootsStr = "["
var first = true
for r in g.validRoots.items():
if not first:
rootsStr.add(", ")
rootsStr.add($r)
first = false
rootsStr.add("]")
debug "Valid Merkle roots in validateRoot", roots = rootsStr, root_to_validate = root
# Check if the root is in the valid roots queue
if g.indexOfRoot(root) >= 0:
return true
return false

View File

@ -451,7 +451,7 @@ method generateProof*(
method verifyProof*(
g: OnchainGroupManager, # verifier context
input: openArray[byte], # raw message data (signal)
input: seq[byte], # raw message data (signal)
proof: RateLimitProof, # proof received from the peer
): GroupManagerResult[bool] {.gcsafe, raises: [].} =
## -- Verifies an RLN rate-limit proof against the set of valid Merkle roots --