Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ From now on, we focus only on the case in which the backend is barretenberg.

## `Opcode`

The following is the list of opcodes (see [`Opcode`](serde/acir.hpp#L3905)):
The following is the list of opcodes (see [`Opcode`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3224)):

- [`AssertZero`](serde/acir.hpp#L3907)
- [`MemoryInit`](serde/acir.hpp#L3971)
- [`MemoryOp`](serde/acir.hpp#L3947)
- [`BrilligCall`](serde/acir.hpp#L3998)
- [`BlackBoxFuncCall`](serde/acir.hpp#L3927)
- [`AssertZero`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3226)
- [`MemoryInit`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3281)
- [`MemoryOp`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3258)
- [`BrilligCall`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3307)
- [`BlackBoxFuncCall`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3242)

**Note:** There is another opcode: [`Call`](serde/acir.hpp#L4028), which was meant to be used to expose folding to Noir. We are not supporting this functionality, so barretenberg fails the reconstruction of a serialized Noir program if it encounters a `Call` opcode.
**Note:** There is another opcode: [`Call`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3336), which was meant to be used to expose folding to Noir. We are not supporting this functionality, so barretenberg fails the reconstruction of a serialized Noir program if it encounters a `Call` opcode.

### `AssertZero`

Expand All @@ -48,28 +48,28 @@ A `MemoryInit` opcode contains a list of witness indices representing the indice

A `MemoryOp` opcode contains the type of the operation, the index of the element of the table on which to perform the operation, and the value to be read or written.

**Note:** `MemoryOp` use [`Acir::Expression`](serde/acir.hpp#L3565)s to represent the operation type, the index, and the value. Barretenberg enforces that the expressions encode the data type they are supposed to represent. For example, the type of the operation is supposed to be represented by and expression with no multiplication terms, no linear terms, and with a constant term equal to either one or zero. When converting the expression to a memory operation type, barretenberg asserts that these assumptions are satisfied.
**Note:** `MemoryOp` uses [`Acir::Expression`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L2959)s to represent the operation type, the index, and the value. Barretenberg enforces that the expressions encode the data type they are supposed to represent. For example, the type of the operation is supposed to be represented by and expression with no multiplication terms, no linear terms, and with a constant term equal to either one or zero. When converting the expression to a memory operation type, barretenberg asserts that these assumptions are satisfied.

### `BrilligCall`

`BrilligCall` opcodes are no-ops in barretenberg. They are unconstrained functions in Noir that add witnesses without adding constraints for them.

### `BlackBoxFunctionCall`
### `BlackBoxFuncCall`

`BlackBoxFunctionCall` opcodes represent calls from Noir to functions that are implemented in barretenberg. An example is recursive verification: to perform recursive verification from Noir, we call `std::verify_with_type`, which adds a `BlackBoxFunctionCall` opcode for recursive verification. Then, when barretenberg parses this opcode, it adds the constraints for recursive verification using the witness indices passed by Noir.
`BlackBoxFuncCall` opcodes represent calls from Noir to functions that are implemented in barretenberg. An example is recursive verification: to perform recursive verification from Noir, we call `std::verify_with_type`, which adds a `BlackBoxFuncCall` opcode for recursive verification. Then, when barretenberg parses this opcode, it adds the constraints for recursive verification using the witness indices passed by Noir.

## Bytes to `Builder`

The conversion from a buffer of bytes to a `Builder` object happens in two steps. The buffer of bytes is first converted into an instance of the [`AcirFormat`](acir_format.hpp#L69) struct. Then, this struct is used to construct a `Builder`.
The conversion from a buffer of bytes to a `Builder` object happens in two steps. The buffer of bytes is first converted into an instance of the [`AcirFormat`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp#L82) struct. Then, this struct is used to construct a `Builder`.

### Bytes to `AcirFormat`

Instances of the [`AcirFormat`](acir_format.hpp#L69) struct contain a record of all the constraints written in Noir. Barretenberg's role is to take this record and construct a builder out of it. The `Builder` object can then be used to generate a Honk proof, a verification key, or accumulated during the generation of a Chonk proof.
Instances of the `AcirFormat` struct contain a record of all the constraints written in Noir. Barretenberg's role is to take this record and construct a builder out of it. The `Builder` object can then be used to generate a Honk proof, a verification key, or accumulated during the generation of a Chonk proof.

The single entrypoint for the conversion from a buffer of bytes into an instance of `AcirFormat` is the function [`circuit_buf_to_acir_format`](acir_to_constraint_buf.cpp#L166). This function deserializes the buffer according to the msgpack serialization format. The result of the deserialization is an instance of the [`Acir::Circuit`](serde/acir.hpp#L4502) struct, which the opcodes representing the Noir program.
The single entrypoint for the conversion from a buffer of bytes into an instance of `AcirFormat` is the function [`circuit_buf_to_acir_format`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp#L109). This function deserializes the buffer according to the msgpack serialization format. The result of the deserialization is an instance of the [`Acir::Circuit`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp#L3705) struct, which the opcodes representing the Noir program.

The `Acir::Circuit` is passed to [`circuit_serde_to_acir_format`](acir_to_constraint_buf.cpp#L115), which processes all of the opcodes and adds them to an instance of `AcirFormat`. This step is simply converting one representation (`Acir::Circuit`) into another (`AcirFormat`).
The `Acir::Circuit` is passed to [`circuit_serde_to_acir_format`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp#L96), which processes all of the opcodes and adds them to an instance of `AcirFormat`. This step is simply converting one representation (`Acir::Circuit`) into another (`AcirFormat`).

### `AcirFormat` to `Builder`

The instance of [`AcirFormat`](acir_format.hpp#L69) is then passed to the function [`create_circuit`](acir_format.cpp#L640), which constructs a `Builder` object with all the required constraints. This step is where barretenberg's handling of opcodes comes into play: the gates added to the builder depend on the internals of barretenberg and they would be different if we used a different backend.
The instance of `AcirFormat` is then passed to the function [`create_circuit`](https://github.com/AztecProtocol/aztec-packages/blob/795cd3ae80ba971a6d018b6d31e563c2fec870d3/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp#L156), which constructs a `Builder` object with all the required constraints. This step is where barretenberg's handling of opcodes comes into play: the gates added to the builder depend on the internals of barretenberg and they would be different if we used a different backend.
Loading
Loading