Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
596 changes: 298 additions & 298 deletions AllContractsHashes.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions l1-contracts/contracts/common/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,9 @@ enum L2DACommitmentScheme {

/// @dev The L2 data availability commitment scheme that permanent rollups are expected to use.
L2DACommitmentScheme constant ROLLUP_L2_DA_COMMITMENT_SCHEME = L2DACommitmentScheme.BLOBS_AND_PUBDATA_KECCAK256;

/// @dev Minimal allowed code size limit, equals to EVM EIP-170 value.
uint32 constant MIN_CODE_SIZE_LIMIT = 0x6000;

/// @dev Maximal allowed code size limit, 1 MB.
uint32 constant MAX_CODE_SIZE_LIMIT = 0x100000;
6 changes: 6 additions & 0 deletions l1-contracts/contracts/common/L1ContractErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ error IncorrectBatchBounds(
);
// 0xc1b4bc7b
error IncorrectBatchChainId(uint256, uint256);
// 0x55424854
error IncorrectBatchCodeSizeLimit(uint32, uint32);
// 0xdd381a4c
error IncorrectBridgeHubAddress(address bridgehub);
// 0x1929b7de
Expand Down Expand Up @@ -408,6 +410,10 @@ error ZeroGasPriceL1TxZKsyncOS();
error ZKChainLimitReached();
// 0x646ac57e
error ZKsyncOSNotForceDeployForExistingContract(address);
// 0xbcfe4b69
error CodeSizeLimitTooLow(uint32 codeSizeLimit, uint32 minCodeSizeLimit);
// 0x47386ac7
error CodeSizeLimitTooBig(uint32 codeSizeLimit, uint32 maxCodeSizeLimit);

enum SharedBridgeKey {
PostUpgradeFirstBatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ abstract contract ChainTypeManagerBase is IChainTypeManager, ReentrancyGuard, Ow

// construct init data
bytes memory initData;
/// all together 4+9*32=292 bytes for the selector + mandatory data
// It consists from chain specific part and general part(which is same for all the chains and it's fixed as part of `initialCutHash`)
// all together 4+8*32=260 bytes for the selector and chain specific part + general part
// solhint-disable-next-line func-named-parameters
initData = bytes.concat(
IDiamondInit.initialize.selector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.28;

import {Diamond} from "../libraries/Diamond.sol";
import {ZKChainBase} from "./facets/ZKChainBase.sol";
import {L2_TO_L1_LOG_SERIALIZE_SIZE, MAX_GAS_PER_TRANSACTION, DEFAULT_PRECOMMITMENT_FOR_THE_LAST_BATCH} from "../../common/Config.sol";
import {L2_TO_L1_LOG_SERIALIZE_SIZE, MAX_GAS_PER_TRANSACTION, DEFAULT_PRECOMMITMENT_FOR_THE_LAST_BATCH, MIN_CODE_SIZE_LIMIT} from "../../common/Config.sol";
import {IDiamondInit, InitializeData} from "../chain-interfaces/IDiamondInit.sol";
import {PriorityQueue} from "../libraries/PriorityQueue.sol";
import {PriorityTree} from "../libraries/PriorityTree.sol";
Expand Down Expand Up @@ -84,6 +84,8 @@ contract DiamondInit is ZKChainBase, IDiamondInit {
s.priorityTree.setup(s.__DEPRECATED_priorityQueue.getTotalPriorityTxs());
s.precommitmentForTheLatestBatch = DEFAULT_PRECOMMITMENT_FOR_THE_LAST_BATCH;
s.zksyncOS = IS_ZKSYNC_OS;
// by default we set code size limit to minimal(EVM) value, can be changed later by admin.
s.codeSizeLimit = MIN_CODE_SIZE_LIMIT;

// While this does not provide a protection in the production, it is needed for local testing
// Length of the L2Log encoding should not be equal to the length of other L2Logs' tree nodes preimages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,6 @@ struct ZKChainStorage {
bool zksyncOS;
/// @dev The scheme of L2 DA commitment. Different L1 validators may use different schemes.
L2DACommitmentScheme l2DACommitmentScheme;
/// @dev The code size limit. Used ONLY for ZKsync OS, ignored for Era VM.
uint32 codeSizeLimit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {IL1Bridgehub} from "../../../bridgehub/IL1Bridgehub.sol";
import {ZKChainBase} from "./ZKChainBase.sol";
import {IChainTypeManager} from "../../IChainTypeManager.sol";
import {IL1GenesisUpgrade} from "../../../upgrades/IL1GenesisUpgrade.sol";
import {AlreadyPermanentRollup, DenominatorIsZero, DiamondAlreadyFrozen, DiamondNotFrozen, HashMismatch, InvalidDAForPermanentRollup, InvalidPubdataPricingMode, PriorityTxPubdataExceedsMaxPubDataPerBatch, NotAZKChain, ProtocolIdMismatch, ProtocolIdNotGreater, TooMuchGas, Unauthorized, InvalidL2DACommitmentScheme} from "../../../common/L1ContractErrors.sol";
import {AlreadyPermanentRollup, DenominatorIsZero, DiamondAlreadyFrozen, DiamondNotFrozen, HashMismatch, InvalidDAForPermanentRollup, InvalidPubdataPricingMode, PriorityTxPubdataExceedsMaxPubDataPerBatch, NotAZKChain, ProtocolIdMismatch, ProtocolIdNotGreater, TooMuchGas, Unauthorized, InvalidL2DACommitmentScheme, CodeSizeLimitTooLow, CodeSizeLimitTooBig} from "../../../common/L1ContractErrors.sol";
import {AlreadyMigrated, ContractNotDeployed, ExecutedIsNotConsistentWithVerified, InvalidNumberOfBatchHashes, L1DAValidatorAddressIsZero, NotAllBatchesExecuted, NotChainAdmin, NotEraChain, NotHistoricalRoot, NotL1, NotMigrated, OutdatedProtocolVersion, ProtocolVersionNotUpToDate, VerifiedIsNotConsistentWithCommitted} from "../../L1StateTransitionErrors.sol";
import {RollupDAManager} from "../../data-availability/RollupDAManager.sol";
import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR} from "../../../common/l2-helpers/L2ContractAddresses.sol";
import {AllowedBytecodeTypes, IL2ContractDeployer} from "../../../common/interfaces/IL2ContractDeployer.sol";
import {L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS} from "../../../common/Config.sol";
import {L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS, MIN_CODE_SIZE_LIMIT, MAX_CODE_SIZE_LIMIT} from "../../../common/Config.sol";

// While formally the following import is not used, it is needed to inherit documentation from it
import {IZKChainBase} from "../../chain-interfaces/IZKChainBase.sol";
Expand Down Expand Up @@ -207,6 +207,17 @@ contract AdminFacet is ZKChainBase, IAdmin {
emit EnableEvmEmulator();
}

/// @inheritdoc IAdmin
function setCodeSizeLimit(uint32 _codeSizeLimit) external onlyAdmin {
if (_codeSizeLimit < MIN_CODE_SIZE_LIMIT) {
revert CodeSizeLimitTooLow(_codeSizeLimit, MIN_CODE_SIZE_LIMIT);
}
if (_codeSizeLimit > MAX_CODE_SIZE_LIMIT) {
revert CodeSizeLimitTooBig(_codeSizeLimit, MAX_CODE_SIZE_LIMIT);
}
s.codeSizeLimit = _codeSizeLimit;
Copy link
Member

Choose a reason for hiding this comment

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

Please always add events for functions that change the config on smart contract. It is the easiest way to monitor the smart contract.

}

/*//////////////////////////////////////////////////////////////
UPGRADE EXECUTION
//////////////////////////////////////////////////////////////*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {L2_BOOTLOADER_ADDRESS, L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR, L2_TO_L1_
import {IChainTypeManager} from "../../IChainTypeManager.sol";
import {PriorityOpsBatchInfo, PriorityTree} from "../../libraries/PriorityTree.sol";
import {IL1DAValidator, L1DAValidatorOutput} from "../../chain-interfaces/IL1DAValidator.sol";
import {IncorrectBatchChainId, BatchHashMismatch, BatchNumberMismatch, CanOnlyProcessOneBatch, CantExecuteUnprovenBatches, CantRevertExecutedBatch, HashMismatch, InvalidLogSender, InvalidMessageRoot, InvalidNumberOfBlobs, InvalidProof, InvalidProtocolVersion, InvalidSystemLogsLength, L2TimestampTooBig, LogAlreadyProcessed, MissingSystemLogs, NonIncreasingTimestamp, NonSequentialBatch, PriorityOperationsRollingHashMismatch, RevertedBatchNotAfterNewLastBatch, SystemLogsSizeTooBig, TimeNotReached, TimestampError, TxHashMismatch, UnexpectedSystemLog, UpgradeBatchNumberIsNotZero, ValueMismatch, VerifiedBatchesExceedsCommittedBatches, InvalidBatchNumber, EmptyPrecommitData, PrecommitmentMismatch, InvalidPackedPrecommitmentLength, NonZeroBlobToVerifyZKsyncOS, InvalidBlockRange} from "../../../common/L1ContractErrors.sol";
import {IncorrectBatchChainId, IncorrectBatchCodeSizeLimit, BatchHashMismatch, BatchNumberMismatch, CanOnlyProcessOneBatch, CantExecuteUnprovenBatches, CantRevertExecutedBatch, HashMismatch, InvalidLogSender, InvalidMessageRoot, InvalidNumberOfBlobs, InvalidProof, InvalidProtocolVersion, InvalidSystemLogsLength, L2TimestampTooBig, LogAlreadyProcessed, MissingSystemLogs, NonIncreasingTimestamp, NonSequentialBatch, PriorityOperationsRollingHashMismatch, RevertedBatchNotAfterNewLastBatch, SystemLogsSizeTooBig, TimeNotReached, TimestampError, TxHashMismatch, UnexpectedSystemLog, UpgradeBatchNumberIsNotZero, ValueMismatch, VerifiedBatchesExceedsCommittedBatches, InvalidBatchNumber, EmptyPrecommitData, PrecommitmentMismatch, InvalidPackedPrecommitmentLength, NonZeroBlobToVerifyZKsyncOS, InvalidBlockRange} from "../../../common/L1ContractErrors.sol";
import {CommitBasedInteropNotSupported, DependencyRootsRollingHashMismatch, InvalidBatchesDataLength, MessageRootIsZero, MismatchNumberOfLayer1Txs, MismatchL2DACommitmentScheme} from "../../L1StateTransitionErrors.sol";

// While formally the following import is not used, it is needed to inherit documentation from it
Expand Down Expand Up @@ -193,6 +193,9 @@ contract ExecutorFacet is ZKChainBase, IExecutor {
if (_newBatch.chainId != s.chainId) {
revert IncorrectBatchChainId(_newBatch.chainId, s.chainId);
}
if (_newBatch.codeSizeLimit != s.codeSizeLimit) {
revert IncorrectBatchCodeSizeLimit(_newBatch.codeSizeLimit, s.codeSizeLimit);
Comment on lines +196 to +197

Choose a reason for hiding this comment

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

P1 Badge Initialize codeSizeLimit on upgrade

For existing ZKsync OS chains that upgrade to this code, s.codeSizeLimit will default to zero because the new storage slot is appended and DiamondInit only runs on fresh deployments. The new equality check in Executor._commitOneBatchZKsyncOS (_newBatch.codeSizeLimit != s.codeSizeLimit) will therefore revert for any commit that uses the normal EIP‑170 limit (0x6000), effectively halting batch commits until an admin explicitly calls setCodeSizeLimit. If upgrades are expected to be seamless, this needs an initialization/migration path or a safe fallback when s.codeSizeLimit == 0.

Useful? React with 👍 / 👎.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@AntonD3 the comment is correct

}
if (_newBatch.daCommitmentScheme != s.l2DACommitmentScheme) {
revert MismatchL2DACommitmentScheme(uint256(_newBatch.daCommitmentScheme), uint256(s.l2DACommitmentScheme));
}
Expand All @@ -203,6 +206,7 @@ contract ExecutorFacet is ZKChainBase, IExecutor {
bytes32 batchOutputHash = keccak256(
abi.encodePacked(
_newBatch.chainId,
_newBatch.codeSizeLimit,
_newBatch.firstBlockTimestamp,
_newBatch.lastBlockTimestamp,
uint256(_newBatch.daCommitmentScheme),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ contract GettersFacet is ZKChainBase, IGetters, ILegacyGetters {
return (s.l1DAValidator, s.l2DACommitmentScheme);
}

/// @inheritdoc IGetters
function getCodeSizeLimit() external view returns (uint32) {
return s.codeSizeLimit;
}

/*//////////////////////////////////////////////////////////////
DIAMOND LOUPE
//////////////////////////////////////////////////////////////*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ interface IAdmin is IZKChainBase {
/// @notice Allow EVM emulation on chain
function allowEvmEmulation() external returns (bytes32 canonicalTxHash);

/// @notice set contracts code size limit for the chain
function setCodeSizeLimit(uint32 _codeSizeLimit) external;

/// @notice Perform the upgrade from the current protocol version with the corresponding upgrade data
/// @param _protocolVersion The current protocol version from which upgrade is executed
/// @param _cutData The diamond cut parameters that is executed in the upgrade
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.21;
import {IVerifier, VerifierParams} from "./IVerifier.sol";
import {FeeParams} from "../chain-deps/ZKChainStorage.sol";

/// @dev Chain initialization data
/// @param chainId the id of the chain
/// @param bridgehub the address of the bridgehub contract
/// @param chainTypeManager contract's address
Expand Down Expand Up @@ -39,6 +40,7 @@ struct InitializeData {
FeeParams feeParams;
}

/// @dev General part of the chain initialize data, this part of data is same for all chains.
/// @param verifier address of Verifier contract
/// @param verifierParams Verifier config parameters that describes the circuit to be verified
/// @param l2BootloaderBytecodeHash The hash of bootloader L2 bytecode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,16 @@ interface IExecutor is IZKChainBase {
/// (state root, block number, bloch hashes)
/// @param numberOfLayer1Txs Number of priority operations to be processed
/// @param priorityOperationsHash Hash of all priority operations from this batch
/// @param dependencyRootsRollingHash Hash of imported dependency interop roots
/// @param l2LogsTreeRoot Root hash of tree that contains L2 -> L1 messages from this batch
/// @param daCommitmentScheme commitment scheme used to generate pubdata commitment for this batch
/// @param daCommitment commitment to the batch pubdata to validate DA in the l1 da validator
/// @param firstBlockTimestamp timestamp of the first block in the batch
/// @param firstBlockNumber number of the first block in the batch
/// @param lastBlockTimestamp timestamp of the last block in the batch
/// @param lastBlockNumber number of the last block in the batch
/// @param chainId chain id used during batch execution
/// @param codeSizeLimit code size limit used during batch execution
// solhint-disable-next-line gas-struct-packing
struct CommitBatchInfoZKsyncOS {
uint64 batchNumber;
Expand All @@ -152,6 +159,7 @@ interface IExecutor is IZKChainBase {
uint64 lastBlockTimestamp;
uint64 lastBlockNumber;
uint256 chainId;
uint32 codeSizeLimit;
bytes operatorDAInput;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ interface IGetters is IZKChainBase {

/// @return DA configuration.
function getDAValidatorPair() external view returns (address, L2DACommitmentScheme);

/// @return codeSizeLimit chain contract size limit.
function getCodeSizeLimit() external view returns (uint32);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ library BatchDecoder {
uint8 internal constant SUPPORTED_ENCODING_VERSION = 1;
/// @notice The currently supported encoding version for ZKSync OS commit data.
/// We use different encoding only for commit, while prove/execute are common for Era VM and ZKsync OS chains.
uint8 internal constant SUPPORTED_ENCODING_VERSION_COMMIT_ZKSYNC_OS = 3;
uint8 internal constant SUPPORTED_ENCODING_VERSION_COMMIT_ZKSYNC_OS = 4;

/// @notice Decodes commit data from a calldata bytes into the last committed batch data and an array of new batch data.
/// @param _commitData The calldata byte array containing the data for committing batches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ contract ExecutorTest is Test {
lastBlockTimestamp: uint64(currentTimestamp),
lastBlockNumber: uint64(2),
chainId: l2ChainId,
operatorDAInput: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
operatorDAInput: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
codeSizeLimit: 0x6000
});

dummyBridgehub.setZKChain(l2ChainId, address(diamondProxy));
Expand Down
Loading