Implements selecting a cell sample from a block

This commit is contained in:
benbierens 2023-11-22 16:28:05 +01:00 committed by Dmitriy Ryajov
parent b031fb9e4a
commit 07ed066b1e
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 11 additions and 4 deletions

View File

@ -18,7 +18,7 @@ const
type type
DSFieldElement* = F DSFieldElement* = F
DSCellIndex* = uint64 DSCellIndex* = uint64
DSSample* = array[CellSize, byte] DSSample* = seq[byte]
func extractLowBits*[n: static int](A: BigInt[n], k: int): uint64 = func extractLowBits*[n: static int](A: BigInt[n], k: int): uint64 =
@ -74,4 +74,9 @@ proc getCellIndexInBlock*(cellIndex: DSCellIndex, blockSize: uint64): uint64 =
return cellIndex mod numberOfCellsPerBlock return cellIndex mod numberOfCellsPerBlock
proc getSampleFromBlock*(blk: bt.Block, cellIndex: DSCellIndex, blockSize: uint64): DSSample = proc getSampleFromBlock*(blk: bt.Block, cellIndex: DSCellIndex, blockSize: uint64): DSSample =
raiseAssert("a") let
inBlockCellIndex = getCellIndexInBlock(cellIndex, blockSize)
dataStart = (CellSize * inBlockCellIndex)
dataEnd = dataStart + CellSize
return blk.data[dataStart ..< dataEnd]

View File

@ -169,16 +169,18 @@ asyncchecksuite "Test proof datasampler":
test "Can get sample from block": test "Can get sample from block":
let let
blockSize = CellSize * 2 blockSize = CellSize * 3
bytes = newSeqWith(blockSize.int, rand(uint8)) bytes = newSeqWith(blockSize.int, rand(uint8))
blk = bt.Block.new(bytes).tryGet() blk = bt.Block.new(bytes).tryGet()
sample0 = getSampleFromBlock(blk, 0, blockSize.uint64) sample0 = getSampleFromBlock(blk, 0, blockSize.uint64)
sample1 = getSampleFromBlock(blk, 1, blockSize.uint64) sample1 = getSampleFromBlock(blk, 1, blockSize.uint64)
sample2 = getSampleFromBlock(blk, 2, blockSize.uint64)
check: check:
sample0 == bytes[0..<CellSize] sample0 == bytes[0..<CellSize]
sample1 == bytes[CellSize..^1] sample1 == bytes[CellSize..<(CellSize*2)]
sample2 == bytes[(CellSize*2)..^1]
# proc getSampleFromBlock(blk: bt.Block, cellIndex: DSCellIndex, blockSize: uint64): DSSample # proc getSampleFromBlock(blk: bt.Block, cellIndex: DSCellIndex, blockSize: uint64): DSSample