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

Issue with DCAP ZKP Proof Verification in Solidity Smart Contract #6

Open
danivilardell opened this issue May 28, 2024 · 0 comments
Open

Comments

@danivilardell
Copy link

I'm trying to verify the DCAP ZKP on chain via the Solidity smart contract.
I'm able to generate the proof, verify the proof on my machine, and generate the Solidity smart contract correctly.
However, when I try to verify the proof with Truffle, I get the following error:

Compiling your contracts...
===========================
> Compiling ./contracts/verifier.sol
> Artifacts written to /var/folders/6x/bs175kk945z9qhqcl0btt6sm0000gn/T/test--61440-1tB505qxWkv4
> Compiled successfully using:
   - solc: 0.8.19+commit.7dd6d404.Emscripten.clang


  Contract: Verifier
Proof verification failed: Error: Transaction has been reverted by the EVM:
{
  "transactionHash": "0x4bcbdd9ecde6c352b4d740676b50f2306f2f6842d06e018f9ae8b814a179700d",
  "transactionIndex": 0,
  "blockNumber": 2,
  "blockHash": "0x11d1c5a195c69959c40efffd917266dede16146357c8ad33481cc6764c47248f",
  "from": "0x627306090abab3a6e1400e9345bc60c78a8bef57",
  "to": "0x8cdaf0cd259887258bc13a92c0a6da92698644c0",
  "cumulativeGasUsed": 90000,
  "gasUsed": 90000,
  "contractAddress": null,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "effectiveGasPrice": 3410045336,
  "type": "0x2"
}
    at Object.TransactionError (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/lib/errors.js:90:1)
    at Object.TransactionRevertedWithoutReasonError (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/lib/errors.js:101:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-method/lib/index.js:396:1
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  receipt: {
    transactionHash: '0x4bcbdd9ecde6c352b4d740676b50f2306f2f6842d06e018f9ae8b814a179700d',
    transactionIndex: 0,
    blockNumber: 2,
    blockHash: '0x11d1c5a195c69959c40efffd917266dede16146357c8ad33481cc6764c47248f',
    from: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
    to: '0x8cdaf0cd259887258bc13a92c0a6da92698644c0',
    cumulativeGasUsed: 90000,
    gasUsed: 90000,
    contractAddress: null,
    logs: [],
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    effectiveGasPrice: 3410045336,
    type: '0x2'
  }
}
    ✔ Should verify (194ms)


  1 passing (242ms)

The truffle test I'm running is the following:

const SolidityVerifier = artifacts.require("Halo2Verifier");
const { TextEncoder } = require("util");
const fs = require("fs");


contract("Verifier", (accounts) => {

  it("Should verify", async () => {
    const verifier = await SolidityVerifier.deployed();

    // Read calldata from calldata.bin
    const calldataHex = fs.readFileSync("test/calldata.bin", "utf-8").trim();

    try {
      // Call the fallback function of the contract with the calldata
      const result = await web3.eth.sendTransaction({
        from: accounts[0],    // Replace with appropriate account if needed
        to: verifier.address,
        data: calldataHex
      });

      // If the call succeeds, the proof is valid
      console.log("Proof verified successfully.");
    } catch (error) {
      // If the call fails (reverts), the proof is invalid
      console.error("Proof verification failed:", error);
    }
  });
    
});

I have not modified the solidity smart contract and I generated the proof and the calldata the following way:

zk-clique p256-ecdsa prove --params bin/assets/params.json --evm  -o evm_proof.bin        
zk-clique p256-ecdsa gen-calldata --params bin/assets/params.json --proof evm_proof.bin -o calldata.bin

With params.json being the following file:

[
  {
    "msghash": "0x9c8adb93585642008f6defe84b014d3db86e65ec158f32c1fe8b78974123c264",
    "signature": "0x89e7242b7a0be99f7c668a8bdbc1fcaf6fa7562dd28538dbab4b059e9d6955c2c434593d3ccb0e7e5825effb14e251e6e5efb738d6042647ed2e2faac9191718",
    "pubkey": "0x04cd8fdae57e9fcc6638b7e0bdf1cfe6eb4783c29ed13916f10c121c70b7173dd61291422f9ef68a1b6a7e9cccbe7cc2c0738f81a996f7e62e9094c1f80bc0d788"
  }
]

What can I do to solve this issue?

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