nim-dagger/benchmarks/ark_prover_bench.nim

56 lines
1.6 KiB
Nim
Raw Normal View History

2024-04-23 17:21:39 +00:00
import std/sequtils
import std/options
import std/importutils
import pkg/questionable
import pkg/questionable/results
import pkg/datastore
import pkg/codex/rng
import pkg/codex/stores
import pkg/codex/merkletree
import pkg/codex/utils/json
import pkg/codex/codextypes
import pkg/codex/slots
import pkg/codex/slots/builder
import pkg/codex/utils/poseidon2digest
import pkg/codex/slots/sampler/utils
import pkg/constantine/math/arithmetic
import pkg/constantine/math/io/io_bigints
import pkg/constantine/math/io/io_fields
import codex/slots/backends/helpers
proc setup() =
2024-04-23 17:26:16 +00:00
let
inputData = readFile("tests/circuits/fixtures/input.json")
inputJson: JsonNode = !JsonNode.parse(inputData)
proofInput: ProofInputs[Poseidon2Hash] =
Poseidon2Hash.jsonToProofInput(inputJson)
2024-04-23 17:21:39 +00:00
let
blockCells = 32
cellIdxs = proofInput.entropy.cellIndices(proofInput.slotRoot, proofInput.nCellsPerSlot, 5)
for i, cellIdx in cellIdxs:
let
sample = proofInput.samples[i]
cellIdx = cellIdxs[i]
cellProof = Poseidon2Proof.init(
cellIdx.toCellInBlk(blockCells),
proofInput.nCellsPerSlot,
sample.merklePaths[0..<5]).tryGet
slotProof = Poseidon2Proof.init(
cellIdx.toBlkInSlot(blockCells),
proofInput.nCellsPerSlot,
sample.merklePaths[5..<9]).tryGet
cellData = Poseidon2Hash.fromCircomData(sample.cellData)
cellLeaf = Poseidon2Hash.spongeDigest(cellData, rate = 2).tryGet
slotLeaf = cellProof.reconstructRoot(cellLeaf).tryGet
# check slotProof.verify(slotLeaf, proofInput.slotRoot).tryGet