Skip to content

Commit

Permalink
Merge 23ca079 into 46e2af6
Browse files Browse the repository at this point in the history
  • Loading branch information
MirandaWood authored Nov 14, 2024
2 parents 46e2af6 + 23ca079 commit 7b42e8c
Show file tree
Hide file tree
Showing 101 changed files with 1,232 additions and 607 deletions.
16 changes: 9 additions & 7 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ library Constants {
uint256 internal constant MAX_NOTE_ENCRYPTED_LOGS_PER_CALL = 16;
uint256 internal constant MAX_ENCRYPTED_LOGS_PER_CALL = 4;
uint256 internal constant MAX_UNENCRYPTED_LOGS_PER_CALL = 4;
uint256 internal constant MAX_CONTRACT_CLASS_LOGS_PER_CALL = 1;
uint256 internal constant ARCHIVE_HEIGHT = 29;
uint256 internal constant VK_TREE_HEIGHT = 6;
uint256 internal constant PROTOCOL_CONTRACT_TREE_HEIGHT = 3;
Expand Down Expand Up @@ -70,6 +71,7 @@ library Constants {
uint256 internal constant MAX_NOTE_ENCRYPTED_LOGS_PER_TX = 64;
uint256 internal constant MAX_ENCRYPTED_LOGS_PER_TX = 8;
uint256 internal constant MAX_UNENCRYPTED_LOGS_PER_TX = 8;
uint256 internal constant MAX_CONTRACT_CLASS_LOGS_PER_TX = 1;
uint256 internal constant MAX_PUBLIC_DATA_HINTS = 128;
uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
uint256 internal constant EMPTY_NESTED_INDEX = 0;
Expand Down Expand Up @@ -202,7 +204,7 @@ library Constants {
uint256 internal constant TX_REQUEST_LENGTH = 12;
uint256 internal constant TOTAL_FEES_LENGTH = 1;
uint256 internal constant HEADER_LENGTH = 24;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 499;
uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 490;
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 866;
uint256 internal constant PRIVATE_CONTEXT_INPUTS_LENGTH = 37;
uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = 41;
Expand All @@ -214,20 +216,20 @@ library Constants {
uint256 internal constant NUM_PUBLIC_VALIDATION_REQUEST_ARRAYS = 5;
uint256 internal constant PUBLIC_VALIDATION_REQUESTS_LENGTH = 834;
uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 3;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 545;
uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 550;
uint256 internal constant TX_CONSTANT_DATA_LENGTH = 34;
uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 43;
uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1064;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1877;
uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1036;
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1849;
uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 1023;
uint256 internal constant NUM_PUBLIC_ACCUMULATED_DATA_ARRAYS = 8;
uint256 internal constant PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH = 576;
uint256 internal constant PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH = 548;
uint256 internal constant PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH = 160;
uint256 internal constant NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3;
uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1196;
uint256 internal constant PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1140;
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2931;
uint256 internal constant VM_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2340;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 600;
uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 605;
uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 13;
uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 30;
uint256 internal constant BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 90;
Expand Down
68 changes: 51 additions & 17 deletions l1-contracts/src/core/libraries/TxsDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ library TxsDecoder {
uint256 noteEncryptedLogsLength;
uint256 encryptedLogsLength;
uint256 unencryptedLogsLength;
uint256 contractClassLogsLength;
}

struct Counts {
Expand All @@ -72,9 +73,11 @@ library TxsDecoder {
uint256 kernelNoteEncryptedLogsLength;
uint256 kernelEncryptedLogsLength;
uint256 kernelUnencryptedLogsLength;
uint256 kernelContractClassLogsLength;
bytes32 noteEncryptedLogsHash;
bytes32 encryptedLogsHash;
bytes32 unencryptedLogsHash;
bytes32 contractClassLogsHash;
bytes32 txOutHash;
}

Expand Down Expand Up @@ -166,8 +169,12 @@ library TxsDecoder {
offsets.unencryptedLogsLength = offset;
offset += 0x20;

// CONTRACT CLASS LOGS LENGTH
offsets.contractClassLogsLength = offset;
offset += 0x20;

/**
* Compute note, encrypted and unencrypted logs hashes corresponding to the current leaf.
* Compute note, encrypted, unencrypted, and contract class logs hashes corresponding to the current leaf.
* Note: will advance offsets by the number of bytes processed.
*/
// NOTE ENCRYPTED LOGS HASH
Expand All @@ -178,7 +185,11 @@ library TxsDecoder {
computeKernelEncryptedLogsHash(offset, _body);
// UNENCRYPTED LOGS HASH
(vars.unencryptedLogsHash, offset, vars.kernelUnencryptedLogsLength) =
computeKernelUnencryptedLogsHash(offset, _body);
computeKernelUnencryptedLogsHash(offset, _body, false);
// CONTRACT CLASS LOGS HASH
// Note: the logic for unenc. and contract class logs hashing is the same:
(vars.contractClassLogsHash, offset, vars.kernelContractClassLogsLength) =
computeKernelUnencryptedLogsHash(offset, _body, true);
// TX LEVEL OUT HASH
(vars.txOutHash) = computeTxOutHash(offsets.l2ToL1Msgs, _body);

Expand Down Expand Up @@ -208,6 +219,14 @@ library TxsDecoder {
vars.kernelUnencryptedLogsLength
)
);
require(
uint256(bytes32(slice(_body, offsets.contractClassLogsLength, 0x20)))
== vars.kernelContractClassLogsLength,
Errors.TxsDecoder__InvalidLogsLength(
uint256(bytes32(slice(_body, offsets.contractClassLogsLength, 0x20))),
vars.kernelContractClassLogsLength
)
);

// Insertions are split into multiple `bytes.concat` to work around stack too deep.
vars.baseLeaf = bytes.concat(
Expand Down Expand Up @@ -239,10 +258,18 @@ library TxsDecoder {
),
bytes.concat(
slice(_body, offsets.noteEncryptedLogsLength, 0x20),
slice(_body, offsets.encryptedLogsLength, 0x20),
slice(_body, offsets.unencryptedLogsLength, 0x20)
slice(_body, offsets.encryptedLogsLength, 0x20)
),
bytes.concat(
slice(_body, offsets.unencryptedLogsLength, 0x20),
slice(_body, offsets.contractClassLogsLength, 0x20)
),
bytes.concat(vars.noteEncryptedLogsHash, vars.encryptedLogsHash, vars.unencryptedLogsHash)
bytes.concat(
vars.noteEncryptedLogsHash,
vars.encryptedLogsHash,
vars.unencryptedLogsHash,
vars.contractClassLogsHash
)
);

vars.baseLeaves[i] = Hash.sha256ToField(vars.baseLeaf);
Expand All @@ -251,7 +278,7 @@ library TxsDecoder {
// We pad base leaves with hashes of empty tx effect.
for (uint256 i = numTxEffects; i < vars.baseLeaves.length; i++) {
// Value taken from tx_effect.test.ts "hash of empty tx effect matches snapshot" test case
vars.baseLeaves[i] = hex"00f0aa51fc81f8242316fcf2cb3b28196241ed3fa26dd320a959bce6c529b270";
vars.baseLeaves[i] = hex"00c2dece9c9f14c67b8aafabdcb80793f1cffe95a801e15d648fd214a0522ee8";
}
}

Expand Down Expand Up @@ -421,18 +448,18 @@ library TxsDecoder {
}

/**
* @notice Computes unencrypted logs hash as is done in the kernel circuits.
* @notice Computes unencrypted or contract class logs hash as is done in the kernel circuits.
* @param _offsetInBlock - The offset of kernel's logs in a block.
* @param _body - The L2 block calldata.
* @return The hash of the logs and offset in a block after processing the logs.
* @dev See above for details. The only difference here is that unencrypted logs are
* @dev See above for details. The only difference here is that unencrypted and contract class logs are
* siloed with their contract address.
*/
function computeKernelUnencryptedLogsHash(uint256 _offsetInBlock, bytes calldata _body)
internal
pure
returns (bytes32, uint256, uint256)
{
function computeKernelUnencryptedLogsHash(
uint256 _offsetInBlock,
bytes calldata _body,
bool _contractClassLogs
) internal pure returns (bytes32, uint256, uint256) {
uint256 offset = _offsetInBlock;
uint256 remainingLogsLength = read4(_body, offset);
uint256 kernelLogsLength = remainingLogsLength;
Expand Down Expand Up @@ -473,10 +500,17 @@ library TxsDecoder {
}

// padded to MAX_LOGS * 32 bytes
flattenedLogHashes = bytes.concat(
flattenedLogHashes,
new bytes(Constants.MAX_UNENCRYPTED_LOGS_PER_TX * 32 - flattenedLogHashes.length)
);
if (_contractClassLogs) {
flattenedLogHashes = bytes.concat(
flattenedLogHashes,
new bytes(Constants.MAX_CONTRACT_CLASS_LOGS_PER_TX * 32 - flattenedLogHashes.length)
);
} else {
flattenedLogHashes = bytes.concat(
flattenedLogHashes,
new bytes(Constants.MAX_UNENCRYPTED_LOGS_PER_TX * 32 - flattenedLogHashes.length)
);
}

bytes32 kernelPublicInputsLogsHash = Hash.sha256ToField(flattenedLogHashes);

Expand Down
18 changes: 9 additions & 9 deletions l1-contracts/test/fixtures/empty_block_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x01c96319c544c46399dcc0f48c344210ae5bf846507a202512d3aaa4768aad7f",
"blockHash": "0x1e273844400064424f4b091fd7944446a32bb7a96d8bf69a05e32f01a1a40cde",
"archive": "0x1f80d0f24457c066a8b752a2c424ee0c8bd61143db120fa0841d0f4233f7e21d",
"blockHash": "0x267f79fe7e757b20e924fac9f78264a0d1c8c4b481fea21d0bbe74650d87a1f1",
"body": "0x00000000",
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
"txsEffectsHash": "0x002dcd61493c9a7f3ce4605573ee657e6ced4a3dd10bfb216f44a796b3d585c9",
"decodedHeader": {
"contentCommitment": {
"inHash": "0x00089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c",
"outHash": "0x00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb",
"numTxs": 2,
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6"
"txsEffectsHash": "0x002dcd61493c9a7f3ce4605573ee657e6ced4a3dd10bfb216f44a796b3d585c9"
},
"globalVariables": {
"blockNumber": 1,
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000012",
"chainId": 31337,
"timestamp": 1731107199,
"timestamp": 1731434785,
"version": 1,
"coinbase": "0x8a914126f71d7c294a01833665b9a9019347d6a2",
"feeRecipient": "0x1d2bd70d60e15b1148d6c5590d5ed3dd0427419f862ee389b12abf25481ffd26",
"coinbase": "0x4f6cd865d580ac0011a4776d8dc51db519c2318a",
"feeRecipient": "0x1ae8b5e1d9882013ea5271b1e71b307bc48c191549588587a227c8a118834864",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
Expand Down Expand Up @@ -57,8 +57,8 @@
}
}
},
"header": "0x2a05cb8aeefe9b9797f90650eae072f5ab7437807e62f9724ce190046777986000000001000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6000000101fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb000000800c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d6390730000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000672e997f8a914126f71d7c294a01833665b9a9019347d6a21d2bd70d60e15b1148d6c5590d5ed3dd0427419f862ee389b12abf25481ffd26000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00fc461dff8a8b9e2397bb5d40053b87281dd9fd28e77834a2749bfc5f32bfb9",
"header": "0x2a05cb8aeefe9b9797f90650eae072f5ab7437807e62f9724ce1900467779860000000010000000000000000000000000000000000000000000000000000000000000002002dcd61493c9a7f3ce4605573ee657e6ced4a3dd10bfb216f44a796b3d585c900089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6000000101fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb000000800c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d6390730000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000673399214f6cd865d580ac0011a4776d8dc51db519c2318a1ae8b5e1d9882013ea5271b1e71b307bc48c191549588587a227c8a118834864000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00f45c9ec73df38136aa1fed90362a5df796817e37a36d02df4700f80bc356b2",
"numTxs": 0
}
}
20 changes: 10 additions & 10 deletions l1-contracts/test/fixtures/empty_block_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x19b0447418d0e86728db9266ecf57b26b3e4a47388c4241e16f5f9e4b2d20492",
"blockHash": "0x07effa5ee44661e8167d238e02729e739543aa4cfbf619878850a440e021ce72",
"archive": "0x1120ec22c3dd3dd6904b9520f086189726776a41c75c53f8f4cea4a53bc45844",
"blockHash": "0x2d48eea4aa6c13eea47df326e22cd76e74ecc24ee272d6b4207eb5f494f891d3",
"body": "0x00000000",
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
"txsEffectsHash": "0x002dcd61493c9a7f3ce4605573ee657e6ced4a3dd10bfb216f44a796b3d585c9",
"decodedHeader": {
"contentCommitment": {
"inHash": "0x00089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c",
"outHash": "0x00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb",
"numTxs": 2,
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6"
"txsEffectsHash": "0x002dcd61493c9a7f3ce4605573ee657e6ced4a3dd10bfb216f44a796b3d585c9"
},
"globalVariables": {
"blockNumber": 2,
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000013",
"chainId": 31337,
"timestamp": 1731107223,
"timestamp": 1731434809,
"version": 1,
"coinbase": "0x8a914126f71d7c294a01833665b9a9019347d6a2",
"feeRecipient": "0x1d2bd70d60e15b1148d6c5590d5ed3dd0427419f862ee389b12abf25481ffd26",
"coinbase": "0x4f6cd865d580ac0011a4776d8dc51db519c2318a",
"feeRecipient": "0x1ae8b5e1d9882013ea5271b1e71b307bc48c191549588587a227c8a118834864",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
}
},
"lastArchive": {
"nextAvailableLeafIndex": 2,
"root": "0x01c96319c544c46399dcc0f48c344210ae5bf846507a202512d3aaa4768aad7f"
"root": "0x1f80d0f24457c066a8b752a2c424ee0c8bd61143db120fa0841d0f4233f7e21d"
},
"stateReference": {
"l1ToL2MessageTree": {
Expand All @@ -57,8 +57,8 @@
}
}
},
"header": "0x01c96319c544c46399dcc0f48c344210ae5bf846507a202512d3aaa4768aad7f00000002000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6000000201fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb000001000c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d6390730000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001300000000000000000000000000000000000000000000000000000000672e99978a914126f71d7c294a01833665b9a9019347d6a21d2bd70d60e15b1148d6c5590d5ed3dd0427419f862ee389b12abf25481ffd26000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x006d28d243077e67b4570884f2b6d0b30aba890a326b21308690d5f279e47ab9",
"header": "0x1f80d0f24457c066a8b752a2c424ee0c8bd61143db120fa0841d0f4233f7e21d000000020000000000000000000000000000000000000000000000000000000000000002002dcd61493c9a7f3ce4605573ee657e6ced4a3dd10bfb216f44a796b3d585c900089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6000000201fd848aa69e1633722fe249a5b7f53b094f1c9cef9f5c694b073fd1cc5850dfb000001000c499b373a1f0fe1b510a63563546d2d39e206895056a5af0143c5f30d6390730000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a6900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001300000000000000000000000000000000000000000000000000000000673399394f6cd865d580ac0011a4776d8dc51db519c2318a1ae8b5e1d9882013ea5271b1e71b307bc48c191549588587a227c8a118834864000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x0050ad1c615efe79df6f8ed137584b719b7043725a87ff1b1e2a29f22f0827c8",
"numTxs": 0
}
}
20 changes: 10 additions & 10 deletions l1-contracts/test/fixtures/mixed_block_1.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions l1-contracts/test/fixtures/mixed_block_2.json

Large diffs are not rendered by default.

Loading

0 comments on commit 7b42e8c

Please sign in to comment.