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.
Before placing proof request, ensure that is enough token balance and gas balance to place request against your request.
- Markets with confidential inputs
- Markets with no confidential inputs
- 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 uint256[5]
is converted into contiguous bytes.
let abiCoder = new ethers.AbiCoder();
let publicInputs = abiCoder.encode(["uint256[5]"], [[input.root, input.nullifier, input.out_commit, input.delta, input.memo]]);
const secretString = JSON.stringify(secret);
// Data
const encryptedRequestData = await kalypso.MarketPlace().createEncryptedRequestData(publicInputs, Buffer.from(secretString), marketId);
// TODO: Verify encrypted inputs against IVS
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,
encryptedRequestData.publicInputs,
reward,
assignmentDeadline,
proofGenerationTimeInBlocks.toFixed(0),
refundAddress,
requestType,
encryptedRequestData.encryptedSecret,
encryptedRequestData.acl
);
const tx = await askRequest.wait();
console.log("Ask Request Hash: ", askRequest.hash, " at block", tx?.blockNumber);
Explanation of Each Step
-
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
uint256
values using theabiCoder.encode
method, ensuring they are in a format that Kalypso can process.
warningThe encoding of public inputs mentioned here is for a specific example, where
uint256[5]
is converted into bytes. Based on the inputs to your verifier contract, you will have to update this encoding. - abiCoder: We initialize the
-
Prepare Secret Data:
- secretString: We convert the
secret
object into a JSON string for easier handling during the encryption process.
- secretString: We convert the
-
Create Encrypted Request Data:
- encryptedRequestData: Using the
kalypso.MarketPlace().createEncryptedRequestData
method, we encrypt thepublicInputs
along with the secret data and associate it with a specific market (marketId
).
- encryptedRequestData: Using the
-
Verify Encrypted Inputs (TODO):
- TODO: This is a placeholder for verifying the encrypted inputs against the IVS (Initial Verification System). Ensure that the encrypted data meets the necessary verification criteria.
-
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.
-
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).
- askRequest: We create an ask request using the
-
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.
By following these steps, you ensure that the public inputs are securely encoded and encrypted before creating an ask request in the Kalypso marketplace.
- 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.
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
-
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 theabiCoder.encode
method, ensuring they are in a format that Kalypso can process.
warningThe 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. - abiCoder: We initialize the
-
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.
-
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).
- askRequest: We create an ask request using the
-
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.