Skip to content

chore: post blob batching cleanup#14637

Merged
MirandaWood merged 181 commits into
nextfrom
mw/blob-batching-final-cleanup
Jun 11, 2025
Merged

chore: post blob batching cleanup#14637
MirandaWood merged 181 commits into
nextfrom
mw/blob-batching-final-cleanup

Conversation

@MirandaWood

@MirandaWood MirandaWood commented May 30, 2025

Copy link
Copy Markdown
Contributor

Cleanup

Added as a new branch as to not bloat the number of files\lines changed in the core branches. Also can be merged later as (should) touch no logic.
This PR:

  • Rearranges nr methods into blob_batching.nr, keep blob.nr for evaluation only
  • Delete now unused blob_public_inputs.nr
  • Use bigcurve 0.9.0
  • Rename Blob.getBlobs() -> Blob.getBlobsPerBlock() (previously we only dealt with blobs per block, but now we deal with them across epochs, so getBlobs may be confusing)
  • Remove y and proof from the Blob class (only used in BatchedBlob, and not required to be carried around the repo)
  • Remove a few now unused methods
  • Remove circular dependencies and linter warnings

TODO on this branch:

  • Rename blob.nr to barycentric.nr or similar?
  • Rename BatchingBlobCommitment ('BatchedBlobCommitment'?)?

MirandaWood and others added 30 commits April 15, 2025 19:27
github-merge-queue Bot pushed a commit that referenced this pull request Jun 9, 2025
## The blobs are back in town.

This PR reworks blobs so that instead of calling the point evaluation
precompile for each blob (currently up to 3 per block => up to 96 (?)
calls per epoch), we call it once per epoch by batching blobs to a
single kzg commitment, opening, challenge, and proof.

How we can be sure that this one pairing check is equivalent to a check
per blob is covered in the maths by @iAmMichaelConnor
[here](https://hackmd.io/WUtNusQxS5KAw-af3gxycA?view) 🎉

## Overview

Instead of pushing to a long array of `BlobPublicInputs`, which are then
individually checked on L1, we batch each blob together to a single set
of `BlobAccumulatorPublicInputs`. The `start` accumulator state is fed
into each block root circuit, where the block's blobs are accumulated
and the `end` state is set. Each block merge circuit checks that the
state follows on correctly and, finally, the root circuit checks that
the very `start` state was empty and finalises the last `end` state.

This last `end` state makes up the set of inputs for the point
evaluation precompile. If the pairing check in that precompile passes,
we know that all blobs for all blocks in the epoch are valid and contain
only the tx effects validated by the rollup.

### Circuits

Key changes:
- Integrate BLS12-381 curve operations with `bignum` and `bigcurve`
libraries, plus tests.
- Rework the `blob` package to batch blobs and store in reworked
structs, plus tests.
- Rework the rollup circuits from `block_root` above to handle blob
accumulation state rather than a list of individual blob inputs, plus
(you guessed it) tests.

### Contracts

The contracts:
- No longer call the point evaluation precompile on `propose`, instead
inject the blob commitments, check they correspond to the broadcast
blobs, and stores them in the `blobCommitmentsHash`.
- Do not store any blob public inputs apart from the
`blobCommitmentsHash`.
- Call the point evaluation precompile once on `submitEpochRootProof`
for ALL blobs in the epoch.
- Use the same precompile inputs as pubic inputs to the root proof
verification along with the `blobCommitmentsHash` to link the circuit
batched blob, real L1 blobs, and the batched blob verified on L1.

### TypeScript

Key changes:
- Edit all the structs and methods reliant on the circuits/contracts to
match the above changes.
- Inject the final blob challenges used on each blob into all block
building methods in `orchestrator`.
- Accumulate blobs in ts when building blocks and use as inputs to each
rollup circuit, plus tests.
- Return the blob inputs required for `submitEpochRootProof` on
`finaliseEpoch()`.

### TODOs/Related Issues

- Choose field for hashing challenge:
#13608
- Instead of exponentiating `gamma` (expensive!), hash it for each
iteration: #13740
- Number of public inputs: BLS points in noir take up 9 fields (4 for
each coordinate as a limbed bignum, 1 for the is_inf flag) but can be
compressed to only 2. For recursive verification in block root and
above, would it be worth the gates to compress these? It depends whether
the gate cost of compression is more/less than gate cost of recursively
verifying 7 more public inputs.
- Remove the large trusted setup file from
`yarn-project/blob-lib/src/trusted_setup_bit_reversed.json`? Used in
testing, but may not be worth keeping (see code comments).
- Cleanup old, unused blob stuff in #14637.

## PR Stack

- [x] `mw/blob-batching` <- main feature
- [x] ^ `mw/blob-batching-bls-utils` <- BLS12-381 bigcurve and bignum
utils (noir) (#13583)
- [x] ^ `mw/blob-batching-bls-utils-ts` <- BLS12-381 bigcurve and bignum
utils (ts) (#13606)
- [x] ^ `mw/blob-batching-integration` <- Integrate batching into noir
protocol circuits (#13817)
- [x] ^ `mw/blob-batching-integration-ts-sol` <- Integrate batching into
ts and solidity (#14329)
- [ ] ^ `mw/blob-batching-cleanup` <- Remove old blob code

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Base automatically changed from mw/blob-batching to next June 9, 2025 15:40
@MirandaWood MirandaWood marked this pull request as ready for review June 9, 2025 19:49
@MirandaWood MirandaWood requested a review from LeilaWang as a code owner June 9, 2025 19:49

@LeilaWang LeilaWang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup! Just a few nits 😛

// eslint-disable-next-line @typescript-eslint/no-this-alias
let acc: BatchedBlobAccumulator = this; // TODO(MW): this.clone()
// Initialise the acc to iterate over:
let acc: BatchedBlobAccumulator = Object.create(this);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to define a clone method and avoid footgun of using Object.create. The data is not too big to be cloned and will be easier to understand.

* @returns The point fields.
*/
toBN254Fields() {
return [new Fr(this.compress().subarray(0, 31)), new Fr(this.compress().subarray(31, 48))];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just call this.compress() once. It's slightly more efficient and easier to see that the fields are taken from the same buffer.


// Note: we may be able to use the constant values in block_root/empty_block_root_rollup_inputs.nr, set by block_building_helpers.test.ts, but
// having this separate fn hopefully makes it clear how we treat empty blocks and their blobs, and won't break if we decide to change how
// getBlobsPerBlock() works on empty input.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include this in the test so we know the values match!

@iAmMichaelConnor iAmMichaelConnor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏎️

@MirandaWood MirandaWood added this pull request to the merge queue Jun 11, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 11, 2025
@MirandaWood MirandaWood added this pull request to the merge queue Jun 11, 2025
Merged via the queue into next with commit d836aa4 Jun 11, 2025
4 checks passed
@MirandaWood MirandaWood deleted the mw/blob-batching-final-cleanup branch June 11, 2025 13:05
danielntmd pushed a commit to danielntmd/aztec-packages that referenced this pull request Jul 16, 2025
## The blobs are back in town.

This PR reworks blobs so that instead of calling the point evaluation
precompile for each blob (currently up to 3 per block => up to 96 (?)
calls per epoch), we call it once per epoch by batching blobs to a
single kzg commitment, opening, challenge, and proof.

How we can be sure that this one pairing check is equivalent to a check
per blob is covered in the maths by @iAmMichaelConnor
[here](https://hackmd.io/WUtNusQxS5KAw-af3gxycA?view) 🎉

## Overview

Instead of pushing to a long array of `BlobPublicInputs`, which are then
individually checked on L1, we batch each blob together to a single set
of `BlobAccumulatorPublicInputs`. The `start` accumulator state is fed
into each block root circuit, where the block's blobs are accumulated
and the `end` state is set. Each block merge circuit checks that the
state follows on correctly and, finally, the root circuit checks that
the very `start` state was empty and finalises the last `end` state.

This last `end` state makes up the set of inputs for the point
evaluation precompile. If the pairing check in that precompile passes,
we know that all blobs for all blocks in the epoch are valid and contain
only the tx effects validated by the rollup.

### Circuits

Key changes:
- Integrate BLS12-381 curve operations with `bignum` and `bigcurve`
libraries, plus tests.
- Rework the `blob` package to batch blobs and store in reworked
structs, plus tests.
- Rework the rollup circuits from `block_root` above to handle blob
accumulation state rather than a list of individual blob inputs, plus
(you guessed it) tests.

### Contracts

The contracts:
- No longer call the point evaluation precompile on `propose`, instead
inject the blob commitments, check they correspond to the broadcast
blobs, and stores them in the `blobCommitmentsHash`.
- Do not store any blob public inputs apart from the
`blobCommitmentsHash`.
- Call the point evaluation precompile once on `submitEpochRootProof`
for ALL blobs in the epoch.
- Use the same precompile inputs as pubic inputs to the root proof
verification along with the `blobCommitmentsHash` to link the circuit
batched blob, real L1 blobs, and the batched blob verified on L1.

### TypeScript

Key changes:
- Edit all the structs and methods reliant on the circuits/contracts to
match the above changes.
- Inject the final blob challenges used on each blob into all block
building methods in `orchestrator`.
- Accumulate blobs in ts when building blocks and use as inputs to each
rollup circuit, plus tests.
- Return the blob inputs required for `submitEpochRootProof` on
`finaliseEpoch()`.

### TODOs/Related Issues

- Choose field for hashing challenge:
AztecProtocol#13608
- Instead of exponentiating `gamma` (expensive!), hash it for each
iteration: AztecProtocol#13740
- Number of public inputs: BLS points in noir take up 9 fields (4 for
each coordinate as a limbed bignum, 1 for the is_inf flag) but can be
compressed to only 2. For recursive verification in block root and
above, would it be worth the gates to compress these? It depends whether
the gate cost of compression is more/less than gate cost of recursively
verifying 7 more public inputs.
- Remove the large trusted setup file from
`yarn-project/blob-lib/src/trusted_setup_bit_reversed.json`? Used in
testing, but may not be worth keeping (see code comments).
- Cleanup old, unused blob stuff in AztecProtocol#14637.

## PR Stack

- [x] `mw/blob-batching` <- main feature
- [x] ^ `mw/blob-batching-bls-utils` <- BLS12-381 bigcurve and bignum
utils (noir) (AztecProtocol#13583)
- [x] ^ `mw/blob-batching-bls-utils-ts` <- BLS12-381 bigcurve and bignum
utils (ts) (AztecProtocol#13606)
- [x] ^ `mw/blob-batching-integration` <- Integrate batching into noir
protocol circuits (AztecProtocol#13817)
- [x] ^ `mw/blob-batching-integration-ts-sol` <- Integrate batching into
ts and solidity (AztecProtocol#14329)
- [ ] ^ `mw/blob-batching-cleanup` <- Remove old blob code

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
danielntmd pushed a commit to danielntmd/aztec-packages that referenced this pull request Jul 16, 2025
## Cleanup

Added as a new branch as to not bloat the number of files\lines changed
in the core branches. Also can be merged later as (should) touch no
logic.
This PR:

- Rearranges nr methods into `blob_batching.nr`, keep `blob.nr` for
evaluation only
- Delete now unused `blob_public_inputs.nr`
- Use bigcurve 0.9.0
- Rename `Blob.getBlobs()` -> `Blob.getBlobsPerBlock()` (previously we
only dealt with blobs per block, but now we deal with them across
epochs, so `getBlobs` may be confusing)
- Remove `y` and `proof` from the `Blob` class (only used in
`BatchedBlob`, and not required to be carried around the repo)
- Remove a few now unused methods
- Remove circular dependencies and linter warnings

TODO on this branch:
 - Rename `blob.nr` to `barycentric.nr` or similar?
 - Rename BatchingBlobCommitment ('BatchedBlobCommitment'?)?

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants