Putting Everything Together

Finally, we will see how we can call our prover to generate a custom proof, submit to Brevis, and have Brevis's contracts call our app contract with our circuit output.

Call Our Prover to Generate a Proof

Edit index.ts. Initialize two clients: one for talking to our prover, one for talking to Brevis.

const prover = new Prover('localhost:33247');
const brevis = new Brevis('appsdk.brevis.network:11080');

Adding Data to Prove

To prove an account's age, we only need to supply a transaction of nonce 0 that is originated from the account.

// initialize a proof request to our prover
const proofReq = new ProofRequest();
// adding the tx of nonce 0
proofReq.addTransaction(
    new TransactionData({
        hash: '0x6dc75e61220cc775aafa17796c20e49ac08030020fce710e3e546aa4e003454c',
        chain_id: 1,
        block_num: 19073244,
        nonce: 0,
        gas_tip_cap_or_gas_price: '90000000000',
        gas_fee_cap: '90000000000',
        gas_limit: 21000,
        from: '0x6c2843bA78Feb261798be1AAC579d1A4aE2C64b4',
        to: '0x2F19E5C3C66C44E6405D4c200fE064ECe9bC253a',
        value: '22329290000000000',
    }),
);

Calling Our Prover

const proofRes = await prover.prove(proofReq);

index.ts#L23-L41 handles submitting proof request to our prover

Submitting Your Proof to Brevis

There are still several items left unproven in our custom circuit. They are:

  • How do we know if the transaction is valid at all (signed by 0x6c28...)?

  • How do we know that the transaction is certainly on Ethereum?

  • How do we know the the transaction happened in block 19073244?

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.

const brevisRes = await brevis.submit(proofReq, proofRes, 1, 11155111);
await brevis.wait(brevisRes.id, 11155111);

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

ts-node index.ts
Click to see console output
proof 0x019fb03580787d96b8d949bbec67cdd70de7aa24416b7e15622278498976e53238462cc55ae41be8f498e8c9a102b93600a62065fd59b8d14f89bfbc7d209dad60fbe0ed0e159f7ac0cf76be32eec539678259187d706092d7bdfda103cc1ffd0017467b80a6490a33f618956ce0a87d7e005dad7a3661ac9e360b6dd410e99937ac3c70025ea92f5788041d63319be0015f906a16617f965e5060860064385bdcc0316e154f7f67d93dfabe98e7f3f78484c89d581e5b19f05854190986951a013b05a1f316f4ec76d1303a45c4323451f80b6055b50c7e98d3fd4d86dabed0f529e8bd13c5b9208a0607b4542be1b00044304242c01d7281faa41a97436185e4095b11ba1fbdf3743861ca788dea38ee276fe2ed3f4302dd09c736fcb7652401715ffcd70ddf9e508cb83d36c1bcc09a0e79f55924b3901e028e13019df28024d6e2e7bf9cfce98e2bef38c7690f8a015c8482b07f93df9f614bf2b629cc3b15e0faf8add00fb8435701f6995d6224d3c274a6b359b61fba45591a394037fd005ebd7e09747b06a0d9bb85423bf90831735eb80ad08ccbe8cf9a71544d026eca3dcfe041162ec5c4d0316d8ab24fa2001a2f052431c9a3ff1811c6d6946f387db7926583f184d628e9394ed42d58c00ad2bb8ecc2934db5c06faa5d654a1fe0185aabeceb5e667611dbd3c3c33dae13e44e9b0753fbda3dc891de725c74ddc01522f362d89187170620798817b4a5c0107cdcfbb98e2061a571a9c1488042a5203436abf9bc6d22bbf5ec931b9b2aee3b0c81aedbdbc5c861fc900b75724e400574bd57cd803d91926627c0ca037f6bf9f99e41be9b918555ffedd65ab91a144e75ecd467ac415d23e1eaa11979aa3015d3a1327dd33444e4a16e88cbcbf2a63083c6568343fdd7e93c4a946e97a495273a7c0746b24547f5abb461cc68db20052e58dc6a7736bdc09982efe0f2db29ac6a9ac50d8b9290b911644c18a1483fdc9f9fad34499d94b35dbb13e9a88ab00a7c05d9fc7c66eee1af22b42a111856a79112fec82c1cbf297c6ce9ce5a0c8df2c58a4df956856da382a6418091b70000000080d45c7fdb2a06b6dd07d38f6358552db25d540698b4f8201ee5f72f50c2f5e8a100ef08d52c09c438232bab7754e42a9262433cc2a41cbae88921c65fd5e630d114d70a6aa2e46e153a1c7840005aaf47461aea2df152e4d4bf7923c40ba0b340917760b4415706db6139a6c427fe86636e1d70844fc5551f267413b483c903c1132e063a3a520c13cbbaa7a81f1d0b851599fed0050a38b82b831359a94e32f03777f3551bd6b06d5a1671ded316abb503af9edfdcbc691cfabd097ce4a453905923458a4ac102b42383ff330ab3e9b67206c110384a37fc4891bcdb1dbe9f3094910cb0825aa21e0dc4a9145227fb17e3e47be967a9f95bc97d7f202706b4600c1af2bccd7d7c8abfaee96018bcc1de1cbab86880674a85d46ad7541f80d639849da420b1674b53fd0549d9b38a70201a9556904aefec50e67d2e09ef8e79cf06633715c26a801e53a777d2694db286aa948b389ddcc894b65df0c696241690e422b6fa909ff820693c67da5a2da418d28d4e56a10d9fea31c74570b8484500000000100f4fa2be331ad7753ecf2dc480924b2bd73bea113724c7430eefbd2241e18103c0b1bdbe49444195ba54ff557276de0005b9780c35f2ed950acfb0f341e03cbb1cef4bb48e703014fcc718796d395053825988ab90e5148356bc2391d6059ee
brevis request id 0x2c9fb082f0e3873b1f63da45a2963e9bb2746baae3dab553e70c3e856e2cbac2
brevis res {
  id: '0x2c9fb082f0e3873b1f63da45a2963e9bb2746baae3dab553e70c3e856e2cbac2',
  fee: '0'
}
request 0x2c9fb082f0e3873b1f63da45a2963e9bb2746baae3dab553e70c3e856e2cbac2 waiting for payment. call BrevisRequest.sendRequest to initiate the payment
request 0x2c9fb082f0e3873b1f63da45a2963e9bb2746baae3dab553e70c3e856e2cbac2 waiting for payment. call BrevisRequest.sendRequest to initiate the payment
...

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.

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.

...
request 0x2c9fb082f0e3873b1f63da45a2963e9bb2746baae3dab553e70c3e856e2cbac2 waiting for final tx
request 0x2c9fb082f0e3873b1f63da45a2963e9bb2746baae3dab553e70c3e856e2cbac2 success, tx 0x2631596212a162c633116ceaa58891b43a7cc02dcbf3e83b77d5c77bf596b6f7

Last updated