Skip to content

Change functions params order in the Groth16VerifierHelper library #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions contracts/libs/zkp/Groth16VerifierHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ library Groth16VerifierHelper {
* @notice Function to call the `verifyProof` function on the `verifier` contract.
* The ZK proof points are wrapped in a structure for convenience
* @param verifier_ the address of the autogenerated `Verifier` contract
* @param pubSignals_ the array of the ZK proof public signals
* @param proofPoints_ the ProofPoints struct with ZK proof points
* @param pubSignals_ the array of the ZK proof public signals
* @return true if the proof is valid, false - otherwise
*/
function verifyProof(
address verifier_,
uint256[] memory pubSignals_,
ProofPoints memory proofPoints_
ProofPoints memory proofPoints_,
uint256[] memory pubSignals_
) internal view returns (bool) {
return
_verifyProof(
Expand All @@ -53,18 +53,18 @@ library Groth16VerifierHelper {
/**
* @notice Function to call the `verifyProof` function on the `verifier` contract
* @param verifier_ the address of the autogenerated `Verifier` contract
* @param pubSignals_ the array of the ZK proof public signals
* @param a_ the A point of the ZK proof
* @param b_ the B point of the ZK proof
* @param c_ the C point of the ZK proof
* @param pubSignals_ the array of the ZK proof public signals
* @return true if the proof is valid, false - otherwise
*/
function verifyProof(
address verifier_,
uint256[] memory pubSignals_,
uint256[2] memory a_,
uint256[2][2] memory b_,
uint256[2] memory c_
uint256[2] memory c_,
uint256[] memory pubSignals_
) internal view returns (bool) {
return _verifyProof(verifier_, a_, b_, c_, pubSignals_, pubSignals_.length);
}
Expand All @@ -74,15 +74,15 @@ library Groth16VerifierHelper {
* The ZK proof points are wrapped in a structure for convenience
* The length of the `pubSignals_` arr must be strictly equal to `pubSignalsCount_`
* @param verifier_ the address of the autogenerated `Verifier` contract
* @param pubSignals_ the array of the ZK proof public signals
* @param proofPoints_ the ProofPoints struct with ZK proof points
* @param pubSignals_ the array of the ZK proof public signals
* @param pubSignalsCount_ the number of public signals
* @return true if the proof is valid, false - otherwise
*/
function verifyProofSafe(
address verifier_,
uint256[] memory pubSignals_,
ProofPoints memory proofPoints_,
uint256[] memory pubSignals_,
uint256 pubSignalsCount_
) internal view returns (bool) {
if (pubSignals_.length != pubSignalsCount_)
Expand All @@ -103,19 +103,19 @@ library Groth16VerifierHelper {
* @notice Function to call the `verifyProof` function on the `verifier` contract
* The length of the `pubSignals_` arr must be strictly equal to `pubSignalsCount_`
* @param verifier_ the address of the autogenerated `Verifier` contract
* @param pubSignals_ the array of the ZK proof public signals
* @param a_ the A point of the ZK proof
* @param b_ the B point of the ZK proof
* @param c_ the C point of the ZK proof
* @param pubSignals_ the array of the ZK proof public signals
* @param pubSignalsCount_ the number of public signals
* @return true if the proof is valid, false - otherwise
*/
function verifyProofSafe(
address verifier_,
uint256[] memory pubSignals_,
uint256[2] memory a_,
uint256[2][2] memory b_,
uint256[2] memory c_,
uint256[] memory pubSignals_,
uint256 pubSignalsCount_
) internal view returns (bool) {
if (pubSignals_.length != pubSignalsCount_)
Expand Down
20 changes: 10 additions & 10 deletions contracts/mock/libs/zkp/snarkjs/Groth16VerifierHelperMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ contract Groth16VerifierHelperMock {

function verifyProofStruct(
address verifier_,
uint256[] memory pubSignals_,
Groth16VerifierHelper.ProofPoints memory proofPoints_
Groth16VerifierHelper.ProofPoints memory proofPoints_,
uint256[] memory pubSignals_
) external view returns (bool) {
return verifier_.verifyProof(pubSignals_, proofPoints_);
return verifier_.verifyProof(proofPoints_, pubSignals_);
}

function verifyProof(
address verifier_,
uint256[] memory pubSignals_,
uint256[2] memory a_,
uint256[2][2] memory b_,
uint256[2] memory c_
uint256[2] memory c_,
uint256[] memory pubSignals_
) external view returns (bool) {
return verifier_.verifyProof(pubSignals_, a_, b_, c_);
return verifier_.verifyProof(a_, b_, c_, pubSignals_);
}

function verifyProofStructSafe(
address verifier_,
uint256[] memory pubSignals_,
Groth16VerifierHelper.ProofPoints memory proofPoints_,
uint256[] memory pubSignals_,
uint256 pubSignalsCount_
) external view returns (bool) {
return verifier_.verifyProofSafe(pubSignals_, proofPoints_, pubSignalsCount_);
return verifier_.verifyProofSafe(proofPoints_, pubSignals_, pubSignalsCount_);
}

function verifyProofSafe(
address verifier_,
uint256[] memory pubSignals_,
uint256[2] memory a_,
uint256[2][2] memory b_,
uint256[2] memory c_,
uint256[] memory pubSignals_,
uint256 pubSignalsCount_
) external view returns (bool) {
return verifier_.verifyProofSafe(pubSignals_, a_, b_, c_, pubSignalsCount_);
return verifier_.verifyProofSafe(a_, b_, c_, pubSignals_, pubSignalsCount_);
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solarity/solidity-lib",
"version": "3.0.0-rc.0",
"version": "3.0.0-rc.1",
"license": "MIT",
"author": "Distributed Lab",
"readme": "README.md",
Expand Down
24 changes: 12 additions & 12 deletions test/libs/zkp/Groth16VerifierHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,49 @@ describe("Groth16VerifierHelper", () => {
describe("verifyProof", () => {
it("should correctly call verifyProof function", async () => {
const contractInterface = expect(
await verifierHelper.verifyProofStruct(await verifier3.getAddress(), pubSignals3, { a, b, c }),
await verifierHelper.verifyProofStruct(await verifier3.getAddress(), { a, b, c }, pubSignals3),
).to.be.true;

expect(await verifierHelper.verifyProof(await verifier3.getAddress(), pubSignals3, a, b, c)).to.be.true;
expect(await verifierHelper.verifyProof(await verifier3.getAddress(), a, b, c, pubSignals3)).to.be.true;

await verifier2.setVerifyResult(false);

expect(await verifierHelper.verifyProofStruct(await verifier2.getAddress(), pubSignals2, { a, b, c })).to.be
expect(await verifierHelper.verifyProofStruct(await verifier2.getAddress(), { a, b, c }, pubSignals2)).to.be
.false;
expect(await verifierHelper.verifyProof(await verifier2.getAddress(), pubSignals2, a, b, c)).to.be.false;
expect(await verifierHelper.verifyProof(await verifier2.getAddress(), a, b, c, pubSignals2)).to.be.false;
});

it("should get exception if failed to call verifyProof function", async () => {
const wrongPubSignals = [1, 1, 2, 3];

await expect(verifierHelper.verifyProofStruct(await verifier2.getAddress(), wrongPubSignals, { a, b, c }))
await expect(verifierHelper.verifyProofStruct(await verifier2.getAddress(), { a, b, c }, wrongPubSignals))
.to.be.revertedWithCustomError(verifierHelper, "FailedToCallVerifyProof")
.withArgs();
await expect(verifierHelper.verifyProof(await verifier3.getAddress(), wrongPubSignals, a, b, c))
await expect(verifierHelper.verifyProof(await verifier3.getAddress(), a, b, c, wrongPubSignals))
.to.be.revertedWithCustomError(verifierHelper, "FailedToCallVerifyProof")
.withArgs();
});
});

describe("verifyProofSafe", () => {
it("should correctly call verifyProof function with additional checks", async () => {
expect(await verifierHelper.verifyProofStructSafe(await verifier3.getAddress(), pubSignals3, { a, b, c }, 3)).to
expect(await verifierHelper.verifyProofStructSafe(await verifier3.getAddress(), { a, b, c }, pubSignals3, 3)).to
.be.true;
expect(await verifierHelper.verifyProofSafe(await verifier3.getAddress(), pubSignals3, a, b, c, 3)).to.be.true;
expect(await verifierHelper.verifyProofSafe(await verifier3.getAddress(), a, b, c, pubSignals3, 3)).to.be.true;

await verifier2.setVerifyResult(false);

expect(await verifierHelper.verifyProofStructSafe(await verifier2.getAddress(), pubSignals2, { a, b, c }, 2)).to
expect(await verifierHelper.verifyProofStructSafe(await verifier2.getAddress(), { a, b, c }, pubSignals2, 2)).to
.be.false;
expect(await verifierHelper.verifyProofSafe(await verifier2.getAddress(), pubSignals2, a, b, c, 2)).to.be.false;
expect(await verifierHelper.verifyProofSafe(await verifier2.getAddress(), a, b, c, pubSignals2, 2)).to.be.false;
});

it("should get an exception if it passes invalid public signals arr", async () => {
await expect(verifierHelper.verifyProofStructSafe(await verifier2.getAddress(), pubSignals2, { a, b, c }, 4))
await expect(verifierHelper.verifyProofStructSafe(await verifier2.getAddress(), { a, b, c }, pubSignals2, 4))
.to.be.revertedWithCustomError(verifierHelper, "InvalidPublicSignalsCount")
.withArgs(pubSignals2.length, 4);

await expect(verifierHelper.verifyProofSafe(await verifier3.getAddress(), pubSignals3, a, b, c, 4))
await expect(verifierHelper.verifyProofSafe(await verifier3.getAddress(), a, b, c, pubSignals3, 4))
.to.be.revertedWithCustomError(verifierHelper, "InvalidPublicSignalsCount")
.withArgs(pubSignals3.length, 4);
});
Expand Down