logos-storage-contracts-eth/test/Bn254Verifier.test.js
Eric Mastro 32ff556691
WIP: Add test for verifier
Needs valid values to test points that exist on the curve as well as a valid proof. Waiting on https://github.com/status-im/nim-codex/pull/101 to get valid values.

TODO: Convert Bn254.sol contract to a generic witnet EllipticCurve.sol contract and fill in values as needed for the Bn254 curve.
2022-06-08 15:15:05 +10:00

49 lines
1.1 KiB
JavaScript

const { expect } = require("chai")
const { ethers } = require("hardhat")
const {
snapshot,
revert,
ensureMinimumBlockHeight,
advanceTime,
} = require("./evm")
describe("Bn254Verifier", function () {
let bn254
beforeEach(async function () {
await snapshot()
await ensureMinimumBlockHeight(256)
const Bn254Verifier = await ethers.getContractFactory("TestBn254Verifier")
verifier = await Bn254Verifier.deploy()
})
afterEach(async function () {
await revert()
})
it("fails when first point is not on Bn254 curve", async function () {
let proof = {
q: [
{ i: -1, v: 1 },
{ i: -2, v: 2 },
{ i: -3, v: 3 },
],
mus: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
sigma: { X: 1, Y: 2 },
u: [
{ X: 1, Y: 2 },
{ X: 2, Y: 2 },
{ X: 3, Y: 3 },
],
name: ethers.utils.toUtf8Bytes("test"),
publicKey: {
X: [1, 2],
Y: [1, 2],
},
}
await expect(verifier.verifyProof(proof)).to.be.revertedWith(
"must be on Bn254 curve"
)
})
})