Skip to content

feat: emit compact PiecesAddedV2 events - #300

Merged
Kubuxu merged 7 commits into
mainfrom
issue-295-compact-pieces-added
Aug 19, 2026
Merged

feat: emit compact PiecesAddedV2 events#300
Kubuxu merged 7 commits into
mainfrom
issue-295-compact-pieces-added

Conversation

@Kubuxu

@Kubuxu Kubuxu commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #295

Summary

Adds a compact, ABI-decodable event for piece additions:

struct PackedCid {
    bytes32 header;
    bytes32 root;
}

event PiecesAddedV2(
    uint256 indexed setId,
    uint256 firstPieceId,
    PackedCid[] pieceCids
);

Piece IDs derive from firstPieceId + arrayIndex. CIDs are reconstructed by stripping the leading zero padding from header and appending root.

Events are limited to 100 pieces. Larger calls emit multiple events with adjusted firstPieceId values. This is a conservative round-number cap below the theoretical 125-piece FEVM limit.

BREAKING (!!): event consumers must upgrade

The legacy PiecesAdded event remains in the contract ABI but is no longer emitted. New additions emit only PiecesAddedV2.

Indexers and all other event consumers must support PiecesAddedV2 before the contract rollout.

Historical PiecesAdded logs remain decodable. The addPieces function ABI and listener callbacks are unchanged.
Tracked in #302

Size

Encoding 64 pieces Configured pieces/event
Existing PiecesAdded 12,480 bytes 41
PiecesAddedV2 4,256 bytes 100

A PiecesAddedV2 event consumes 160 + 64n bytes: two 32-byte topics, three 32-byte ABI words, and two 32-byte words per packed CID. A 100-piece event consumes 6,560 bytes. The theoretical maximum is 125 pieces (8,160 bytes), below FEVM’s 8,192-byte limit.

Gas

Measured with this PR applied, using the prior batch sizes of 41 pieces with one metadata pair and 61 pieces without metadata as baselines.

Metadata per piece Starting pieces Prior batch: gas/piece Largest batch: gas/piece Change
One pair 0 41: 71.003M 135: 59.633M −16.0%
One pair 1,024 41: 71.664M 135: 59.961M −16.3%
None 0 61: 10.063M 225: 6.505M −35.4%
None 1,024 61: 10.455M 225: 6.877M −34.2%

Dependency

Relies on #292 enforcing canonical PieceCIDv2 encodings so splitting a CID into header and root preserves it exactly.

Validation

  • Packed CID and 100/101-piece batching coverage
  • Full suite: 232 passed
  • Contract size checks pass

@FilOzzy FilOzzy added this to FOC Aug 14, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Aug 14, 2026
@Kubuxu
Kubuxu requested a review from rvagg August 14, 2026 23:08
@Kubuxu Kubuxu linked an issue Aug 14, 2026 that may be closed by this pull request
@Kubuxu Kubuxu added this to the August Contract Release milestone Aug 14, 2026
@Kubuxu Kubuxu self-assigned this Aug 14, 2026
@Kubuxu Kubuxu moved this from 📌 Triage to ⌨️ In Progress in FOC Aug 14, 2026
Base automatically changed from feat/optimized-add-pieces-2 to main August 14, 2026 23:42
@Kubuxu Kubuxu moved this from ⌨️ In Progress to 🔎 Awaiting review in FOC Aug 14, 2026
@Kubuxu
Kubuxu force-pushed the issue-295-compact-pieces-added branch from 4f3fe9e to b043537 Compare August 14, 2026 23:47
@Kubuxu
Kubuxu marked this pull request as ready for review August 14, 2026 23:48
@Kubuxu
Kubuxu requested a review from wjmelements as a code owner August 14, 2026 23:48
Comment thread src/PDPVerifier.sol Outdated
Kubuxu added 5 commits August 18, 2026 17:04
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
@Kubuxu
Kubuxu force-pushed the issue-295-compact-pieces-added branch from 79e5e6c to ff68e56 Compare August 18, 2026 15:08
@BigLep
BigLep requested a review from rvagg August 19, 2026 14:38
…ces-added

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>

# Conflicts:
#	src/PDPVerifier.sol
Comment on lines +16 to 18
/// @notice Deprecated. This event is no longer emitted; use {PiecesAddedV2} instead.
/// @custom:deprecated Use {PiecesAddedV2} instead.
event PiecesAdded(uint256 indexed setId, uint256[] pieceIds, Cids.Cid[] pieceCids);

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.

I suspect this will be removed from the ABI if it's unused. If so, might as well remove it from here now.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't want to remove it from ABI as indexers still have to support handling it.
I would be ok removing it in the next version after the switchover is complete, but indexers will still have to understand it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Solidity includes explicitly declared events in the ABI even when they are not emitted. forge inspect confirms PiecesAdded remains in both ABIs. We intentionally retain it so the current published ABI remains sufficient to decode historical logs; removal can happen after the consumer migration.

Comment thread src/PDPVerifier.sol Outdated
Comment thread src/PDPVerifier.sol
uint256 public constant MAX_PIECE_SIZE_LOG2 = 50;
uint256 public constant MAX_ENQUEUED_REMOVALS = 2000;
uint256 private constant PIECE_ID_EVENT_BATCH_SIZE = 100;
uint256 private constant PIECES_ADDED_EVENT_BATCH_SIZE = 100;

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.

how was this calculated?

@Kubuxu Kubuxu Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The limit is 125, based on the calculated event size, event size limit and running in ref-fvm. 100 was requested by Rod as just a round number.

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
@github-project-automation github-project-automation Bot moved this from 🔎 Awaiting review to ✔️ Approved by reviewer in FOC Aug 19, 2026
@Kubuxu
Kubuxu merged commit f278331 into main Aug 19, 2026
3 checks passed
@Kubuxu
Kubuxu deleted the issue-295-compact-pieces-added branch August 19, 2026 16:59
@github-project-automation github-project-automation Bot moved this from ✔️ Approved by reviewer to 🎉 Done in FOC Aug 19, 2026
@github-project-automation github-project-automation Bot moved this to 🎉 Done in PDP Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🎉 Done
Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

Proposal: compact PiecesAddedV2 event

4 participants