Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Updates following is_recursive flag removal #4199

Merged
merged 6 commits into from
Feb 1, 2024
24 changes: 12 additions & 12 deletions docs/docs/how_to/how-to-recursion.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ In short:

:::

In a standard recursive app, you're also dealing with at least two circuits. For the purpose of this guide, we will assume these two:
In a standard recursive app, you're also dealing with at least two circuits. For the purpose of this guide, we will assume the following:

- `main`: a circuit of type `assert(x != y)`
- `main`: a circuit of type `assert(x != y)`, where `main` is marked with a `#[recursive]` attribute. This attribute states that the backend should generate proofs that are friendly for verification within another circuit.
- `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-lang/noir-examples) repository. We will *not* be using it as a reference for this guide.
Expand Down Expand Up @@ -77,7 +77,7 @@ const { witness } = noir.execute(input)
With this witness, you are now able to generate the intermediate proof for the main circuit:

```js
const { proof, publicInputs } = await backend.generateIntermediateProof(witness)
const { proof, publicInputs } = await backend.generateProof(witness)
```

:::warning
Expand All @@ -95,13 +95,13 @@ With this in mind, it becomes clear that our intermediate proof is the one *mean
Optionally, you are able to verify the intermediate proof:

```js
const verified = await backend.verifyIntermediateProof({ proof, publicInputs })
const verified = await backend.verifyProof({ proof, publicInputs })
```

This can be useful to make sure our intermediate proof was correctly generated. But the real goal is to do it within another circuit. For that, we need to generate the intermediate artifacts:
This can be useful to make sure our intermediate proof was correctly generated. But the real goal is to do it within another circuit. For that, we need to generate recursive proof artifacts that will be passed to the circuit that is verifying the proof we just generated. Instead of passing the proof and verification key as a byte array, we pass them as fields which makes it cheaper to verify in a circuit:

```js
const { proofAsFields, vkAsFields, vkHash } = await backend.generateIntermediateProofArtifacts( { publicInputs, proof }, publicInputsCount)
const { proofAsFields, vkAsFields, vkHash } = await backend.generateRecursiveProofArtifacts( { publicInputs, proof }, publicInputsCount)
```

This call takes the public inputs and the proof, but also the public inputs count. While this is easily retrievable by simply counting the `publicInputs` length, the backend interface doesn't currently abstract it away.
Expand Down Expand Up @@ -135,8 +135,8 @@ const recursiveInputs = {
}

const { witness, returnValue } = noir.execute(recursiveInputs) // we're executing the recursive circuit now!
const { proof, publicInputs } = backend.generateFinalProof(witness)
const verified = backend.verifyFinalProof({ proof, publicInputs })
const { proof, publicInputs } = backend.generateProof(witness)
const verified = backend.verifyProof({ proof, publicInputs })
```

You can obviously chain this proof into another proof. In fact, if you're using recursive proofs, you're probably interested of using them this way!
Expand Down Expand Up @@ -165,15 +165,15 @@ This allows you to neatly call exactly the method you want without conflicting n
```js
// Alice runs this 👇
const { witness: mainWitness } = await noir_programs.main.execute(input)
const proof = await backends.main.generateIntermediateProof(mainWitness)
const proof = await backends.main.generateProof(mainWitness)

// Bob runs this 👇
const verified = await backends.main.verifyIntermediateProof(proof)
const { proofAsFields, vkAsFields, vkHash } = await backends.main.generateIntermediateProofArtifacts(
const verified = await backends.main.verifyProof(proof)
const { proofAsFields, vkAsFields, vkHash } = await backends.main.generateRecursiveProofArtifacts(
proof,
numPublicInputs,
);
const recursiveProof = await noir_programs.recursive.generateFinalProof(recursiveInputs)
const recursiveProof = await noir_programs.recursive.generateProof(recursiveInputs)
```

:::
Loading