2024-02-09 21:40:30 +00:00
|
|
|
import std/sequtils
|
|
|
|
import std/sugar
|
|
|
|
import std/math
|
|
|
|
|
|
|
|
import ../../asynctest
|
|
|
|
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/libp2p/cid
|
|
|
|
import pkg/datastore
|
|
|
|
|
|
|
|
import pkg/codex/merkletree
|
|
|
|
import pkg/codex/rng
|
|
|
|
import pkg/codex/manifest
|
|
|
|
import pkg/codex/chunker
|
|
|
|
import pkg/codex/blocktype as bt
|
|
|
|
import pkg/codex/slots
|
|
|
|
import pkg/codex/stores
|
|
|
|
import pkg/poseidon2/io
|
|
|
|
import pkg/codex/utils/poseidon2digest
|
|
|
|
|
|
|
|
import ./helpers
|
|
|
|
import ../helpers
|
|
|
|
import ./backends/helpers
|
|
|
|
|
|
|
|
suite "Test Prover":
|
|
|
|
let
|
|
|
|
slotId = 1
|
|
|
|
samples = 5
|
|
|
|
ecK = 3
|
|
|
|
ecM = 2
|
|
|
|
numDatasetBlocks = 8
|
2024-02-19 18:58:39 +00:00
|
|
|
blockSize = DefaultBlockSize
|
|
|
|
cellSize = DefaultCellSize
|
2024-02-09 21:40:30 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
datasetBlocks: seq[bt.Block]
|
|
|
|
store: BlockStore
|
|
|
|
manifest: Manifest
|
|
|
|
protected: Manifest
|
|
|
|
verifiable: Manifest
|
|
|
|
sampler: Poseidon2Sampler
|
|
|
|
|
|
|
|
setup:
|
|
|
|
let
|
|
|
|
repoDs = SQLiteDatastore.new(Memory).tryGet()
|
|
|
|
metaDs = SQLiteDatastore.new(Memory).tryGet()
|
|
|
|
|
|
|
|
store = RepoStore.new(repoDs, metaDs)
|
|
|
|
|
|
|
|
(manifest, protected, verifiable) =
|
|
|
|
await createVerifiableManifest(
|
|
|
|
store,
|
|
|
|
numDatasetBlocks,
|
|
|
|
ecK, ecM,
|
|
|
|
blockSize,
|
|
|
|
cellSize)
|
|
|
|
|
|
|
|
test "Should sample and prove a slot":
|
|
|
|
let
|
|
|
|
r1cs = "tests/circuits/fixtures/proof_main.r1cs"
|
|
|
|
wasm = "tests/circuits/fixtures/proof_main.wasm"
|
|
|
|
|
|
|
|
circomBackend = CircomCompat.init(r1cs, wasm)
|
2024-02-19 18:58:39 +00:00
|
|
|
prover = Prover.new(store, circomBackend, samples)
|
2024-02-09 21:40:30 +00:00
|
|
|
challenge = 1234567.toF.toBytes.toArray32
|
2024-02-19 18:58:39 +00:00
|
|
|
(inputs, proof) = (await prover.prove(1, verifiable, challenge)).tryGet
|
2024-02-09 21:40:30 +00:00
|
|
|
|
|
|
|
check:
|
2024-02-19 18:58:39 +00:00
|
|
|
(await prover.verify(proof, inputs)).tryGet == true
|