diff --git a/reference/haskell/cli/testMain.hs b/reference/haskell/cli/testMain.hs index 86ee6e6..0006830 100644 --- a/reference/haskell/cli/testMain.hs +++ b/reference/haskell/cli/testMain.hs @@ -15,8 +15,8 @@ smallDataSetCfg = MkDataSetCfg , _maxLog2NSlots = 5 , _nSlots = 5 , _cellSize = 128 - , _blockSize = 1024 - , _nCells = 64 + , _blockSize = 4096 -- 1024 + , _nCells = 256 -- 64 , _nSamples = 10 , _dataSrc = FakeData (Seed 12345) } diff --git a/reference/nim/proof_input/src/dataset.nim b/reference/nim/proof_input/src/dataset.nim index a0f4fd7..55c5e2e 100644 --- a/reference/nim/proof_input/src/dataset.nim +++ b/reference/nim/proof_input/src/dataset.nim @@ -19,6 +19,11 @@ const exDataSetCfg* = , dataSrc: DataSource(kind: FakeData, seed: 12345) ) +const exGlobalCfg* = + GlobalConfig( maxDepth: 16 + , maxLog2NSlots: 5 + ) + #------------------------------------------------------------------------------- {.overflowChecks: off.} diff --git a/reference/nim/proof_input/src/gen_input.nim b/reference/nim/proof_input/src/gen_input.nim index cb45d00..5012efc 100644 --- a/reference/nim/proof_input/src/gen_input.nim +++ b/reference/nim/proof_input/src/gen_input.nim @@ -29,7 +29,7 @@ proc buildSlotTreeFull( slotCfg: SlotConfig ): (seq[MerkleTree], MerkleTree) = proc buildSlotTree( slotCfg: SlotConfig ): MerkleTree = return buildSlotTreeFull(slotCfg)[1] -proc generateProofInput*( dsetCfg: DataSetConfig, slotIdx: SlotIdx, entropy: Entropy ): SlotProofInput = +proc generateProofInput*( globCfg: GlobalConfig, dsetCfg: DataSetConfig, slotIdx: SlotIdx, entropy: Entropy ): SlotProofInput = let nslots = dsetCfg.nSlots let ncells = dsetCfg.nCells let nblocks = ncells div cellsPerBlock @@ -57,7 +57,7 @@ proc generateProofInput*( dsetCfg: DataSetConfig, slotIdx: SlotIdx, entropy: Ent let cellData = slotLoadCellData( ourSlotCfg, cellIdx ) let botProof = merkleProof( blockTree , cellIdx mod cellsPerBlock ) let topProof = merkleProof( bigTree , blockIdx ) - let prf = mergeMerkleProofs( botProof, topProof ) + let prf = padMerkleProof( mergeMerkleProofs( botProof, topProof ), globCfg.maxDepth ) inputs.add( CellProofInput(cellData: cellData, merkleProof: prf) ) return SlotProofInput( dataSetRoot: dsetRoot @@ -66,7 +66,7 @@ proc generateProofInput*( dsetCfg: DataSetConfig, slotIdx: SlotIdx, entropy: Ent , nSlots: nslots , slotIndex: slotIdx , slotRoot: ourSlotRoot - , slotProof: slotProof + , slotProof: padMerkleProof( slotProof, globCfg.maxLog2NSlots ) , proofInputs: inputs ) diff --git a/reference/nim/proof_input/src/slot.nim b/reference/nim/proof_input/src/slot.nim index 26e3388..94f8067 100644 --- a/reference/nim/proof_input/src/slot.nim +++ b/reference/nim/proof_input/src/slot.nim @@ -44,7 +44,7 @@ genFakeCell cfg (Seed seed) (CellIdx idx) = (mkCellData cfg $ B.pack list) where go cnt state = fromIntegral state'' : go (cnt-1) state'' where state' = state*(state + seed1)*(state + seed2) + state*(state `xor` 0x5a5a5a5a) + seed1*state + (seed2 + 17) state'' = mod state' 1698428844001831 -#] +]# #------------------------------------------------------------------------------- diff --git a/reference/nim/proof_input/src/testmain.nim b/reference/nim/proof_input/src/testmain.nim index 1b34c75..9bdfe6b 100644 --- a/reference/nim/proof_input/src/testmain.nim +++ b/reference/nim/proof_input/src/testmain.nim @@ -50,8 +50,9 @@ when isMainModule: let slotIdx = 3 let fakedata = DataSource(kind: FakeData, seed: 12345) - let dsetcfg = DataSetConfig( nCells: 256, nSlots: 5, nSamples: 5, dataSrc: fakedata) + let globcfg = GlobalConfig( maxDepth: 16, maxLog2NSlots: 5) + let dsetcfg = DataSetConfig( nCells: 256, nSlots: 5, nSamples: 10, dataSrc: fakedata) let entropy = toF( 1234567 ) - let prfInput = generateProofInput(dsetcfg, slotIdx, entropy) + let prfInput = generateProofInput(globcfg, dsetcfg, slotIdx, entropy) exportProofInput( "json/foo.json" , prfInput ) diff --git a/reference/nim/proof_input/src/types.nim b/reference/nim/proof_input/src/types.nim index c35ecb3..26ab33e 100644 --- a/reference/nim/proof_input/src/types.nim +++ b/reference/nim/proof_input/src/types.nim @@ -1,5 +1,6 @@ import std/strutils +import std/sequtils from constantine/math/io/io_fields import toDecimal @@ -48,6 +49,18 @@ type #------------------------------------------------------------------------------- +# the circuit expect merkle path of statically known length, so we need to pad them +func padMerkleProof*( old: MerkleProof, newlen: int ): MerkleProof = + let pad = newlen - old.merklePath.len + assert( pad >= 0 ) + return MerkleProof( leafIndex: old.leafIndex + , leafValue: old.leafValue + , merklePath: old.merklePath & repeat(zero,pad) + , numberOfLeaves: old.numberOfLeaves + ) + +#------------------------------------------------------------------------------- + type Seed* = uint64 @@ -94,4 +107,8 @@ type nSamples* : int # how many cells we sample dataSrc* : DataSource # slot data source + GlobalConfig* = object + maxDepth* : int # maximum depth of the big merkle tree (log2 of maximum numbers of cells per slot) + maxLog2NSlots* : int # log2 of maximum number of slots per dataset + #-------------------------------------------------------------------------------