add tests for prover
This commit is contained in:
parent
d87dfed307
commit
b0a963755c
|
@ -1,5 +1,6 @@
|
||||||
import std/sequtils
|
import std/sequtils
|
||||||
import std/sugar
|
import std/sugar
|
||||||
|
import std/math
|
||||||
|
|
||||||
import ../../asynctest
|
import ../../asynctest
|
||||||
|
|
||||||
|
@ -14,30 +15,33 @@ import pkg/codex/chunker
|
||||||
import pkg/codex/blocktype as bt
|
import pkg/codex/blocktype as bt
|
||||||
import pkg/codex/slots
|
import pkg/codex/slots
|
||||||
import pkg/codex/stores
|
import pkg/codex/stores
|
||||||
|
import pkg/poseidon2/io
|
||||||
|
import pkg/codex/utils/poseidon2digest
|
||||||
|
|
||||||
|
import pkg/constantine/math/arithmetic
|
||||||
|
import pkg/constantine/math/io/io_bigints
|
||||||
|
import pkg/constantine/math/io/io_fields
|
||||||
|
|
||||||
import ./helpers
|
import ./helpers
|
||||||
import ../helpers
|
import ../helpers
|
||||||
import ./backends/helpers
|
import ./backends/helpers
|
||||||
|
|
||||||
|
const
|
||||||
|
slotId = 1
|
||||||
|
samples = 5
|
||||||
|
blockSize = DefaultBlockSize
|
||||||
|
cellSize = DefaultCellSize
|
||||||
|
ecK = 2
|
||||||
|
ecM = 2
|
||||||
|
numDatasetBlocks = 8
|
||||||
|
|
||||||
suite "Test Prover":
|
suite "Test Prover":
|
||||||
let
|
|
||||||
blockSize = NBytes 1024
|
|
||||||
cellSize = NBytes 64
|
|
||||||
ecK = 3
|
|
||||||
ecM = 2
|
|
||||||
|
|
||||||
numSlots = ecK + ecM
|
|
||||||
numDatasetBlocks = 100
|
|
||||||
numTotalBlocks = calcEcBlocksCount(numDatasetBlocks, ecK, ecM) # total number of blocks in the dataset after
|
|
||||||
# EC (should will match number of slots)
|
|
||||||
originalDatasetSize = numDatasetBlocks * blockSize.int
|
|
||||||
totalDatasetSize = numTotalBlocks * blockSize.int
|
|
||||||
|
|
||||||
var
|
var
|
||||||
datasetBlocks: seq[bt.Block]
|
datasetBlocks: seq[bt.Block]
|
||||||
store: BlockStore
|
store: BlockStore
|
||||||
chunker: Chunker
|
manifest: Manifest
|
||||||
verifiableManifest: Manifest
|
protected: Manifest
|
||||||
|
verifiable: Manifest
|
||||||
sampler: Poseidon2Sampler
|
sampler: Poseidon2Sampler
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
|
@ -46,24 +50,14 @@ suite "Test Prover":
|
||||||
metaDs = SQLiteDatastore.new(Memory).tryGet()
|
metaDs = SQLiteDatastore.new(Memory).tryGet()
|
||||||
|
|
||||||
store = RepoStore.new(repoDs, metaDs)
|
store = RepoStore.new(repoDs, metaDs)
|
||||||
chunker = RandomChunker.new(Rng.instance(), size = totalDatasetSize, chunkSize = blockSize)
|
|
||||||
datasetBlocks = await chunker.createBlocks(store)
|
|
||||||
|
|
||||||
let
|
(manifest, protected, verifiable) =
|
||||||
(manifest, protectedManifest) =
|
await createVerifiableManifest(
|
||||||
await createProtectedManifest(
|
store,
|
||||||
datasetBlocks,
|
numDatasetBlocks,
|
||||||
store,
|
ecK, ecM,
|
||||||
numDatasetBlocks,
|
blockSize,
|
||||||
ecK, ecM,
|
cellSize)
|
||||||
blockSize,
|
|
||||||
originalDatasetSize,
|
|
||||||
totalDatasetSize)
|
|
||||||
|
|
||||||
builder = Poseidon2Builder.new(store, protectedManifest, cellSize = cellSize).tryGet
|
|
||||||
|
|
||||||
# build the slots
|
|
||||||
verifiableManifest = (await builder.buildManifest()).tryGet
|
|
||||||
|
|
||||||
test "Should sample and prove a slot":
|
test "Should sample and prove a slot":
|
||||||
let
|
let
|
||||||
|
@ -72,17 +66,13 @@ suite "Test Prover":
|
||||||
|
|
||||||
circomBackend = CircomCompat.init(r1cs, wasm)
|
circomBackend = CircomCompat.init(r1cs, wasm)
|
||||||
prover = Prover.new(store, circomBackend)
|
prover = Prover.new(store, circomBackend)
|
||||||
challenge = 12345.toF.toBytes.toArray32
|
challenge = 1234567.toF.toBytes.toArray32
|
||||||
proof = (await prover.prove(1, verifiableManifest, 5, challenge)).tryGet
|
proof = (await prover.prove(1, verifiable, challenge, 5)).tryGet
|
||||||
key = circomBackend.getVerifyingKey().tryGet
|
key = circomBackend.getVerifyingKey().tryGet
|
||||||
builder = Poseidon2Builder.new(store, verifiableManifest).tryGet
|
builder = Poseidon2Builder.new(store, verifiable).tryGet
|
||||||
sampler = Poseidon2Sampler.new(1, store, builder).tryGet
|
sampler = Poseidon2Sampler.new(1, store, builder).tryGet
|
||||||
proofInput = (await sampler.getProofInput(challenge, 5)).tryGet
|
proofInput = (await sampler.getProofInput(challenge, 5)).tryGet
|
||||||
inputs = toCircomInputs(PublicInputs(
|
inputs = proofInput.toPublicInputs.toCircomInputs
|
||||||
slotIndex: proofInput.slotIndex.toF,
|
|
||||||
datasetRoot: proofInput.verifyRoot,
|
|
||||||
entropy: proofInput.entropy
|
|
||||||
))
|
|
||||||
|
|
||||||
check:
|
check:
|
||||||
(await prover.verify(proof, inputs, key[])).tryGet
|
(await prover.verify(proof, inputs, key[])).tryGet == true
|
||||||
|
|
Loading…
Reference in New Issue