diff --git a/reference/nim/proof_input/src/blocks.nim b/reference/nim/proof_input/src/blocks.nim index 4db714d..7feb872 100644 --- a/reference/nim/proof_input/src/blocks.nim +++ b/reference/nim/proof_input/src/blocks.nim @@ -12,45 +12,47 @@ import merkle #------------------------------------------------------------------------------- -func hashCellOpen( cellData: openArray[byte] ): Hash = - assert( cellData.len == cellSize , "cells are expected to be exactly 2048 bytes" ) +func hashCellOpen( globcfg: GlobalConfig, cellData: openArray[byte] ): Hash = + assert( cellData.len == globcfg.cellSize , ("cells are expected to be exactly " & $globcfg.cellSize & " bytes") ) return Sponge.digest( cellData, rate=2 ) -func hashCell*(cellData: Cell): Hash = hashCellOpen(cellData) +func hashCell*( globcfg: GlobalConfig, cellData: Cell): Hash = hashCellOpen(globcfg, cellData) #------------------------------------------------------------------------------- -func splitBlockIntoCells( blockData: openArray[byte] ): seq[Cell] = - assert( blockData.len == blockSize , "network blocks are expected to be exactly 65536 bytes" ) +func splitBlockIntoCells( globcfg: GlobalConfig, blockData: openArray[byte] ): seq[Cell] = + assert( blockData.len == globcfg.blockSize , ("network blocks are expected to be exactly" & $globcfg.blockSize & " bytes" ) ) - var cells : seq[seq[byte]] = newSeq[seq[byte]]( cellsPerBlock ) + var cells : seq[seq[byte]] = newSeq[seq[byte]]( cellsPerBlock(globcfg) ) let start = low(blockData) - var leaves : seq[Hash] = newSeq[Hash]( cellsPerBlock ) - for i in 0.. 0): @@ -13,10 +15,15 @@ func floorLog2* (x : int) : int = y = y shr 1 return k -func ceilingLog2* (x : int) : int = +func ceilingLog2* (x: int): int = if (x==0): return -1 else: return (floorLog2(x-1) + 1) +func exactLog2( x: int): int = + let k = ceilingLog2(x) + assert( x == 2^k, "exactLog2: not a power of two" ) + return k + #------------------------------------------------------------------------------- diff --git a/reference/nim/proof_input/src/slot.nim b/reference/nim/proof_input/src/slot.nim index 94f8067..a16015f 100644 --- a/reference/nim/proof_input/src/slot.nim +++ b/reference/nim/proof_input/src/slot.nim @@ -22,12 +22,12 @@ const exSlotCfg = # (10852671575406741732, 3735945064, 2557891771) {.overflowChecks: off.} -proc genFakeCell(cfg: SlotConfig, seed: Seed, idx: CellIdx): Cell = +proc genFakeCell(globcfg: GlobalConfig, cfg: SlotConfig, seed: Seed, idx: CellIdx): Cell = let seed1 : uint64 = uint64(seed) + 0xdeadcafe'u64 let seed2 : uint64 = uint64(idx) + 0x98765432'u64 - var cell : seq[byte] = newSeq[byte](cellSize) + var cell : seq[byte] = newSeq[byte](globcfg.cellSize) var state : uint64 = 1 - for i in 0..