Developer tutorial for integrating Quantum
In the following page, we detail all the steps required for a protocol to integrate with Quantum. We use the ZKP2P's VenmoOnRamp2 circuit as an example throughout the demo.
Step 1: Setup Nodejs repo
Firstly, install quantum-sdk in your project:
npm i quantum-sdk
npm i axiosStep 2: Retrive auth key
Now, we have to retrieve an auth key to get access to quantum testnet.
import axios from "axios";
const RPC_ENDPOINT = "xx.xxx.xx";
async function main() {
let requestData = { "protocol_name": "your_protocol_name" }
let resp = await axios.post(`${RPC_ENDPOINT}/auth/protocol`, requestData);
const authKey = resp.data.auth_token;
console.log(authKey);
}Step 3: Circuit registration with Quantum
Now, assuming that the circuit's proving key, and verification key files have been generated following the steps detailed in Circom's documentation, the next step is to register the verification key file.
The circuit_hash received above is basically an identifier for this circuit, and here onward any interactions for this circuit will be done using this circuit_hash.
Step 3.1: Check if registration is completed
Next, we check if the circuit registration is complete.
Step 4: Proof submission to Quantum
Next, we will submit a proof to Quantum for aggregation. After the protocol has generated proof.json and public.json files through either Snarkjs or Rapidsnark, they can submit the proof to quantum as follows:
The proof_hash received above will be used to check the status of the proof.
Step 4.1: Check if proof is verified
To check if a proof has been aggregated and submitted on chain:
Step 5: Retrieve inclusion proof from Quantum
When an aggregated proof is submitted on chain, all the individual proofs’ public inputs are arranged in a merkle tree and it's root is stored on chain. The merkle proof for the same is used to verify validity of public inputs on-chain. It can be retrieved as follows:
Step 6: Verifying public inputs in contract
To verify public inputs on chain, the protocol needs to make slight changes to their contract, which are summarised below. We demonstrate by making changes to ZKP2P's VenmoSendProcessorV2 contract.
With this, we have completed the integration of Quantum with this protocol. If you are still facing any problems in integrating Quantum with your protocol, please reach out to us.
Last updated