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
|
2024-09-23 14:37:17 +00:00
|
|
|
import pkg/codex/conf
|
|
|
|
import pkg/confutils/defs
|
2024-02-09 21:40:30 +00:00
|
|
|
import pkg/poseidon2/io
|
|
|
|
import pkg/codex/utils/poseidon2digest
|
|
|
|
|
|
|
|
import ./helpers
|
|
|
|
import ../helpers
|
|
|
|
import ./backends/helpers
|
|
|
|
|
|
|
|
suite "Test Prover":
|
|
|
|
let
|
|
|
|
samples = 5
|
2024-02-19 18:58:39 +00:00
|
|
|
blockSize = DefaultBlockSize
|
|
|
|
cellSize = DefaultCellSize
|
2024-05-30 06:57:10 +00:00
|
|
|
repoTmp = TempLevelDb.new()
|
|
|
|
metaTmp = TempLevelDb.new()
|
2024-07-18 13:25:06 +00:00
|
|
|
challenge = 1234567.toF.toBytes.toArray32
|
2024-02-09 21:40:30 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
store: BlockStore
|
2024-07-18 13:25:06 +00:00
|
|
|
prover: Prover
|
2024-02-09 21:40:30 +00:00
|
|
|
|
|
|
|
setup:
|
|
|
|
let
|
2024-05-30 06:57:10 +00:00
|
|
|
repoDs = repoTmp.newDb()
|
|
|
|
metaDs = metaTmp.newDb()
|
2024-09-23 14:37:17 +00:00
|
|
|
config = CodexConf(
|
|
|
|
cmd: StartUpCmd.persistence,
|
|
|
|
nat: ValidIpAddress.init("127.0.0.1"),
|
|
|
|
discoveryIp: ValidIpAddress.init(IPv4_any()),
|
|
|
|
metricsAddress: ValidIpAddress.init("127.0.0.1"),
|
|
|
|
persistenceCmd: PersistenceCmd.prover,
|
|
|
|
circomR1cs: InputFile("tests/circuits/fixtures/proof_main.r1cs"),
|
|
|
|
circomWasm: InputFile("tests/circuits/fixtures/proof_main.wasm"),
|
|
|
|
circomZkey: InputFile("tests/circuits/fixtures/proof_main.zkey"),
|
|
|
|
numProofSamples: samples
|
|
|
|
)
|
|
|
|
backend = config.initializeBackend().tryGet()
|
2024-02-09 21:40:30 +00:00
|
|
|
|
|
|
|
store = RepoStore.new(repoDs, metaDs)
|
2024-09-23 14:37:17 +00:00
|
|
|
prover = Prover.new(store, backend, config.numProofSamples)
|
2024-02-09 21:40:30 +00:00
|
|
|
|
2024-07-18 13:25:06 +00:00
|
|
|
teardown:
|
|
|
|
await repoTmp.destroyDb()
|
|
|
|
await metaTmp.destroyDb()
|
|
|
|
|
|
|
|
test "Should sample and prove a slot":
|
|
|
|
let
|
|
|
|
(_, _, verifiable) =
|
2024-02-09 21:40:30 +00:00
|
|
|
await createVerifiableManifest(
|
|
|
|
store,
|
2024-07-18 13:25:06 +00:00
|
|
|
8, # number of blocks in the original dataset (before EC)
|
|
|
|
5, # ecK
|
|
|
|
3, # ecM
|
2024-02-09 21:40:30 +00:00
|
|
|
blockSize,
|
|
|
|
cellSize)
|
|
|
|
|
2024-07-18 13:25:06 +00:00
|
|
|
let
|
|
|
|
(inputs, proof) = (
|
|
|
|
await prover.prove(1, verifiable, challenge)).tryGet
|
2024-05-30 06:57:10 +00:00
|
|
|
|
2024-07-18 13:25:06 +00:00
|
|
|
check:
|
|
|
|
(await prover.verify(proof, inputs)).tryGet == true
|
|
|
|
|
|
|
|
test "Should generate valid proofs when slots consist of single blocks":
|
|
|
|
|
|
|
|
# To get single-block slots, we just need to set the number of blocks in
|
|
|
|
# the original dataset to be the same as ecK. The total number of blocks
|
|
|
|
# after generating random data for parity will be ecK + ecM, which will
|
|
|
|
# match the number of slots.
|
2024-02-09 21:40:30 +00:00
|
|
|
let
|
2024-07-18 13:25:06 +00:00
|
|
|
(_, _, verifiable) =
|
|
|
|
await createVerifiableManifest(
|
|
|
|
store,
|
|
|
|
2, # number of blocks in the original dataset (before EC)
|
|
|
|
2, # ecK
|
|
|
|
1, # ecM
|
|
|
|
blockSize,
|
|
|
|
cellSize)
|
2024-02-09 21:40:30 +00:00
|
|
|
|
2024-07-18 13:25:06 +00:00
|
|
|
let
|
|
|
|
(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
|