Implements selecting a cell sample from a block
This commit is contained in:
parent
b031fb9e4a
commit
07ed066b1e
|
@ -18,7 +18,7 @@ const
|
|||
type
|
||||
DSFieldElement* = F
|
||||
DSCellIndex* = uint64
|
||||
DSSample* = array[CellSize, byte]
|
||||
DSSample* = seq[byte]
|
||||
|
||||
|
||||
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
|
||||
|
||||
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]
|
||||
|
|
|
@ -169,16 +169,18 @@ asyncchecksuite "Test proof datasampler":
|
|||
|
||||
test "Can get sample from block":
|
||||
let
|
||||
blockSize = CellSize * 2
|
||||
blockSize = CellSize * 3
|
||||
bytes = newSeqWith(blockSize.int, rand(uint8))
|
||||
blk = bt.Block.new(bytes).tryGet()
|
||||
|
||||
sample0 = getSampleFromBlock(blk, 0, blockSize.uint64)
|
||||
sample1 = getSampleFromBlock(blk, 1, blockSize.uint64)
|
||||
sample2 = getSampleFromBlock(blk, 2, blockSize.uint64)
|
||||
|
||||
check:
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue