codex-contracts-eth/test/proof.js

42 lines
894 B
JavaScript
Raw Normal View History

2024-01-10 14:12:18 +00:00
const fs = require("fs")
2024-01-15 15:25:30 +00:00
const ethers = require("ethers")
2024-01-18 08:54:21 +00:00
const { BigNumber } = ethers
2024-01-05 11:27:53 +00:00
2024-01-18 08:54:21 +00:00
const BASE_PATH = __dirname + "/../verifier/networks"
const PROOF_FILE_NAME = "example-proof/proof.json"
const PUBLIC_INPUT_FILE_NAME = "example-proof/public.json"
2024-01-18 08:54:21 +00:00
2024-01-18 12:50:54 +00:00
function G1ToStruct(point) {
return {
x: point[0],
2024-01-22 15:43:11 +00:00
y: point[1],
2024-01-18 12:50:54 +00:00
}
2024-01-18 08:54:21 +00:00
}
2024-01-18 12:50:54 +00:00
function G2ToStruct(point) {
return {
2024-01-22 15:43:11 +00:00
x: [point[0][1], point[0][0]],
y: [point[1][1], point[1][0]],
2024-01-18 12:50:54 +00:00
}
2024-01-18 08:54:21 +00:00
}
2024-01-05 11:27:53 +00:00
2024-01-10 14:12:18 +00:00
function loadProof(name) {
const proof = JSON.parse(
fs.readFileSync(`${BASE_PATH}/${name}/${PROOF_FILE_NAME}`)
)
2024-01-18 12:50:54 +00:00
return {
2024-01-22 15:43:11 +00:00
a: G1ToStruct(proof["pi_a"]),
b: G2ToStruct(proof["pi_b"]),
c: G1ToStruct(proof["pi_c"]),
2024-01-18 12:50:54 +00:00
}
2024-01-05 11:27:53 +00:00
}
function loadPublicInput(name) {
const input = JSON.parse(
fs.readFileSync(`${BASE_PATH}/${name}/${PUBLIC_INPUT_FILE_NAME}`)
)
return input
}
module.exports = { loadProof, loadPublicInput }