Skip to content
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

The return value of GrandSumVerifier should be tested. #4

Open
qpzm opened this issue Apr 16, 2024 · 0 comments
Open

The return value of GrandSumVerifier should be tested. #4

qpzm opened this issue Apr 16, 2024 · 0 comments

Comments

@qpzm
Copy link

qpzm commented Apr 16, 2024

Description

GrandSumVerifier.verifyProof is not a view function.
https://github.com/summa-dev/summa-solvency/blob/fec83a747ead213261aecfaf4a01b43fff9731ee/contracts/src/GrandSumVerifier.sol#L32

This is a generated type in contracts/typechain-types/src/GrandSumVerifier.ts when running tests.

verifyProof(
  vk: PromiseOrValue<string>,
  proof: PromiseOrValue<BytesLike>,
  values: PromiseOrValue<BigNumberish>[],
  overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

It does not return the bool value that GrandSumVerifier.verifyProof returns so the test just checks whether the function is not reverted. However, the function does not revert when I change the input total_balances.
https://github.com/summa-dev/summa-solvency/blob/fec83a747ead213261aecfaf4a01b43fff9731ee/contracts/test/Verifiers.ts#L96

POC

Change total_balances to random values and then run npx hardhat test.
https://github.com/summa-dev/summa-solvency/blob/fec83a747ead213261aecfaf4a01b43fff9731ee/prover/bin/commitment_solidity_calldata.json#L5-L6

{
  "range_check_snark_proof": "...",
  "grand_sums_batch_proof": "...",
  "total_balances": [
    "0x1087f3e0000000000000",
    "0x197f3000000000000000"
  ]
}

In Verifier.ts, GrandSum Proof Verifier > should verify grand sum proof test passes.
https://github.com/summa-dev/summa-solvency/blob/fec83a747ead213261aecfaf4a01b43fff9731ee/contracts/test/Verifiers.ts#L96

Fix

  1. add view modifier to GrandSumVerifier.verifyProof
-    ) public returns (bool) {
+    ) public view returns (bool) {

https://github.com/summa-dev/summa-solvency/blob/fec83a747ead213261aecfaf4a01b43fff9731ee/contracts/src/GrandSumVerifier.sol#L32

  1. Test the return value.
-       expect(await grandSumVerifier.verifyProof(verifyingKey.address, proofs, totalBalances)).to.be.not.reverted;
+       expect(await grandSumVerifier.verifyProof(verifyingKey.address, proofs, totalBalances)).to.be.true;

https://github.com/summa-dev/summa-solvency/blob/fec83a747ead213261aecfaf4a01b43fff9731ee/contracts/test/Verifiers.ts#L96

  1. check success and revert before pairing as in InclusionVerifier.sol.
    success := ec_add_tmp(success, lhs_x, lhs_y)
+   if iszero(success) {
+       revert(0, 0)
+   }

https://github.com/summa-dev/summa-solvency/blob/fec83a747ead213261aecfaf4a01b43fff9731ee/contracts/src/GrandSumVerifier.sol#L143-L144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant