Putting Everything Together
Last updated
Last updated
Finally, we will see how we can call our prover to generate an app proof, submit to Brevis, and have Brevis contracts calling our app contract with our circuit output.
Edit index.ts. Initialize two clients: one for talking to our prover, one for talking to Brevis.
To prove token transfer, we only need to add a receipt which emits the USDC Transfer
event. In the below sample transaction receipt. We will use the first log in this receipt(LogPos 0). The second topic(FieldIndex 1) is "From" address. The first 32-byte data value(FieldIndex 0) is "TransferAmount". By adding these two Fields in receiptData, the prover service is able to check amount and generate corresponding application circuit output.
index.ts#L63-L82 handles submitting proof request to our prover
There are still several items left unproven in our custom circuit. They are:
How do we know if the transaction receipt is valid at all?
How do we know that the transaction is certainly on Ethereum?
How do we know the the transaction happened in block 21146236?
When you submit the proof generated by your circuit, Brevis's provers will wrap a proof around yours to further prove that the transaction is valid on the specified source chain and is certainly from the block we say it's from.
The arguments 1 and 11155111 are the chain ids of the data source chain and the "destination chain" that we want to post the final proof to, respectively
Now, run the program
If there is a partnership between the developer's project and Brevis, the developer can hand over the corresponding BREVIS_PARTNER_KEY and CALLBACK_ADDRESS to Brevis gateway when using submit
provided by Brevis SDK. Then you can skip the subsequent sendRequest on-chain transaction
BREVIS_PARTNER_KEY and CALLBACK_ADDRESS are NOT required to send requests to the Brevis gateway. Developers can leave them as empty string
As we can see, our request is assigned a request id and the fee we are going to pay is 0 (this is only zero for the testnet). Our program is currently waiting for us to pay the fee.
Now, you can call BrevisRequest.sendRequest
on the destination chain to pay for the proof. For demo purposes, we will just send the transaction through the Sepolia explorer. You can find the address of BrevisRequest under Contract Addresses. You may also find the sample contract here.
After the transaction is sent, it takes around two minutes for the transaction to be confirmed and Brevis's final proof to be generated. We should see the console outputs keep updating.