Contract Integration
Write the custom app contract that integrates with Brevis SDK.
The final step is to write a smart contract that handles the ZK-attested results. To streamline this process, you can use the contract SDK and implement the handleProofResult
function to process the circuit outputs.
Here is an example of a typical app contract:
Handling Circuit Outputs in Contract
Your app contract needs to inherit the BrevisApp
contract and call its constructor with the address of the BrevisProof
contract (Deployment Addresses). It also needs to override the abstract method handleProofResult
.
Checking the Verifying Key
The vk hash you get from the Compiling & Setup step uniquely identifies of your circuit. You should save the vk hash in your contract. When handling callbacks from the BrevisRequest
contract, you must check that the vkHash matches your expected one.
Reading the Circuit Output
The output calls in your circuit definition are packed in the form of abi.encodePacked(...)
. The order of the variables is the same as the order you call the output APIs in the circuit.
Pay Request Fee
If an application is partnered with the Brevis system to serve requests with a customized fee plan, it can skip this step and send off-chain requests directly to the Brevis gateway.
Otherwise, for most applications, the user needs to send the request with fee in native tokens on-chain to the BrevisRequest
contract.
Paying the Fee
You need to call BrevisRequest.sendRequest
with the requestId
and the feeValue
(as transaction value) you acquire from in the previous step when you call app.PrepareRequest
in Go. The parameter _callback
is where you specify your app contract address.
Or, you can send a raw transaction using the calldata
you acquire from app.PrepareRequest
as the transaction call data and the feeValue
as the transaction value.
Refunding a Fee after Timeout
requestTimeout
a state variable in BrevisRequest
. If there is no proof submitted within the requestTimeout
, you can call BrevisRequest.refund
to refund the fee back to the _refundee
you initially specified when calling sendRequest
Last updated