App Smart Contract
The final step is to write a smart contract to handle the ZK verified result. There are two integration points where you interact with Brevis's contracts:
Calling
BrevisRequest.sendRequest
to pay the proving fee.Handling circuit outputs in your app contract's callback function called by
BrevisRequest.
To streamline this process, you can use the contract SDK
Here is an example of a typical app 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
Handling Circuit Outputs in Contract
Your app contract needs to inherit 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 is 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.
Last updated