Skip to main content

Placing the Proof Request

The section explain how to place a request on Kalypso. Since there markets with/without confidential inputs, placing requests for each type of market is slightly different.

warning

Before placing proof request, ensure that is enough token balance and gas balance to place request against your request.

  1. Encode the publicInputs using abiCoder. This encoding is essential because Kalypso expects the public inputs to be in a format compatible with the proof verifier contract.

Below is an example where ["bytes", "bytes"] is converted into contiguous bytes.

./Kalypso-tutorial/index.ts
  
let abiCoder = new ethers.AbiCoder();
let publicInputs = abiCoder.encode(["bytes", "bytes"], [[input1, input2]]);

const reward = "1000000000"; // Reward tokens
const assignmentDeadline = "11000000"; // Block number before which the request should be assigned
const proofGenerationTimeInBlocks = "1821231"; // Number of blocks within which the proof must be generated
const refundAddress = await wallet.getAddress();
const requestType = 0;

const askRequest = await kalypso.MarketPlace().createAskWithEncryptedSecretAndAcl(
marketId,
publicInputs,
reward,
assignmentDeadline,
proofGenerationTimeInBlocks.toFixed(0),
refundAddress,
requestType,
"0x",
"0x"
);
const tx = await askRequest.wait();
console.log("Ask Request Hash: ", askRequest.hash, " at block", tx?.blockNumber);

Explanation of Each Step

  1. Encode Public Inputs:

    • abiCoder: We initialize the abiCoder to encode the public inputs. This step ensures that the inputs are formatted correctly for the proof verifier contract.
    • publicInputs: We encode an array of ["bytes", "bytes"] values using the abiCoder.encode method, ensuring they are in a format that Kalypso can process.
    warning

    The encoding of public inputs mentioned here is for a specific example, where ["bytes", "bytes"] is converted into bytes. Based on the inputs to your verifier contract, you will have to update this encoding.

  2. Define Request Parameters:

    • reward: The amount of reward tokens offered for the request.
    • assignmentDeadline: The block number by which the request must be assigned.
    • proofGenerationTimeInBlocks: The number of blocks within which the proof must be generated.
    • refundAddress: The address to which any refunds should be sent.
    • requestType: A numerical value representing the type of request.
  3. Create Ask Request:

    • askRequest: We create an ask request using the kalypso.MarketPlace().createAskWithEncryptedSecretAndAcl method. This request includes the encrypted public inputs, reward, deadlines, refund address, request type, encrypted secret, and access control list (ACL).
  4. Wait for Transaction Confirmation:

    • tx: We wait for the transaction to be confirmed on the blockchain.
    • console.log: Finally, we log the transaction hash and the block number at which it was confirmed.

After Placing Request

The proof cost will be transferred from user's wallet to Kalypso Core Contract and escrowed for further steps. It the generator successfully produces proof, the tokens are transferred to generator, else transferred back to proof requestor

Once the proof request is included in block, an unique requestID is generated, which is explained in next section.