From 5dc14b50e9729a0d524a761b83ba705f1e9ffbb4 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Feb 2024 11:37:17 -0600 Subject: [PATCH] fix tests --- codex/slots/sampler/utils.nim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/codex/slots/sampler/utils.nim b/codex/slots/sampler/utils.nim index fa68e408..b14659c0 100644 --- a/codex/slots/sampler/utils.nim +++ b/codex/slots/sampler/utils.nim @@ -84,3 +84,30 @@ func cellIndices*( let idx = cellIndex(entropy, slotRoot, numCells, indices.len + 1) indices.add(idx.Natural) indices + +func checkCellProof*[H, P]( + cellData: seq[byte], + cellProof: P, + blkRoot: H, + slotProof: P, + slotRoot: H): ?!bool = + ## Check the proof for a given cell. + ## + + let + cellLeaf = H.spongeDigest(cellData).valueOr: + return failure("Failed to digest cell data") + + slotLeaf = cellProof.reconstructRoot(cellLeaf).valueOr: + return failure("Failed to reconstruct slot leaf") + + recRoot = slotProof.reconstructRoot(slotLeaf).valueOr: + return failure("Failed to reconstruct slot root") + + if blkRoot != slotLeaf: + return failure("Block root does not match slot leaf") + + if recRoot != slotRoot: + return failure("Reconstructed slot root does not match expected slot root") + + success true