From 70541921c494aded3b20107139b171a8456b68dd Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 16 Jan 2024 09:35:45 +0100 Subject: [PATCH] Fix: ProofInputSample data is cell bytes instead of block bytes --- codex/slots/builder/builder.nim | 7 +++++++ codex/slots/sampler/sampler.nim | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/codex/slots/builder/builder.nim b/codex/slots/builder/builder.nim index 49c283ca..6b979b99 100644 --- a/codex/slots/builder/builder.nim +++ b/codex/slots/builder/builder.nim @@ -127,6 +127,13 @@ func numBlockCells*(self: SlotsBuilder): Natural = (self.manifest.blockSize div self.cellSize).Natural +func cellSize*(self: SlotsBuilder): NBytes = + ## Cell size. + ## + + self.cellSize + + func numSlotCells*(self: SlotsBuilder): Natural = ## Number of cells per slot. ## diff --git a/codex/slots/sampler/sampler.nim b/codex/slots/sampler/sampler.nim index b8be0a18..39771979 100644 --- a/codex/slots/sampler/sampler.nim +++ b/codex/slots/sampler/sampler.nim @@ -69,7 +69,14 @@ proc new*( blockStore: blockStore, builder: builder) -proc getProofs*( +proc getCell*(self: DataSampler, blkBytes: seq[byte], blkCellIdx: uint64): Cell = + let + cellSize = self.builder.cellSize.uint64 + dataStart = (cellSize * blkCellIdx) + dataEnd = dataStart + cellSize + return blkBytes[dataStart ..< dataEnd] + +proc getProofInput*( self: DataSampler, entropy: ProofChallenge, nSamples: Natural): Future[?!ProofInput] {.async.} = @@ -126,7 +133,9 @@ proc getProofs*( error "Failed to get proof from block tree", err = err.msg return failure(err) - Sample(data: bytes, proof: blockProof) + let cellData = self.getCell(bytes, blkCellIdx) + + Sample(data: cellData, proof: blockProof) success ProofInput( entropy: entropy,