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

update todos fix efficient calls #549

Merged
merged 12 commits into from
Jul 1, 2024
5 changes: 4 additions & 1 deletion da-contracts/contracts/RollupL1DAValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ contract RollupL1DAValidator is IL1DAValidator, CalldataDA {
return keccak256(abi.encodePacked(blobVersionedHash, _commitment[:PUBDATA_COMMITMENT_COMMITMENT_OFFSET]));
}

/// todo: better doc comments
/// @notice Verify that the blob DA was correctly provided.
/// @param _blobsProvided The number of blobs provided.
/// @param _maxBlobsSupported Maximum number of blobs supported.
/// @param _operatorDAInput Input used to verify that the blobs contain the data we expect.
function _processBlobDA(
uint256 _blobsProvided,
uint256 _maxBlobsSupported,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity 0.8.24;

import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";

/// @dev Enum used to determine the source of pubdata. At first we will support calldata and blobs but this can be extended.
enum PubdataSource {
Calldata,
Expand All @@ -22,7 +20,7 @@ struct L1DAValidatorOutput {
bytes32[] blobsOpeningCommitments;
}

interface IL1DAValidator is IERC165 {
interface IL1DAValidator {
/// @notice The function that checks the data availability for the given batch input.
/// @param chainId The chain id of the chain that is being committed.
/// @param l2DAValidatorOutputHash The hash of that was returned by the l2DAValidator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,4 @@ contract RelayedSLDAValidator is IL1DAValidator, CalldataDA {
);
}
}

function supportsInterface(bytes4 interfaceId) external view override returns (bool) {
return interfaceId == type(IL1DAValidator).interfaceId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {DiamondInit} from "contracts/state-transition/chain-deps/DiamondInit.sol
import {DiamondProxy} from "contracts/state-transition/chain-deps/DiamondProxy.sol";
import {VerifierParams, FeeParams, PubdataPricingMode} from "contracts/state-transition/chain-deps/ZkSyncHyperchainStorage.sol";
import {TestExecutor} from "contracts/dev-contracts/test/TestExecutor.sol";
import {ExecutorFacet} from "contracts/state-transition/chain-deps/facets/Executor.sol";
import {GettersFacet} from "contracts/state-transition/chain-deps/facets/Getters.sol";
import {AdminFacet} from "contracts/state-transition/chain-deps/facets/Admin.sol";
import {MailboxFacet} from "contracts/state-transition/chain-deps/facets/Mailbox.sol";
Expand Down
54 changes: 27 additions & 27 deletions system-contracts/SystemContractsHashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@
"contractName": "AccountCodeStorage",
"bytecodePath": "artifacts-zk/contracts-preprocessed/AccountCodeStorage.sol/AccountCodeStorage.json",
"sourceCodePath": "contracts-preprocessed/AccountCodeStorage.sol",
"bytecodeHash": "0x0100005d0b453ecf38e139e0dabe23b3478d640cb44421989769be6678e6124d",
"bytecodeHash": "0x0100005d43809646f388d9c4fc6367946f72bf210993cbab99dd620d2e8687a0",
"sourceCodeHash": "0x69d2533e5481ff13e65f4442e650f4b90c46a48ac643cac9798bbbf421194353"
},
{
"contractName": "BootloaderUtilities",
"bytecodePath": "artifacts-zk/contracts-preprocessed/BootloaderUtilities.sol/BootloaderUtilities.json",
"sourceCodePath": "contracts-preprocessed/BootloaderUtilities.sol",
"bytecodeHash": "0x010007c78c38350307112e6db2023bfc8695b8bc6f0ef8e18d4ffd45f2d2e727",
"bytecodeHash": "0x010007c7c30f1c5fffc3b02ff5158b3bed82582910deff1a7108a711ff3becc8",
"sourceCodeHash": "0x26060f33c7c63bd1f8a1a2f3b368b97ef8dd939bc53e95090f2c556248b99dce"
},
{
"contractName": "ComplexUpgrader",
"bytecodePath": "artifacts-zk/contracts-preprocessed/ComplexUpgrader.sol/ComplexUpgrader.json",
"sourceCodePath": "contracts-preprocessed/ComplexUpgrader.sol",
"bytecodeHash": "0x0100004d4f572f1d9c6aabae2b991b7a719bb360dffeb6df1c68a5d144cf39b3",
"bytecodeHash": "0x0100004d35653fb7a6689316431d054126a652517fda8473816c342e5066344e",
"sourceCodeHash": "0xdde7c49a94cc3cd34c3e7ced1b5ba45e4740df68d26243871edbe393e7298f7a"
},
{
"contractName": "Compressor",
"bytecodePath": "artifacts-zk/contracts-preprocessed/Compressor.sol/Compressor.json",
"sourceCodePath": "contracts-preprocessed/Compressor.sol",
"bytecodeHash": "0x0100013f1e1157a545197b40ded1ee3533f242988df9c8186e3a000f71a73f9f",
"bytecodeHash": "0x0100013f2fecc7cb115cd432d3dfd809f33ff0cdc497203ab4979dcaccd07051",
"sourceCodeHash": "0xb0cec0016f481ce023478f71727fbc0d82e967ddc0508e4d47f5c52292a3f790"
},
{
"contractName": "ContractDeployer",
"bytecodePath": "artifacts-zk/contracts-preprocessed/ContractDeployer.sol/ContractDeployer.json",
"sourceCodePath": "contracts-preprocessed/ContractDeployer.sol",
"bytecodeHash": "0x010004e558b2927988e0bb6233c8ee6e230b29be45949aa00ef131ef4f730950",
"bytecodeHash": "0x010004e50ff656731d9e621e2db0139cfd22345a433b2c98cf8e84b327bd280e",
"sourceCodeHash": "0x1657e45c2ff4d6a892afaf71dab71bb8dc7db2c6863e66240e83dfdd2535420d"
},
{
"contractName": "Create2Factory",
"bytecodePath": "artifacts-zk/contracts-preprocessed/Create2Factory.sol/Create2Factory.json",
"sourceCodePath": "contracts-preprocessed/Create2Factory.sol",
"bytecodeHash": "0x01000049dde67f20eeaae3f4c3c36e215dbbcf8d49b31fd51d6b2733acb09766",
"bytecodeHash": "0x0100004925bbd761afb2cc5badb3e215353641119fac0475ed9f82e4e4c9a03d",
"sourceCodeHash": "0x217e65f55c8add77982171da65e0db8cc10141ba75159af582973b332a4e098a"
},
{
"contractName": "DefaultAccount",
"bytecodePath": "artifacts-zk/contracts-preprocessed/DefaultAccount.sol/DefaultAccount.json",
"sourceCodePath": "contracts-preprocessed/DefaultAccount.sol",
"bytecodeHash": "0x0100055d1a120251ebdf8fd8d369d6b1002329b7dedae1f5a38fff9237460d4e",
"bytecodeHash": "0x0100055d16f15378f8338471eef7af52def45925e83f98affc0ee7883e34c494",
"sourceCodeHash": "0xeb5ac8fc83e1c8619db058a9b6973958bd6ed1b6f4938f8f4541d702f12e085d"
},
{
Expand All @@ -59,63 +59,63 @@
"contractName": "ImmutableSimulator",
"bytecodePath": "artifacts-zk/contracts-preprocessed/ImmutableSimulator.sol/ImmutableSimulator.json",
"sourceCodePath": "contracts-preprocessed/ImmutableSimulator.sol",
"bytecodeHash": "0x0100003b45050809a0c4f902e9ce2973192e579779681ec9e87da615261ddcc8",
"bytecodeHash": "0x0100003b391e787ed9314d60d5fe40a8f5337183572967f74b3aa2ecd0b493b4",
"sourceCodeHash": "0x4212e99cbc1722887cfb5b4cb967f278ac8642834786f0e3c6f3b324a9316815"
},
{
"contractName": "KnownCodesStorage",
"bytecodePath": "artifacts-zk/contracts-preprocessed/KnownCodesStorage.sol/KnownCodesStorage.json",
"sourceCodePath": "contracts-preprocessed/KnownCodesStorage.sol",
"bytecodeHash": "0x0100006f4dfe7289b377f7b199493be039bd9cda36fb612eaddfec8e2e41fc03",
"bytecodeHash": "0x0100006faf078bd81858a2386a00988442fbf245849a773968f33e2ba2edc3d5",
"sourceCodeHash": "0x8da495a9fc5aa0d7d20a165a4fc8bc77012bec29c472015ea5ecc0a2bd706137"
},
{
"contractName": "L1Messenger",
"bytecodePath": "artifacts-zk/contracts-preprocessed/L1Messenger.sol/L1Messenger.json",
"sourceCodePath": "contracts-preprocessed/L1Messenger.sol",
"bytecodeHash": "0x010001b9ed8fd23c0eade1a4becbf22bf916b91157a018466912a76a91c6058f",
"sourceCodeHash": "0x9fd8efda2bb59c7fec1e13985e8f164a4c7ccd6a02eaf62a267047864ae4297b"
"bytecodeHash": "0x010001c53022fe89a41df6c8238369b623fff572de264541156c100be5ae1aa9",
"sourceCodeHash": "0xd37126ed20e8a3b36afb28eccb2852c91c61d862129ff6676ad2506a96991fed"
},
{
"contractName": "L2BaseToken",
"bytecodePath": "artifacts-zk/contracts-preprocessed/L2BaseToken.sol/L2BaseToken.json",
"sourceCodePath": "contracts-preprocessed/L2BaseToken.sol",
"bytecodeHash": "0x01000105dce09804a12bb3783109121e79b36443d39d701f3398350b2631e6ae",
"bytecodeHash": "0x01000105abdfcf0b91f25f1e9b78792aa80c502f0ddd3eb7dc4ce1e6672c03d1",
"sourceCodeHash": "0x4cdafafd4cfdf410b31641e14487ea657be3af25e5ec1754fcd7ad67ec23d8be"
},
{
"contractName": "L2GenesisUpgrade",
"bytecodePath": "artifacts-zk/contracts-preprocessed/L2GenesisUpgrade.sol/L2GenesisUpgrade.json",
"sourceCodePath": "contracts-preprocessed/L2GenesisUpgrade.sol",
"bytecodeHash": "0x010000979a293f4433e682737cd65c856886788bd87b3ee932200beee96f8077",
"bytecodeHash": "0x010000972f98193a62c441b2bcad006aa6dcf362679e96d129ca3a21b517acdc",
"sourceCodeHash": "0xcb190d0dfd41bbc809409a8aa04a4847b86edfe010b1d75e23b4c8d07b13a9d0"
},
{
"contractName": "MsgValueSimulator",
"bytecodePath": "artifacts-zk/contracts-preprocessed/MsgValueSimulator.sol/MsgValueSimulator.json",
"sourceCodePath": "contracts-preprocessed/MsgValueSimulator.sol",
"bytecodeHash": "0x0100005dd3e075fc97739676f5351c69fcb3a52066c4fceafa06f4c11fd4b312",
"bytecodeHash": "0x0100005d15d05da21411eac146cc711e20f16d46d8099d165c6925f509458c47",
"sourceCodeHash": "0x4834adf62dbaefa1a1c15d36b5ad1bf2826e7d888a17be495f7ed4e4ea381aa8"
},
{
"contractName": "NonceHolder",
"bytecodePath": "artifacts-zk/contracts-preprocessed/NonceHolder.sol/NonceHolder.json",
"sourceCodePath": "contracts-preprocessed/NonceHolder.sol",
"bytecodeHash": "0x010000db91a9911aaf26bbec121a9a38956ee0ca61eb4a54c0f69917532c0c69",
"bytecodeHash": "0x010000dbecaf5124feced9df437daa0d3f6c4c7ea6d6b15654b66471043fac44",
"sourceCodeHash": "0xaa2ed3a26af30032c00a612ac327e0cdf5288b7c932ae903462355f863f950cb"
},
{
"contractName": "PubdataChunkPublisher",
"bytecodePath": "artifacts-zk/contracts-preprocessed/PubdataChunkPublisher.sol/PubdataChunkPublisher.json",
"sourceCodePath": "contracts-preprocessed/PubdataChunkPublisher.sol",
"bytecodeHash": "0x0100004b5ef5f37c229e7e3ea08ace485a8ed88e3577740d4681924942bc0db1",
"bytecodeHash": "0x0100004b3513ceb2387c75b634286c1b455859e30fff89050a656f535b03a371",
"sourceCodeHash": "0xc442fd1abb821c95e8229f4ef1575f789e89d60d1001489f5ac9250155cd11dc"
},
{
"contractName": "SystemContext",
"bytecodePath": "artifacts-zk/contracts-preprocessed/SystemContext.sol/SystemContext.json",
"sourceCodePath": "contracts-preprocessed/SystemContext.sol",
"bytecodeHash": "0x010001a7333a60831e6d722d217a61c0e8fb15f59a5e4889a95c43f814e9a7ce",
"bytecodeHash": "0x010001a7ac4d57eb2787575049763621c26ca6bec771e62f31fefcf34c3a50d8",
"sourceCodeHash": "0x532a962209042f948e8a13e3f4cf12b6d53631e0fc5fa53083c7e2d8062771c0"
},
{
Expand Down Expand Up @@ -185,35 +185,35 @@
"contractName": "bootloader_test",
"bytecodePath": "bootloader/build/artifacts/bootloader_test.yul.zbin",
"sourceCodePath": "bootloader/build/bootloader_test.yul",
"bytecodeHash": "0x010003cb32ddf442430c157f99f3c9e8bf1715bf5b730e5b66505f424aab870b",
"sourceCodeHash": "0x87b6c09b35653a3f7cbee20227a0c924833dc282024863e3e7cc788147831943"
"bytecodeHash": "0x010003cbbc8703410736ad54cccbed76ec542c222d22735187462e2b2543ca44",
"sourceCodeHash": "0xd09753d165f94039e78cb65baa2b533d07a48074e88570264fa542684486add4"
},
{
"contractName": "fee_estimate",
"bytecodePath": "bootloader/build/artifacts/fee_estimate.yul.zbin",
"sourceCodePath": "bootloader/build/fee_estimate.yul",
"bytecodeHash": "0x0100095522aa28c47c12ba2318be9f81f71953d4ac428f4b350c1a60d0d7ad52",
"sourceCodeHash": "0xf19e13eba2e5f5b5807de44129e955eb59d4da81df22814c4f14e9629e40956e"
"bytecodeHash": "0x010009550b7a3b047282957bfa3f57eed7afbfd14d9dccf91510e1f4ea8ae165",
"sourceCodeHash": "0x7819f3afb78430870f281842efa6abab20f4e98d358ed384293b78f6a5b308cc"
},
{
"contractName": "gas_test",
"bytecodePath": "bootloader/build/artifacts/gas_test.yul.zbin",
"sourceCodePath": "bootloader/build/gas_test.yul",
"bytecodeHash": "0x010008db638bea3362928963e1068be05bd67e4bb06929f5929e3d0a2c17a453",
"sourceCodeHash": "0xb9f35f0173e38fee1c65e828b5832e4ef16b64d750f6d79462f9a8875fb7e257"
"bytecodeHash": "0x010008db393295170e205eaa4ca5b997a6dd834ffc0b0f266f60c08d39c791e6",
"sourceCodeHash": "0x5fd9a9801ce058ffa87d53c74b10bb90cfa54d0619695d1be103752fd7ef47aa"
},
{
"contractName": "playground_batch",
"bytecodePath": "bootloader/build/artifacts/playground_batch.yul.zbin",
"sourceCodePath": "bootloader/build/playground_batch.yul",
"bytecodeHash": "0x0100095b811d15001bb78cae07dc7cfa4a5f064e7d01ce40c82bf23433ee7c37",
"sourceCodeHash": "0xb007d4e3029cf6facf08a04e8e25648ede7b64fb6ebf1889a8dd073c3c5d83ad"
"bytecodeHash": "0x0100095b4ba8dc5c753f6861739349c9564ec4f7d0c43df61c2c62f7d3a1aee9",
"sourceCodeHash": "0x5efcab1bc35d122095dda9ed8451822b294708e9eb44951722b7b61241a94e4f"
},
{
"contractName": "proved_batch",
"bytecodePath": "bootloader/build/artifacts/proved_batch.yul.zbin",
"sourceCodePath": "bootloader/build/proved_batch.yul",
"bytecodeHash": "0x010008eb8627da94d891c5897c1e7764ec5f85fd263efaa7712e6b92352ae96a",
"sourceCodeHash": "0xf1242ca88d9c28c691dac72eed89279cf8f520d2356ccf1ce1f9402580374eca"
"bytecodeHash": "0x010008eb9b3415d2b039a95d4e356f75fe0abcba9568b782194a04eaadaf0a7f",
"sourceCodeHash": "0xdd1eb343ed49ce908047f18e9e7a668b34bd27e291125fc44c28c1dcf94277fa"
}
]
70 changes: 62 additions & 8 deletions system-contracts/contracts/L1Messenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,56 @@ contract L1Messenger is IL1Messenger, ISystemContract {
) external onlyCallFromBootloader {
uint256 calldataPtr = 0;

// Check function sig and data in the other hashes
// 4 + 32 + 32 + 32 + 32 + 32 + 32
// 4 bytes for L2 DA Validator `validatePubdata` function selector
// 32 bytes for rolling hash of user L2 -> L1 logs
// 32 bytes for root hash of user L2 -> L1 logs
// 32 bytes for hash of messages
// 32 bytes for hash of uncompressed bytecodes sent to L1
// Operator data: 32 bytes for offset
// 32 bytes for length

bytes4 inputL2DAValidatePubdataFunctionSig = bytes4(
_totalL2ToL1PubdataAndStateDiffs[calldataPtr:calldataPtr + 4]
);
if (inputL2DAValidatePubdataFunctionSig != IL2DAValidator.validatePubdata.selector) {
revert ReconstructionMismatch(
PubdataField.InputDAFunctionSig,
bytes32(IL2DAValidator.validatePubdata.selector),
bytes32(inputL2DAValidatePubdataFunctionSig)
);
}
calldataPtr += 4;

bytes32 inputChainedLogsHash = bytes32(_totalL2ToL1PubdataAndStateDiffs[calldataPtr:calldataPtr + 32]);
if (inputChainedLogsHash != chainedLogsHash) {
revert ReconstructionMismatch(PubdataField.InputLogsHash, chainedLogsHash, inputChainedLogsHash);
}
calldataPtr += 32;

// Check happens below after we reconstruct the logs root hash
bytes32 inputChainedLogsRootHash = bytes32(_totalL2ToL1PubdataAndStateDiffs[calldataPtr:calldataPtr + 32]);
calldataPtr += 32;

bytes32 inputChainedMsgsHash = bytes32(_totalL2ToL1PubdataAndStateDiffs[calldataPtr:calldataPtr + 32]);
if (inputChainedMsgsHash != chainedMessagesHash) {
revert ReconstructionMismatch(PubdataField.InputMsgsHash, chainedMessagesHash, inputChainedMsgsHash);
}
calldataPtr += 32;

bytes32 inputChainedBytecodesHash = bytes32(_totalL2ToL1PubdataAndStateDiffs[calldataPtr:calldataPtr + 32]);
if (inputChainedBytecodesHash != chainedL1BytecodesRevealDataHash) {
revert ReconstructionMismatch(
PubdataField.InputBytecodeHash,
chainedL1BytecodesRevealDataHash,
inputChainedBytecodesHash
);
}
calldataPtr += 32;
// Shift calldata ptr past the pubdata offset and len
calldataPtr += 64;

/// Check logs
uint32 numberOfL2ToL1Logs = uint32(bytes4(_totalL2ToL1PubdataAndStateDiffs[calldataPtr:calldataPtr + 4]));
if (numberOfL2ToL1Logs > L2_TO_L1_LOGS_MERKLE_TREE_LEAVES) {
Expand Down Expand Up @@ -237,16 +287,20 @@ contract L1Messenger is IL1Messenger, ISystemContract {
}
bytes32 l2ToL1LogsTreeRoot = l2ToL1LogsTreeArray[0];

// FIXME; this is inefficient and leads to copying the entire array of uncompressed state diffs
// Better to use efficient call
bytes32 l2DAValidatorOutputhash = IL2DAValidator(_l2DAValidator).validatePubdata({
_chainedLogsHash: chainedLogsHash,
_logsRootHash: l2ToL1LogsTreeRoot,
_chainedMessagesHash: chainedMessagesHash,
_chainedBytescodesHash: chainedL1BytecodesRevealDataHash,
_operatorInput: _totalL2ToL1PubdataAndStateDiffs
if (inputChainedLogsRootHash != l2ToL1LogsTreeRoot) {
revert ReconstructionMismatch(PubdataField.InputLogsRootHash, l2ToL1LogsTreeRoot, inputChainedLogsRootHash);
}

bytes memory returnData = EfficientCall.call({
_gas: gasleft(),
_address: _l2DAValidator,
_value: 0,
_data: _totalL2ToL1PubdataAndStateDiffs,
_isSystem: false
});

bytes32 l2DAValidatorOutputhash = abi.decode(returnData, (bytes32));

/// Native (VM) L2 to L1 log
SystemContractHelper.toL1(true, bytes32(uint256(SystemLogKey.L2_TO_L1_LOGS_TREE_ROOT_KEY)), l2ToL1LogsTreeRoot);
SystemContractHelper.toL1(
Expand Down
7 changes: 6 additions & 1 deletion system-contracts/contracts/SystemContractErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ enum PubdataField {
MsgHash,
Bytecode,
StateDiffCompressionVersion,
ExtraData
ExtraData,
InputDAFunctionSig,
InputLogsHash,
InputLogsRootHash,
InputMsgsHash,
InputBytecodeHash
}

enum BytecodeError {
Expand Down
Loading