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

feat: blobs 2. #10188

Merged
merged 71 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
b4033be
Revert "fix: Revert "feat: blobs. (#9302)" (#10187)"
MirandaWood Nov 25, 2024
de14c32
chore: comments/renaming in Rollup.sol
MirandaWood Nov 27, 2024
b75a6f7
feat: give up and make blob oracle for simulation
MirandaWood Nov 27, 2024
3391096
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Nov 27, 2024
624c36d
fix: post merge fixes, fmt, fixtures
MirandaWood Nov 28, 2024
ccb82b2
chore: dummy change to fix ci runner
MirandaWood Nov 28, 2024
fe6fa68
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Nov 28, 2024
64586d8
fix: do horrible things to reduce contract size
MirandaWood Nov 28, 2024
21e8c3a
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Nov 28, 2024
24f2f0e
chore: post merge fixes, add libs to gen contracts, comments
MirandaWood Nov 28, 2024
566c2fc
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Nov 29, 2024
fc03321
feat: integrate private logs, add blob oracle issue num, regen fixtur…
MirandaWood Nov 30, 2024
5c5a655
chore: update proof fixture
MirandaWood Nov 30, 2024
4bd1312
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 2, 2024
f5aac25
fix: revert merge changes, compile time down from 90 to 10 mins (#10341)
MirandaWood Dec 3, 2024
d4bf371
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 3, 2024
78ca2ab
chore: post merge fixes, fmt
MirandaWood Dec 3, 2024
18a66b0
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 3, 2024
b14a892
chore: post merge fixes + update proof fixture
MirandaWood Dec 3, 2024
25d5ba0
chore: some orch cleanup
MirandaWood Dec 3, 2024
a325000
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 3, 2024
933191b
chore: remake consts after merge
MirandaWood Dec 3, 2024
64a4724
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 4, 2024
07449a3
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 4, 2024
5dd97e3
feat: redo blob publishing
MirandaWood Dec 4, 2024
359758f
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 4, 2024
6c0a22a
feat: rearrange all blob l1 logic, replicate in ts
MirandaWood Dec 5, 2024
681b53a
feat: add gas estimation for blob txs, cleanup contracts, increase he…
MirandaWood Dec 5, 2024
1153bf8
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 5, 2024
8511d52
chore: typos, comments clarifications
MirandaWood Dec 5, 2024
ede52a6
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 5, 2024
4d927d2
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 5, 2024
c44e158
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 6, 2024
5506aa2
chore: fix bad noir merge formatting
MirandaWood Dec 6, 2024
f71874b
fix: change slot overrides after merge
MirandaWood Dec 6, 2024
110692f
chore: update timeouts, comment, grab custom error from ext lib
MirandaWood Dec 6, 2024
389a596
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 6, 2024
dff8962
chore: post merge formatting
MirandaWood Dec 6, 2024
a01595d
chore: add leolib abi to error handling
MirandaWood Dec 6, 2024
9a89e75
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 6, 2024
5f5a10d
chore: inc test timeout after sync
MirandaWood Dec 7, 2024
c8c8758
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 7, 2024
03f4ce1
chore: inc timeout
MirandaWood Dec 7, 2024
7fd775f
chore: increase! those! timeouts!
MirandaWood Dec 7, 2024
a9bfda5
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 7, 2024
ba713cd
chore: header -> block_header to match merge
MirandaWood Dec 7, 2024
2daaa48
chore: guess what.
MirandaWood Dec 8, 2024
c6cde5d
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 9, 2024
ec0d50d
chore: fixture + comment out slower test
MirandaWood Dec 9, 2024
be805b6
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 10, 2024
09bcff3
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 10, 2024
949090f
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 11, 2024
a74377b
chore: remove some warnings from blob code
MirandaWood Dec 11, 2024
426f376
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 11, 2024
dc2955f
chore: post merge formatting
MirandaWood Dec 11, 2024
aa3d368
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 12, 2024
728d784
chore: remake constants after merge
MirandaWood Dec 12, 2024
0332bb8
fix: bad merge
MirandaWood Dec 12, 2024
59148e2
chore: proof fixture
MirandaWood Dec 12, 2024
76da0d4
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 12, 2024
e8685ac
feat: reduce the number unconstrained boundary hops in bloblib (#10603)
TomAFrench Dec 12, 2024
7827a73
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 13, 2024
e6fc5b5
fix: add temp brillig skip to run CI
MirandaWood Dec 13, 2024
c423c90
chore: update prover.tomls, ensure block-root is populated
MirandaWood Dec 13, 2024
f420a79
chore: add brillig gates skip to earthfile
MirandaWood Dec 13, 2024
36efe51
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 13, 2024
313c3d8
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 13, 2024
448187e
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 13, 2024
436b7d6
chore: reenable test
MirandaWood Dec 13, 2024
f096e25
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 13, 2024
b8699a2
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
MirandaWood Dec 13, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
concurrency_key: build-x86
# prepare images locally, tagged by commit hash
- name: "Build E2E Image"
timeout-minutes: 40
timeout-minutes: 90
if: (needs.configure.outputs.non-docs == 'true' && needs.configure.outputs.non-barretenberg-cpp == 'true') || github.ref_name == 'master'
run: |
earthly-ci ./yarn-project+export-e2e-test-images
Expand Down
229 changes: 137 additions & 92 deletions l1-contracts/src/core/Rollup.sol

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct SubmitEpochRootProofArgs {
uint256 epochSize;
bytes32[7] args;
bytes32[] fees;
bytes blobPublicInputs;
bytes aggregationObject;
bytes proof;
}
Expand Down Expand Up @@ -70,13 +71,15 @@ interface IRollup {
function propose(
ProposeArgs calldata _args,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body
bytes calldata _body,
bytes calldata _blobInput
) external;

function proposeAndClaim(
ProposeArgs calldata _args,
SignatureLib.Signature[] memory _signatures,
bytes calldata _body,
bytes calldata _blobInput,
EpochProofQuoteLib.SignedEpochProofQuote calldata _quote
) external;

Expand All @@ -89,7 +92,7 @@ interface IRollup {
SignatureLib.Signature[] memory _signatures,
bytes32 _digest,
Timestamp _currentTime,
bytes32 _txsEffecstHash,
bytes32 _blobsHash,
DataStructures.ExecutionFlags memory _flags
) external view;

Expand Down Expand Up @@ -140,7 +143,7 @@ interface IRollup {
uint256 _epochSize,
bytes32[7] calldata _args,
bytes32[] calldata _fees,
bytes calldata _blobPublicInputs,
bytes calldata _aggregationObject
) external view returns (bytes32[] memory);
function computeTxsEffectsHash(bytes calldata _body) external pure returns (bytes32);
}
112 changes: 112 additions & 0 deletions l1-contracts/src/core/libraries/BlobLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {Hash} from "@aztec/core/libraries/crypto/Hash.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Vm} from "forge-std/Vm.sol";

library BlobLib {
/**
* @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(address _vmAddress) public view returns (uint256) {
if (_vmAddress.code.length > 0) {
return Vm(_vmAddress).getBlobBaseFee();
}
return block.blobbasefee;
}

/**
* @notice Validate an L2 block's blobs and return the hashed blobHashes and public inputs.
* Input bytes:
* input[:1] - num blobs in block
* input[1:] - 192 * num blobs of the above _blobInput
* @dev Marked as public to reduce Rollup.sol contract size
* @param _blobsInput - The above bytes to verify a blob
*/
function validateBlobs(bytes calldata _blobsInput, bool _checkBlob)
public
view
returns (bytes32 blobsHash, bytes32 blobPublicInputsHash)
{
// We cannot input the incorrect number of blobs below, as the blobsHash
// and epoch proof verification will fail.
uint8 numBlobs = uint8(_blobsInput[0]);
bytes32[] memory blobHashes = new bytes32[](numBlobs);
bytes memory blobPublicInputs;
for (uint256 i = 0; i < numBlobs; i++) {
// Add 1 for the numBlobs prefix
uint256 blobInputStart = i * 192 + 1;
// Since an invalid blob hash here would fail the consensus checks of
// the header, the `blobInput` is implicitly accepted by consensus as well.
blobHashes[i] = validateBlob(_blobsInput[blobInputStart:blobInputStart + 192], i, _checkBlob);
// We want to extract the 112 bytes we use for public inputs:
// * input[32:64] - z
// * input[64:96] - y
// * input[96:144] - commitment C
// Out of 192 bytes per blob.
blobPublicInputs =
abi.encodePacked(blobPublicInputs, _blobsInput[blobInputStart + 32:blobInputStart + 144]);
}
// Return the hash of all z, y, and Cs, so we can use them in proof verification later
blobPublicInputsHash = sha256(blobPublicInputs);
// Hash the EVM blob hashes for the block header
blobsHash = Hash.sha256ToField(abi.encodePacked(blobHashes));
}

/**
* @notice Validate a blob.
* Input bytes:
* input[:32] - versioned_hash
* input[32:64] - z
* input[64:96] - y
* input[96:144] - commitment C
* input[144:192] - proof (a commitment to the quotient polynomial q(X))
* - This can be relaxed to happen at the time of `submitProof` instead
* @notice Apparently there is no guarantee that the blobs will be processed in the order sent
* so the use of blobhash(_blobNumber) may fail in production
* @param _blobInput - The above bytes to verify a blob
*/
function validateBlob(bytes calldata _blobInput, uint256 _blobNumber, bool _checkBlob)
internal
view
returns (bytes32 blobHash)
{
if (!_checkBlob) {
return bytes32(_blobInput[0:32]);
}
assembly {
blobHash := blobhash(_blobNumber)
}
require(blobHash == bytes32(_blobInput[0:32]), Errors.Rollup__InvalidBlobHash(blobHash));

// Staticcall the point eval precompile https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile :
(bool success,) = address(0x0a).staticcall(_blobInput);
require(success, Errors.Rollup__InvalidBlobProof(blobHash));
}

/**
* @notice Converts a BLS12 field element from bytes32 to a nr BigNum type
* The nr bignum type for BLS12 fields is encoded as 3 nr fields - see blob_public_inputs.ts:
* firstLimb = last 15 bytes;
* secondLimb = bytes 2 -> 17;
* thirdLimb = first 2 bytes;
* Used when verifying epoch proofs to gather blob specific public inputs.
* @param _input - The field in bytes32
*/
function bytes32ToBigNum(bytes32 _input)
internal
pure
returns (bytes32 firstLimb, bytes32 secondLimb, bytes32 thirdLimb)
{
firstLimb = bytes32(uint256(uint120(bytes15(_input << 136))));
secondLimb = bytes32(uint256(uint120(bytes15(_input << 16))));
thirdLimb = bytes32(uint256(uint16(bytes2(_input))));
}
}
23 changes: 19 additions & 4 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ library Constants {
uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4;
uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000000000;
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
uint256 internal constant FIELDS_PER_BLOB = 4096;
uint256 internal constant BLOBS_PER_BLOCK = 3;
uint256 internal constant PRIVATE_LOG_SIZE_IN_FIELDS = 18;
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
uint256 internal constant AZTEC_MAX_EPOCH_DURATION = 32;
uint256 internal constant GENESIS_ARCHIVE_ROOT =
1002640778211850180189505934749257244705296832326768971348723156503780793518;
Expand Down Expand Up @@ -168,6 +169,9 @@ library Constants {
uint256 internal constant FUNCTION_LEAF_PREIMAGE_LENGTH = 5;
uint256 internal constant GLOBAL_VARIABLES_LENGTH = 9;
uint256 internal constant APPEND_ONLY_TREE_SNAPSHOT_LENGTH = 2;
uint256 internal constant APPEND_ONLY_TREE_SNAPSHOT_LENGTH_BYTES = 36;
uint256 internal constant SPONGE_BLOB_LENGTH = 11;
uint256 internal constant BLOB_PUBLIC_INPUTS = 6;
uint256 internal constant L1_TO_L2_MESSAGE_LENGTH = 6;
uint256 internal constant L2_TO_L1_MESSAGE_LENGTH = 3;
uint256 internal constant SCOPED_L2_TO_L1_MESSAGE_LENGTH = 4;
Expand Down Expand Up @@ -200,6 +204,7 @@ library Constants {
uint256 internal constant TOTAL_FEES_LENGTH = 1;
uint256 internal constant TOTAL_MANA_USED_LENGTH = 1;
uint256 internal constant HEADER_LENGTH = 25;
uint256 internal constant HEADER_LENGTH_BYTES = 648;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 731;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 867;
uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 38;
Expand All @@ -219,9 +224,9 @@ library Constants {
uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1845;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 956;
uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 13;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 31;
uint256 internal constant BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 90;
uint256 internal constant ROOT_ROLLUP_PUBLIC_INPUTS_LENGTH = 76;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 52;
uint256 internal constant BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 666;
uint256 internal constant ROOT_ROLLUP_PUBLIC_INPUTS_LENGTH = 652;
uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674;
uint256 internal constant NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 2048;
uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048;
Expand Down Expand Up @@ -271,6 +276,16 @@ library Constants {
uint256 internal constant START_EMIT_NULLIFIER_WRITE_OFFSET = 208;
uint256 internal constant START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = 224;
uint256 internal constant START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 226;
uint256 internal constant TX_START_PREFIX = 8392562855083340404;
uint256 internal constant REVERT_CODE_PREFIX = 1;
uint256 internal constant TX_FEE_PREFIX = 2;
uint256 internal constant NOTES_PREFIX = 3;
uint256 internal constant NULLIFIERS_PREFIX = 4;
uint256 internal constant L2_L1_MSGS_PREFIX = 5;
uint256 internal constant PUBLIC_DATA_UPDATE_REQUESTS_PREFIX = 6;
uint256 internal constant PRIVATE_LOGS_PREFIX = 7;
uint256 internal constant UNENCRYPTED_LOGS_PREFIX = 8;
uint256 internal constant CONTRACT_CLASS_LOGS_PREFIX = 9;
uint256 internal constant PROOF_TYPE_PLONK = 0;
uint256 internal constant PROOF_TYPE_HONK = 1;
uint256 internal constant PROOF_TYPE_OINK = 2;
Expand Down
7 changes: 3 additions & 4 deletions l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ library Errors {
error Rollup__InvalidProposedArchive(bytes32 expected, bytes32 actual); // 0x32532e73
error Rollup__InvalidTimestamp(Timestamp expected, Timestamp actual); // 0x3132e895
error Rollup__InvalidVersion(uint256 expected, uint256 actual); // 0x9ef30794
error Rollup__InvalidBlobHash(bytes32 blobHash); // 0xc4a168c6
error Rollup__InvalidBlobProof(bytes32 blobHash); // 0x5ca17bef
error Rollup__InvalidBlobPublicInputsHash(bytes32 expected, bytes32 actual); // 0xfe6b4994
error Rollup__NoEpochToProve(); // 0xcbaa3951
error Rollup__NonSequentialProving(); // 0x1e5be132
error Rollup__NotClaimingCorrectEpoch(Epoch expected, Epoch actual); // 0xf0e0744d
Expand All @@ -77,10 +80,6 @@ library Errors {
error Rollup__InvalidBasisPointFee(uint256 basisPointFee); // 0x4292d136
error Rollup__InvalidManaBaseFee(uint256 expected, uint256 actual); // 0x73b6d896

//TxsDecoder
error TxsDecoder__InvalidLogsLength(uint256 expected, uint256 actual); // 0x829ca981
error TxsDecoder__TxsTooLarge(uint256 expected, uint256 actual); // 0xc7d44a62

// HeaderLib
error HeaderLib__InvalidHeaderSize(uint256 expected, uint256 actual); // 0xf3ccb247
error HeaderLib__InvalidSlotNumber(Slot expected, Slot actual); // 0x09ba91ff
Expand Down
85 changes: 6 additions & 79 deletions l1-contracts/src/core/libraries/HeaderLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Errors} from "@aztec/core/libraries/Errors.sol";
* | 0x0020 | 0x04 | lastArchive.nextAvailableLeafIndex
* | | | ContentCommitment {
* | 0x0024 | 0x20 | numTxs
* | 0x0044 | 0x20 | txsEffectsHash
* | 0x0044 | 0x20 | blobsHash
* | 0x0064 | 0x20 | inHash
* | 0x0084 | 0x20 | outHash
* | | | StateReference {
Expand Down Expand Up @@ -92,7 +92,7 @@ library HeaderLib {

struct ContentCommitment {
uint256 numTxs;
bytes32 txsEffectsHash;
bytes32 blobsHash;
bytes32 inHash;
bytes32 outHash;
}
Expand All @@ -106,14 +106,15 @@ library HeaderLib {
uint256 totalManaUsed;
}

uint256 private constant HEADER_LENGTH = 0x288; // Header byte length
uint256 private constant HEADER_LENGTH = Constants.HEADER_LENGTH_BYTES; // Header byte length

/**
* @notice Decodes the header
* @dev Marked as public to reduce Rollup.sol contract size
* @param _header - The header calldata
* @return The decoded header
*/
function decode(bytes calldata _header) internal pure returns (Header memory) {
function decode(bytes calldata _header) public pure returns (Header memory) {
MirandaWood marked this conversation as resolved.
Show resolved Hide resolved
require(
_header.length == HEADER_LENGTH,
Errors.HeaderLib__InvalidHeaderSize(HEADER_LENGTH, _header.length)
Expand All @@ -128,7 +129,7 @@ library HeaderLib {

// Reading ContentCommitment
header.contentCommitment.numTxs = uint256(bytes32(_header[0x0024:0x0044]));
header.contentCommitment.txsEffectsHash = bytes32(_header[0x0044:0x0064]);
header.contentCommitment.blobsHash = bytes32(_header[0x0044:0x0064]);
header.contentCommitment.inHash = bytes32(_header[0x0064:0x0084]);
header.contentCommitment.outHash = bytes32(_header[0x0084:0x00a4]);

Expand Down Expand Up @@ -165,78 +166,4 @@ library HeaderLib {

return header;
}

function toFields(Header memory _header) internal pure returns (bytes32[] memory) {
bytes32[] memory fields = new bytes32[](25);

// must match the order in the Header.getFields
fields[0] = _header.lastArchive.root;
fields[1] = bytes32(uint256(_header.lastArchive.nextAvailableLeafIndex));
fields[2] = bytes32(_header.contentCommitment.numTxs);
fields[3] = _header.contentCommitment.txsEffectsHash;
fields[4] = _header.contentCommitment.inHash;
fields[5] = _header.contentCommitment.outHash;
fields[6] = _header.stateReference.l1ToL2MessageTree.root;
fields[7] = bytes32(uint256(_header.stateReference.l1ToL2MessageTree.nextAvailableLeafIndex));
fields[8] = _header.stateReference.partialStateReference.noteHashTree.root;
fields[9] = bytes32(
uint256(_header.stateReference.partialStateReference.noteHashTree.nextAvailableLeafIndex)
);
fields[10] = _header.stateReference.partialStateReference.nullifierTree.root;
fields[11] = bytes32(
uint256(_header.stateReference.partialStateReference.nullifierTree.nextAvailableLeafIndex)
);
fields[12] = _header.stateReference.partialStateReference.publicDataTree.root;
fields[13] = bytes32(
uint256(_header.stateReference.partialStateReference.publicDataTree.nextAvailableLeafIndex)
);
fields[14] = bytes32(_header.globalVariables.chainId);
fields[15] = bytes32(_header.globalVariables.version);
fields[16] = bytes32(_header.globalVariables.blockNumber);
fields[17] = bytes32(_header.globalVariables.slotNumber);
fields[18] = bytes32(_header.globalVariables.timestamp);
fields[19] = bytes32(uint256(uint160(_header.globalVariables.coinbase)));
fields[20] = bytes32(_header.globalVariables.feeRecipient);
fields[21] = bytes32(_header.globalVariables.gasFees.feePerDaGas);
fields[22] = bytes32(_header.globalVariables.gasFees.feePerL2Gas);
fields[23] = bytes32(_header.totalFees);
fields[24] = bytes32(_header.totalManaUsed);
// fail if the header structure has changed without updating this function
require(
fields.length == Constants.HEADER_LENGTH,
Errors.HeaderLib__InvalidHeaderSize(Constants.HEADER_LENGTH, fields.length)
);

return fields;
}

// TODO(#7346): Currently using the below to verify block root proofs until batch rollups fully integrated.
// Once integrated, remove the below fn (not used anywhere else).
function toFields(GlobalVariables memory _globalVariables)
internal
pure
returns (bytes32[] memory)
{
bytes32[] memory fields = new bytes32[](Constants.GLOBAL_VARIABLES_LENGTH);

fields[0] = bytes32(_globalVariables.chainId);
fields[1] = bytes32(_globalVariables.version);
fields[2] = bytes32(_globalVariables.blockNumber);
fields[3] = bytes32(_globalVariables.slotNumber);
fields[4] = bytes32(_globalVariables.timestamp);
fields[5] = bytes32(uint256(uint160(_globalVariables.coinbase)));
fields[6] = bytes32(_globalVariables.feeRecipient);
fields[7] = bytes32(_globalVariables.gasFees.feePerDaGas);
fields[8] = bytes32(_globalVariables.gasFees.feePerL2Gas);

// fail if the header structure has changed without updating this function
// TODO(Miranda): Temporarily using this method and below error while block-root proofs are verified
// When we verify root proofs, this method can be removed => no need for separate named error
require(
fields.length == Constants.GLOBAL_VARIABLES_LENGTH,
Errors.HeaderLib__InvalidHeaderSize(Constants.HEADER_LENGTH, fields.length)
);

return fields;
}
}
Loading
Loading