-
Notifications
You must be signed in to change notification settings - Fork 599
chore: remappings to avoid nasty lib #18004
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
Merged
LHerskind
merged 1 commit into
next
from
lh/tmnt-420-spearbit-6-test-only-vm-cheatcode-path-in-bloblib
Oct 30, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright 2024 Aztec Labs. | ||
| pragma solidity >=0.8.27; | ||
|
|
||
| import {BlobLib as CoreBlobLib} from "@aztec/core/libraries/rollup/BlobLib.sol"; | ||
| import {Vm} from "forge-std/Vm.sol"; | ||
|
|
||
| /** | ||
| * @title BlobLib - Blob Management and Validation Library | ||
| * @author Aztec Labs | ||
| * @notice Core library for handling blob operations, validation, and commitment management in the Aztec rollup. | ||
| * | ||
| * @dev This library provides functionality for managing blobs: | ||
| * - Blob hash retrieval and validation against EIP-4844 specifications | ||
| * - Blob commitment verification and batched blob proof validation | ||
| * - Blob base fee retrieval for transaction cost calculations | ||
| * - Accumulated blob commitments hash calculation for epoch proofs | ||
| * | ||
| * VM_ADDRESS: | ||
| * The VM_ADDRESS (0x7109709ECfa91a80626fF3989D68f67F5b1DD12D) is a special address used to detect | ||
| * when the contract is running in a Foundry test environment. This address is derived from | ||
| * keccak256("hevm cheat code") and corresponds to Foundry's VM contract that provides testing utilities. | ||
| * When VM_ADDRESS.code.length > 0, it indicates we' dre in a test environment, allowing the library to: | ||
| * - Use Foundry's getBlobBaseFee() cheatcode instead of block.blobbasefee | ||
| * - Use Foundry's getBlobhashes() cheatcode instead of the blobhash() opcode | ||
| * This enables comprehensive testing of blob functionality without requiring actual blob transactions. | ||
| * | ||
| * Blob Validation Flow: | ||
| * 1. validateBlobs() processes L2 block blob data, extracting commitments and validating against real blobs | ||
| * 2. calculateBlobCommitmentsHash() accumulates commitments across an epoch for rollup circuit validation | ||
| * 3. validateBatchedBlob() verifies batched blob proofs using the EIP-4844 point evaluation precompile | ||
| * 4. calculateBlobHash() computes versioned hashes from commitments following EIP-4844 specification | ||
| */ | ||
| library BlobLib { | ||
| address public constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); | ||
| uint256 internal constant VERSIONED_HASH_VERSION_KZG = | ||
| 0x0100000000000000000000000000000000000000000000000000000000000000; // 0x01 << 248 to be used in blobHashCheck | ||
|
|
||
| /** | ||
| * @notice Get the blob base fee | ||
| * | ||
| * @dev If we are in a foundry test, we use the cheatcode to get the blob base fee. | ||
| * Otherwise, we use the `block.blobbasefee` | ||
| * | ||
| * @return uint256 - The blob base fee | ||
| */ | ||
| function getBlobBaseFee() internal view returns (uint256) { | ||
| if (VM_ADDRESS.code.length > 0) { | ||
| return Vm(VM_ADDRESS).getBlobBaseFee(); | ||
| } | ||
| return CoreBlobLib.getBlobBaseFee(); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Get the blob hash | ||
| * | ||
| * @dev If we are in a foundry test, we use the cheatcode to get the blob hashes | ||
| * Otherwise, we use the `blobhash` function in assembly | ||
| * | ||
| * @return blobHash - The blob hash | ||
| */ | ||
| function getBlobHash(uint256 _index) internal view returns (bytes32 blobHash) { | ||
| if (VM_ADDRESS.code.length > 0) { | ||
| // We know that this one is ABHORRENT. But it should not exists, and only will | ||
| // be hit in testing. | ||
| bytes32[] memory blobHashes = Vm(VM_ADDRESS).getBlobhashes(); | ||
| if (_index < blobHashes.length) { | ||
| return blobHashes[_index]; | ||
| } | ||
| return bytes32(0); | ||
| } | ||
| return CoreBlobLib.getBlobHash(_index); | ||
| } | ||
|
|
||
| function validateBlobs(bytes calldata _blobsInput, bool _checkBlob) | ||
| internal | ||
| view | ||
| returns (bytes32[] memory blobHashes, bytes32 blobsHashesCommitment, bytes[] memory blobCommitments) | ||
| { | ||
| return CoreBlobLib.validateBlobs(_blobsInput, _checkBlob); | ||
| } | ||
|
|
||
| function validateBatchedBlob(bytes calldata _blobInput) internal view returns (bool success) { | ||
| return CoreBlobLib.validateBatchedBlob(_blobInput); | ||
| } | ||
|
|
||
| function calculateBlobCommitmentsHash( | ||
| bytes32 _previousBlobCommitmentsHash, | ||
| bytes[] memory _blobCommitments, | ||
| bool _isFirstBlockOfEpoch | ||
| ) internal pure returns (bytes32 currentBlobCommitmentsHash) { | ||
| return CoreBlobLib.calculateBlobCommitmentsHash( | ||
| _previousBlobCommitmentsHash, _blobCommitments, _isFirstBlockOfEpoch | ||
| ); | ||
| } | ||
|
|
||
| function calculateBlobHash(bytes memory _blobCommitment) internal pure returns (bytes32) { | ||
| return CoreBlobLib.calculateBlobHash(_blobCommitment); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯