Skip to main content

Verify zkProof

The zkProofVerify method is designed to verify a zero-knowledge proof. This method confirms that the provided proof is both correctly constructed and authentic without exposing any underlying sensitive data. It returns key details such as the current rollup step, the Merkle root computed from the underlying data structure, and a boolean indicator of the proof's validity.

Method Signature

await zkdb.db(databaseName: string).zkProofVerify(): Promise<TZkDbProofVerify>;

Syntax

import { ZkDatabase } from 'zkdb';

const zkdb = await ZkDatabase.connect({
userName: "chiro-user",
privateKey: "EKFTciRxyxshZjimay9sktsn7v5PvmC5zPq7q4JnitHUytxUVnFP",
environment: "node",
// This URL is for test environment
url: "https://api.zkdatabase.org/graphql",
});

await zkdb.auth.signIn();



// Create new instance of 'db_test'
const dbTest = zkdb.db('db_test');
/**
* To verify zkProof, you have 2 options
* 1. Using our 'zkProofVerify()'
* 2. Using o1js 'verify()'
*/

// 1. Using zkdb 'zkProofVerify' method
/**
* Basically it a wrapper that handle
* get verification key, get zkProof
* and verify from o1js to user
* You just simply call it
* */
console.log(await dbTest.zkProofVerify());

// 2. Using o1js 'verify()'
/**
* To verify using o1js, all you need is 'zkProof' and 'verificationKey'
* Firstly, get verification key by calling 'verificationKey()'
* Secondly, get zkProof by calling 'zkProof()'
* Lastly, call the 'verify()' from o1js
* */

// Get verification key to verify
const verificationKey = await dbTest.verificationKey();

// Get zkProof to verify the proof
const zkProof = await dbTest.zkProof();

// Make sure we have both verification zkProof
if (verificationKey && zkProof) {
// Verify proof via 'verify' method from o1js
console.log('Is proof valid:', await verify(zkProof.proof, verificationKey));
}

await zkdb.auth.signOut();

Returns

  • A promise that resolves to a TZkDbProofVerify object.

The TZkDbProofVerify contains the following structure:

TZkProofResponse
PropertyTypeDescription
stepbigintRepresents the rollup step or iteration number associated with the proof verification.
merkleRootstringThe Merkle root computed from the underlying data, ensuring data integrity.
validbooleanA boolean value that indicates whether the provided proof is valid (true) or invalid (false).
{
step: 10n,
merkleRoot: "15383398803871485586427167108754689270190633959576017615536369378087055779186",
valid: true
}