Skip to main content

Placing proof requests

1. Pre-requisites

This is a detailed guide on how to place a proof request. In order to place proof requests, you need to set up the right environment and tooling. Refer to the Initial setup page for detailed instructions on setting up your environment.

Proof requests can be created using two methods:

  1. SDK
  2. UI

Note: Both methods require the following information:

  • Market ID: id of the market, which can be found on the Kalypso markets list dashboard.

2. Working with the SDK

To request proofs using the SDK, follow these steps:

2.1. Set Up Environment

Set up your environment as described on the Placing Market Requests page

2.2 Create a script file called requestProof.ts using this template:

import { KalypsoSdk } from "../../src";
import dotenv from "dotenv";

import { ethers } from "ethers";

import * as secret from "../secret.json";
import * as input from "../input.json";
import BigNumber from "bignumber.js";

import * as fs from "fs";
import { KalspsoConfig } from "../../src/types";
import { marketId } from "../../requestData.json";

const kalypsoConfig: KalspsoConfig = JSON.parse(fs.readFileSync("./contracts/arb-sepolia.json", "utf-8"));
const keys = JSON.parse(fs.readFileSync("./keys/arb-sepolia.json", "utf-8"));

dotenv.config();

const reward = new BigNumber(10).pow(18).multipliedBy(145).div(10).toFixed(0);

const createAskTest = async () => {
const provider = new ethers.JsonRpcProvider(keys.rpc);
const wallet = new ethers.Wallet(keys.treasury_private_key, provider);

console.log("using address", await wallet.getAddress());

let abiCoder = new ethers.AbiCoder();
let inputBytes = abiCoder.encode(["uint256[5]"], [[input.root, input.nullifier, input.out_commit, input.delta, input.memo]]);

const kalypso = new KalypsoSdk(wallet, kalypsoConfig);

const secretString = JSON.stringify(secret);

const latestBlock = await provider.getBlockNumber();

const assignmentDeadline = new BigNumber(latestBlock).plus(100000000000);
console.log({ latestBlock, assignmentDeadline: assignmentDeadline.toFixed(0) });
const proofGenerationTimeInBlocks = new BigNumber(100000000000);

const ivsCheckEciesCheckingKey = await kalypso.MarketPlace().IvsEnclaveConnector().fetchInputVerifierPublicKeys();

const isGoodRequest = await kalypso.MarketPlace().checkInputsAndEncryptedSecretWithIvs(
marketId,
inputBytes,
Buffer.from(secretString),
kalypso.MarketPlace().IvsEnclaveConnector().checkInputUrl(),
ivsCheckEciesCheckingKey.data.ecies_public_key
);

if (!isGoodRequest) {
throw new Error("Better not create a request, if it is not provable to prevent loss of funds");
}
console.log({ isGoodRequest });

// Create ASK request
const askRequest = await kalypso.MarketPlace().createAsk(
marketId,
inputBytes,
reward,
assignmentDeadline.toFixed(0),
proofGenerationTimeInBlocks.toFixed(0),
await wallet.getAddress(),
0, // TODO: keep this 0 for now
Buffer.from(secretString),
false
);
const tx = await askRequest.wait();
console.log("Ask Request Hash: ", askRequest.hash, " at block", tx?.blockNumber);
};

createAskTest();

The Requester needs to make the appropriate edits as hinted in the comments.

The zkApp developer needs to edit the code between the /* zkAPP specific */ comments as per their zkApp requirement.

Edits required are as follows:

  • Line 17-21: Configure these market details as per your zkApp.
  • Line 23-31: Edit this encoding logic as per your zkApp.
  • Line 49: Edit this to your refund address in the format "0xaddress".

The project is still in alpha, SDK updates for the above zkApp-specific configuration will be added in a later version. Developers can contact the Kalypso team for assistance with configuration.

2.3 Run the script

npm run ts-node your_file_name.ts

Upon running the script, it will output details including:

  • Approval Tx
  • Ask request hash
  • Receipt hash

2.4 Verify proof request

Verify your proof request on the Markets dashboard using the output from running the script

For example, the output for our sample sha256 Noir app is provided below:

> [email protected] ts-node
> ts-node proofRequest.ts

[
'0x0123000000000000000000000000000000000000000000000000000000000000',
'0x0100000000000000000000000000000000000000000000000000000000000000',
'0x0200000000000000000000000000000000000000000000000000000000000000',
'0x0300000000000000000000000000000000000000000000000000000000000000'
]
{ latestBlock: 810239, assignmentDeadline: '100810239' }
{ encrypted_secret: 38, acl: 129 }
Approval Tx: 0x91cfd934e3c1f71ee94f5a41f42f6ca62244d4084d3fd18363f01fbe5028f9f9
Approval Tx: 0xbbbaf5903139fb1c4a067556b436390d9fe7111d4363d8b2de9547064dd621b8
Ask Request Hash: 0xe29db3da3910cad83405151ba28467e688faf4c5f2a329462d05c2754f407c78
Done

Block explorer transaction details can be found here