move tests to subdirectory

This commit is contained in:
Dmitriy Ryajov 2024-01-29 15:00:51 -06:00
parent 4748e2a4af
commit 3ec6fe21b3
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 0 additions and 172 deletions

View File

@ -1,115 +0,0 @@
import std/json
import std/sequtils
import pkg/poseidon2
import pkg/constantine/math/arithmetic
import pkg/constantine/math/io/io_bigints
import pkg/codex/merkletree
import pkg/codex/slots/types
type
Input* = object
cellData*: seq[seq[byte]]
merklePaths*: seq[seq[Poseidon2Hash]]
slotProof*: seq[Poseidon2Hash]
datasetRoot*: Poseidon2Hash
slotRoot*: Poseidon2Hash
entropy*: Poseidon2Hash
nCellsPerSlot*: int
nSlotsPerDataSet*: int
slotIndex*: int
proc toInput*(inputJson: JsonNode): Input =
let
cellData =
inputJson["cellData"].mapIt(
it.mapIt(
block:
var
big: BigInt[256]
data = newSeq[byte](BigInt[256].bits div 8)
assert bool(big.fromDecimal( it.str ))
data.marshal(big, littleEndian)
data
).concat # flatten out elements
)
merklePaths =
inputJson["merklePaths"].mapIt(
it.mapIt(
block:
var
big: BigInt[254]
hash: Poseidon2Hash
assert bool(big.fromDecimal( it.str ))
hash.fromBig( big )
hash
)
)
slotProof = inputJson["slotProof"].mapIt(
block:
var
big: BigInt[254]
hash: Poseidon2Hash
assert bool(big.fromDecimal( it.str ))
hash.fromBig( big )
hash
)
datasetRoot = block:
var
big: BigInt[254]
hash: Poseidon2Hash
assert bool(big.fromDecimal( inputJson["dataSetRoot"].str ))
hash.fromBig( big )
hash
slotRoot = block:
var
big: BigInt[254]
hash: Poseidon2Hash
assert bool(big.fromDecimal( inputJson["slotRoot"].str ))
hash.fromBig( big )
hash
entropy = block:
var
big: BigInt[254]
hash: Poseidon2Hash
assert bool(big.fromDecimal( inputJson["entropy"].str ))
hash.fromBig( big )
hash
nCellsPerSlot = inputJson["nCellsPerSlot"].getInt
nSlotsPerDataSet = inputJson["nSlotsPerDataSet"].getInt
slotIndex = inputJson["slotIndex"].getInt
Input(
cellData: cellData,
merklePaths: merklePaths,
slotProof: slotProof,
datasetRoot: datasetRoot,
slotRoot: slotRoot,
entropy: entropy,
nCellsPerSlot: nCellsPerSlot,
nSlotsPerDataSet: nSlotsPerDataSet,
slotIndex: slotIndex)
proc toProofInput*[H](input: Input): ProofInput[H] =
ProofInput[H](
entropy: input.entropy,
slotIndex: input.slotIndex,
verifyRoot: input.datasetRoot,
verifyProof: input.slotProof,
slotRoot: input.slotRoot,
numCells: input.nCellsPerSlot,
numSlots: input.nSlotsPerDataSet,
samples: zip(input.cellData, input.merklePaths)
.mapIt(Sample[H](
data: it[0],
merkleProof: it[1]
))
)

View File

@ -1,57 +0,0 @@
import std/json
import std/sequtils
import std/sugar
import std/options
import pkg/chronos
import pkg/unittest2
import pkg/poseidon2
import pkg/codex/slots
import pkg/codex/slots/types
import pkg/codex/merkletree
import pkg/constantine/math/arithmetic
import pkg/constantine/math/io/io_fields
import pkg/constantine/math/io/io_bigints
import ./helpers
suite "Test Backend":
let
r1cs = "tests/codex/slots/prover/fixtures/proof_main.r1cs"
wasm = "tests/codex/slots/prover/fixtures/proof_main.wasm"
var
circom: CircomCompat
proofInput: ProofInput[Poseidon2Hash]
setup:
let
inputData = readFile("tests/codex/slots/prover/fixtures/input.json")
inputJson = parseJson(inputData)
proofInput = toProofInput[Poseidon2Hash](inputJson.toInput())
# circom = CircomCompat.init(r1cs, wasm, zkey)
circom = CircomCompat.init(r1cs, wasm)
teardown:
circom.release()
test "Should verify with known input":
let
proof = circom.prove(proofInput).tryGet
check circom.verify(proof).tryGet
proof.release()
test "Should not verify with wrong input":
proofInput.slotIndex = 1 # change slot index
let
proof = circom.prove(proofInput).tryGet
check circom.verify(proof).tryGet == false
proof.release()