Skip to content

Commit

Permalink
fix: adding josh's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Dec 14, 2023
1 parent 3cf9fe9 commit c06c7ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 0 additions & 2 deletions docs/docs/explainers/explainer-recursion.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ This would be an approach for something like our guessing game, where proofs are

In such a situation, and assuming Alice is first, she would skip the first part and try to guess Bob's number. Bob would then verify her proof on the first section of his run, and try to guess Alice's number on the second part, and so on.

One could be confused about what happens with the recursive aggregation object, as it seems like it has no relationship with anything other than the "recursive part" of the circuit (it's simply an input and an output to `std::verify_proof`). It actually doesn't, even if it may seem lightly unintuitive. Again, it would help to imagine it as a baton in a draft race, which says nothing about the race itself but simply testifies that it was correctly passed around.

### Aggregating proofs

In some one-way interaction situations, recursiveness would allow for aggregation of simple proofs that don't need to be immediately verified on-chain or elsewhere.

Check warning on line 152 in docs/docs/explainers/explainer-recursion.md

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (recursiveness)
Expand Down
16 changes: 11 additions & 5 deletions docs/docs/how_to/how-to-recursion.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Recursion with NoirJS
title: How to use recursion on NoirJS
description: Learn how to implement recursion with NoirJS, a powerful tool for creating smart contracts on the EVM blockchain. This guide assumes familiarity with NoirJS, solidity verifiers, and the Barretenberg proving backend. Discover how to generate both final and intermediate proofs using `noir_js` and `backend_barretenberg`.
keywords:
[
Expand All @@ -21,9 +21,13 @@ keywords:
sidebar_position: 1
---

We're assuming you already read the [recursion explainer](../explainers/explainer-recursion.md), and that you already built a recursive circuit following [the reference](../noir/standard_library/recursion.md).
This guide shows you how to use recursive proofs in your NoirJS app. For the sake of clarity, it is assumed that:

It is also assumed that you're not using `noir_wasm` for compilation, and instead you've used [`nargo compile`](../reference/nargo_commands.md) to generate the `json` you're now importing into your project.
- You already have a NoirJS app. If you don't, please visit the [NoirJS tutorial](../tutorials/noirjs_app.md) and the [reference](../reference/NoirJS).
- You are familiar with what are recursive proofs and you have read the [recursion explainer](../explainers/explainer-recursion.md)
- You already built a recursive circuit following [the reference](../noir/standard_library/recursion.md), and understand how it works.

It is also assumed that you're not using `noir_wasm` for compilation, and instead you've used [`nargo compile`](../reference/nargo_commands.md) to generate the `json` you're now importing into your project. However, the guide should work just the same if you're using `noir_wasm`.

:::info

Expand All @@ -43,6 +47,8 @@ In a standard recursive app, you're also dealing with at least two circuits. For
- `main`: a circuit of type `assert(x != y)`
- `recursive`: a circuit that verifies `main`

For a full example on how recursive proofs work, please refer to the [noir-examples](https://github.com/noir/noir-examples) repository. We will *not* be using it as a reference for this guide.

## Step 1: Setup

In a common NoirJS app, you need to instantiate a backend with something like `const backend = new Backend(circuit)`. Then you feed it to the `noir_js` interface.
Expand Down Expand Up @@ -164,14 +170,14 @@ This allows you to neatly call exactly the method you want without conflicting n
```js
// Alice runs this 👇
const { witness: mainWitness } = await noirs.main.execute(input)
const proof = await backends.main.generateIntermediateProof(witness)
const proof = await backends.main.generateIntermediateProof(mainWitness)

// Bob runs this 👇
const verified = await backends.main.verifyIntermediateProof(proof)
const { proofAsFields, vkAsFields, vkHash } = await backends.main.generateIntermediateProofArtifacts(
proof,
numPublicInputs,
);

const recursiveProof = await noirs.recursive.generateFinalProof(recursiveInputs)
```

Expand Down

0 comments on commit c06c7ed

Please sign in to comment.