testmain.nim
1 2 import sugar 3 #import std/sequtils 4 5 #import constantine/math/arithmetic 6 7 import poseidon2/types 8 import poseidon2/merkle 9 import poseidon2/io 10 11 import types 12 import merkle 13 import gen_input 14 import json 15 #import blocks 16 #import slot 17 #import dataset 18 #import sample 19 20 #------------------------------------------------------------------------------- 21 22 proc testMerkleProofs*( input: seq[F] ) = 23 let tree = merkleTree(input) 24 let root = Merkle.digest(input) 25 assert( bool(root == treeRoot(tree)) ) 26 27 let n = input.len 28 var ok = true 29 var oks : seq[bool] = newSeq[bool]( n ) 30 for i in 0..<n: 31 let proof = merkleProof(tree, i) 32 let b = checkMerkleProof(root, proof) 33 oks[i] = b 34 ok = ok and b 35 let prefix = ("testing Merkle proofs for an input of size " & $n & " ... ") 36 if ok: 37 echo (prefix & "OK.") 38 else: 39 echo (prefix & "FAILED!") 40 echo oks 41 42 proc testAllMerkleProofs*( N: int ) = 43 for k in 1..N: 44 let input = collect( newSeq , (for i in 1..k: toF(100+i) )) 45 testMerkleProofs( input ) 46 47 #------------------------------------------------------------------------------- 48 49 when isMainModule: 50 # testAllMerkleProofs(20) 51 52 let slotIdx = 3 53 let fakedata = DataSource(kind: FakeData, seed: 12345) 54 let globcfg = GlobalConfig( maxDepth: 16, maxLog2NSlots: 5, cellSize: 128, blockSize: 4096) 55 let dsetcfg = DataSetConfig( nCells: 256, nSlots: 5, nSamples: 10, dataSrc: fakedata) 56 let entropy = toF( 1234567 ) 57 let prfInput = generateProofInput(globcfg, dsetcfg, slotIdx, entropy) 58 exportProofInput( "json/foo.json" , prfInput ) 59