Verified contractPartialMIT
EraChainTypeManager
Address0xe642b64ac222503573ffbebfbd7bb7f072c99ef7
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 9,999,999 runs
- EVM version
- prague
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,378,190
- Creation transaction
- 0x087d522567…f55d378cbe
83 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/state-transition/EraChainTypeManager.solmain2.53 KB
- ../system-contracts/contracts/Constants.sol10.57 KB
- contracts/bridge/asset-router/IAssetRouterBase.sol1.39 KB
- contracts/bridge/asset-router/IL1AssetRouter.sol9 KB
- contracts/bridge/asset-router/IL2AssetRouter.sol1.59 KB
- contracts/bridge/asset-tracker/IGWAssetTracker.sol8.5 KB
- contracts/bridge/asset-tracker/IL1AssetTracker.sol3.34 KB
- contracts/bridge/asset-tracker/IL2AssetTracker.sol2.59 KB
- contracts/bridge/interfaces/IAssetHandler.sol2.27 KB
- contracts/bridge/interfaces/IL1AssetDeploymentTracker.sol375 B
- contracts/bridge/interfaces/IL1CrossChainSender.sol1.91 KB
- contracts/bridge/interfaces/IL1ERC20Bridge.sol2.75 KB
- contracts/bridge/interfaces/IL1Nullifier.sol6.78 KB
- contracts/bridge/interfaces/IL1SharedBridgeLegacy.sol291 B
- contracts/bridge/interfaces/IL2CrossChainSender.sol1.64 KB
- contracts/bridge/ntv/IL1NativeTokenVault.sol1.55 KB
- contracts/bridge/ntv/IL2NativeTokenVault.sol1.07 KB
- contracts/bridge/ntv/INativeTokenVaultBase.sol2.17 KB
- contracts/common/Config.sol18.45 KB
- contracts/common/L1ContractErrors.sol14.84 KB
- contracts/common/Messaging.sol21.68 KB
- contracts/common/ReentrancyGuard.sol4.06 KB
- contracts/common/interfaces/IL2ContractDeployer.sol2.65 KB
- contracts/common/interfaces/IMessageVerification.sol4.59 KB
- contracts/common/interfaces/ISystemContext.sol2.77 KB
- contracts/common/l2-helpers/IBaseToken.sol1.26 KB
- contracts/common/l2-helpers/IL2ToL1MessengerEra.sol3.01 KB
- contracts/common/l2-helpers/L2ContractAddresses.sol8.1 KB
- contracts/common/l2-helpers/L2ContractHelper.sol11.32 KB
- contracts/common/l2-helpers/L2ContractInterfaces.sol4.62 KB
- contracts/common/libraries/DynamicIncrementalMerkle.sol7.04 KB
- contracts/common/libraries/Merkle.sol5.88 KB
- contracts/common/libraries/SemVer.sol2.14 KB
- contracts/common/libraries/UncheckedMath.sol671 B
- contracts/core/bridgehub/IBridgehubBase.sol6.56 KB
- contracts/core/bridgehub/IL1Bridgehub.sol1.94 KB
- contracts/core/chain-asset-handler/IChainAssetHandler.sol3.67 KB
- contracts/core/ctm-deployment/ICTMDeploymentTracker.sol729 B
- contracts/core/message-root/IMessageRoot.sol4.47 KB
- contracts/interop/IInteropCenter.sol8.29 KB
- contracts/interop/IInteropHandler.sol2.56 KB
- contracts/interop/IL2InteropRootStorage.sol595 B
- contracts/l2-system/interfaces/IBaseTokenHolder.sol3.41 KB
- contracts/state-transition/ChainTypeManagerBase.sol36.99 KB
- contracts/state-transition/IChainTypeManager.sol9.02 KB
- contracts/state-transition/L1StateTransitionErrors.sol3.9 KB
- contracts/state-transition/chain-deps/DiamondProxy.sol2.86 KB
- contracts/state-transition/chain-deps/StoredBatchHashing.sol2.31 KB
- contracts/state-transition/chain-deps/ZKChainStorage.sol15.03 KB
- contracts/state-transition/chain-deps/facets/ZKChainBase.sol15.54 KB
- contracts/state-transition/chain-interfaces/IAdmin.sol10.81 KB
- contracts/state-transition/chain-interfaces/IChainUpgrader.sol1.09 KB
- contracts/state-transition/chain-interfaces/ICommitter.sol8.36 KB
- contracts/state-transition/chain-interfaces/IDiamondInit.sol1.83 KB
- contracts/state-transition/chain-interfaces/IExecutor.sol10.6 KB
- contracts/state-transition/chain-interfaces/IGetters.sol10.68 KB
- contracts/state-transition/chain-interfaces/IMailbox.sol790 B
- contracts/state-transition/chain-interfaces/IMailboxImpl.sol8.95 KB
- contracts/state-transition/chain-interfaces/IMailboxLegacy.sol3.61 KB
- contracts/state-transition/chain-interfaces/IMigrator.sol2.44 KB
- contracts/state-transition/chain-interfaces/IVerifier.sol1.18 KB
- contracts/state-transition/chain-interfaces/IZKChain.sol811 B
- contracts/state-transition/chain-interfaces/IZKChainBase.sol507 B
- contracts/state-transition/libraries/Diamond.sol15.39 KB
- contracts/state-transition/libraries/PriorityQueue.sol3.85 KB
- contracts/state-transition/libraries/PriorityTree.sol7.72 KB
- contracts/state-transition/libraries/ProposedUpgradeLib.sol3.64 KB
- contracts/state-transition/libraries/TransactionValidator.sol11.59 KB
- contracts/upgrades/BaseZkSyncUpgrade.sol17.39 KB
- contracts/upgrades/IDefaultUpgrade.sol320 B
- contracts/upgrades/ZkSyncUpgradeErrors.sol1.25 KB
- lib/openzeppelin-contracts-upgradeable-v4/contracts/access/Ownable2StepUpgradeable.sol2.54 KB
- lib/openzeppelin-contracts-upgradeable-v4/contracts/access/OwnableUpgradeable.sol3.17 KB
- lib/openzeppelin-contracts-upgradeable-v4/contracts/proxy/utils/Initializable.sol6.64 KB
- lib/openzeppelin-contracts-upgradeable-v4/contracts/utils/AddressUpgradeable.sol9.38 KB
- lib/openzeppelin-contracts-upgradeable-v4/contracts/utils/ContextUpgradeable.sol1.48 KB
- lib/openzeppelin-contracts-v4/contracts/token/ERC20/IERC20.sol2.74 KB
- lib/openzeppelin-contracts-v4/contracts/utils/Arrays.sol3.97 KB
- lib/openzeppelin-contracts-v4/contracts/utils/StorageSlot.sol4.11 KB
- lib/openzeppelin-contracts-v4/contracts/utils/math/Math.sol12.79 KB
- lib/openzeppelin-contracts-v4/contracts/utils/math/SafeCast.sol35.08 KB
- lib/openzeppelin-contracts-v4/contracts/utils/structs/EnumerableMap.sol21.33 KB
- lib/openzeppelin-contracts-v4/contracts/utils/structs/EnumerableSet.sol12.96 KB
contracts/state-transition/libraries/TransactionValidator.sol
// SPDX-License-Identifier: MIT
// We use a floating point pragma here so it can be used within other projects that interact with the ZKsync ecosystem without using our exact pragma version.
pragma solidity ^0.8.21;
import {Math} from "@openzeppelin/contracts-v4/utils/math/Math.sol";
import {L2CanonicalTransaction} from "../../common/Messaging.sol";
import {
L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS,
L1_TX_DELTA_544_ENCODING_BYTES,
L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
L1_TX_DELTA_FACTORY_DEPS_PUBDATA,
L1_TX_INTRINSIC_L2_GAS,
L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS,
L1_TX_INTRINSIC_PUBDATA,
L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS,
L1_TX_MIN_L2_GAS_BASE,
MEMORY_OVERHEAD_GAS,
TX_SLOT_OVERHEAD_L2_GAS,
L1_TX_NATIVE_PER_GAS,
MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS
} from "../../common/Config.sol";
import {
InvalidUpgradeTxn,
PubdataGreaterThanLimit,
TooMuchGas,
TxnBodyGasLimitNotEnoughGas,
UpgradeTxVerifyParam,
ValidateTxnNotEnoughGas
} from "../../common/L1ContractErrors.sol";
/// @title ZKsync Library for validating L1 -> L2 transactions
/// @author Matter Labs
/// @custom:security-contact [email protected]
library TransactionValidator {
/// @dev Used to validate key properties of an L1->L2 transaction
/// @param _transaction The transaction to validate
/// @param _encoded The abi encoded bytes of the transaction
/// @param _priorityTxMaxGasLimit The max gas limit, generally provided from Storage.sol
/// @param _priorityTxMaxPubdata The maximal amount of pubdata that a single L1->L2 transaction can emit
/// @param zksyncOS ZKsync OS state transition flag
function validateL1ToL2Transaction(
L2CanonicalTransaction memory _transaction,
bytes memory _encoded,
uint256 _priorityTxMaxGasLimit,
uint256 _priorityTxMaxPubdata,
bool zksyncOS
) internal pure {
uint256 l2GasForTxBody = getTransactionBodyGasLimit(_transaction.gasLimit, _encoded.length, zksyncOS);
// Ensuring that the transaction is provable
if (l2GasForTxBody > _priorityTxMaxGasLimit) {
revert TooMuchGas();
}
// Ensuring that the transaction cannot output more pubdata than is processable
if (l2GasForTxBody / _transaction.gasPerPubdataByteLimit > _priorityTxMaxPubdata) {
revert PubdataGreaterThanLimit(_priorityTxMaxPubdata, l2GasForTxBody / _transaction.gasPerPubdataByteLimit);
}
// Ensuring that the transaction covers the minimal costs for its processing:
// hashing its content, publishing the factory dependencies, etc.
if (
// solhint-disable-next-line func-named-parameters
getMinimalPriorityTransactionGasLimit(
_encoded.length,
_transaction.data.length,
_transaction.factoryDeps.length,
_transaction.gasPerPubdataByteLimit,
zksyncOS
) > l2GasForTxBody
) {
revert ValidateTxnNotEnoughGas();
}
}
/// @dev Used to validate upgrade transactions
/// @param _transaction The transaction to validate
function validateUpgradeTransaction(L2CanonicalTransaction memory _transaction) internal pure {
// Restrict from to be within system contract range (0...2^16 - 1)
if (_transaction.from > type(uint16).max) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.From);
}
if (_transaction.to > type(uint160).max) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.To);
}
if (_transaction.paymaster != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.Paymaster);
}
if (_transaction.value != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.Value);
}
if (_transaction.maxFeePerGas != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.MaxFeePerGas);
}
if (_transaction.maxPriorityFeePerGas != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.MaxPriorityFeePerGas);
}
if (_transaction.reserved[0] != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.Reserved0);
}
if (_transaction.reserved[1] > type(uint160).max) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.Reserved1);
}
if (_transaction.reserved[2] != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.Reserved2);
}
if (_transaction.reserved[3] != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.Reserved3);
}
if (_transaction.signature.length != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.Signature);
}
if (_transaction.paymasterInput.length != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.PaymasterInput);
}
if (_transaction.reservedDynamic.length != 0) {
revert InvalidUpgradeTxn(UpgradeTxVerifyParam.ReservedDynamic);
}
}
/// @dev Calculates the approximate minimum gas limit required for executing a priority transaction.
/// @param _encodingLength The length of the priority transaction encoding in bytes.
/// @param _numberOfFactoryDependencies The number of new factory dependencies that will be added.
/// @param _l2GasPricePerPubdata The L2 gas price for publishing the priority transaction on L2.
/// @param zksyncOS ZKsync OS state transition flag
/// @return The minimum gas limit required to execute the priority transaction.
/// Note: The calculation includes the main cost of the priority transaction, however, in reality, the operator can spend a little more gas on overheads.
function getMinimalPriorityTransactionGasLimit(
uint256 _encodingLength,
uint256 _calldataLength,
uint256 _numberOfFactoryDependencies,
uint256 _l2GasPricePerPubdata,
bool zksyncOS
) internal pure returns (uint256) {
if (zksyncOS) {
// Due to double account resources model in zksync os, we need to calculate 2 things for minimal gas limit:
// 1. Intrinsic tx cost in gas
// 2. Intrinsic tx cost in native resources
// And then take the bigger value
// 1. Intrinsic tx cost in gas
uint256 intrinsicGasCost = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS;
// we are overcharging using floor non-zero byte cost to cover the worst case
intrinsicGasCost += L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * _calldataLength;
// 2. Intrinsic tx cost in native resources
// Since we are using huge `L1_TX_NATIVE_PER_GAS` ratio, it mostly consists of pubdata cost.
uint256 intrinsicPubdataGasCost = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * _l2GasPricePerPubdata;
// And because of huge ratio, we are overestimating using `MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS`.
// Actual intrinsic cost is much lower, but even with `MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS`
// it will be around 343 gas and overestimate makes code safer and easier to support
uint256 gasForIntrinsicNative = intrinsicPubdataGasCost +
Math.ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
return Math.max(intrinsicGasCost, gasForIntrinsicNative);
} else {
uint256 costForComputation;
{
// Adding the intrinsic cost for the transaction, i.e. auxiliary prices which cannot be easily accounted for
costForComputation = L1_TX_INTRINSIC_L2_GAS;
// Taking into account the hashing costs that depend on the length of the transaction
// Note that L1_TX_DELTA_544_ENCODING_BYTES is the delta in the price for every 544 bytes of
// the transaction's encoding. It is taken as LCM between 136 and 32 (the length for each keccak256 round
// and the size of each new encoding word).
costForComputation += Math.ceilDiv(_encodingLength * L1_TX_DELTA_544_ENCODING_BYTES, 544);
// Taking into the account the additional costs of providing new factory dependencies
costForComputation += _numberOfFactoryDependencies * L1_TX_DELTA_FACTORY_DEPS_L2_GAS;
// There is a minimal amount of computational L2 gas that the transaction should cover
costForComputation = Math.max(costForComputation, L1_TX_MIN_L2_GAS_BASE);
}
uint256 costForPubdata = 0;
{
// Adding the intrinsic cost for the transaction, i.e. auxiliary prices which cannot be easily accounted for
costForPubdata = L1_TX_INTRINSIC_PUBDATA * _l2GasPricePerPubdata;
// Taking into the account the additional costs of providing new factory dependencies
costForPubdata +=
_numberOfFactoryDependencies *
L1_TX_DELTA_FACTORY_DEPS_PUBDATA *
_l2GasPricePerPubdata;
}
return costForComputation + costForPubdata;
}
}
/// @notice Based on the full L2 gas limit (that includes the batch overhead) and other
/// properties of the transaction, returns the l2GasLimit for the body of the transaction (the actual execution).
/// @param _totalGasLimit The L2 gas limit that includes both the overhead for processing the batch
/// and the L2 gas needed to process the transaction itself (i.e. the actual l2GasLimit that will be used for the transaction).
/// @param _encodingLength The length of the ABI-encoding of the transaction.
/// @param zksyncOS ZKsync OS state transition flag
function getTransactionBodyGasLimit(
uint256 _totalGasLimit,
uint256 _encodingLength,
bool zksyncOS
) internal pure returns (uint256 txBodyGasLimit) {
// There is no overhead in ZKsync OS
if (zksyncOS) {
return _totalGasLimit;
}
uint256 overhead = getOverheadForTransaction(_encodingLength);
// provided gas limit doesn't cover transaction overhead
if (_totalGasLimit < overhead) {
revert TxnBodyGasLimitNotEnoughGas();
}
unchecked {
// We enforce the fact that `_totalGasLimit >= overhead` explicitly above.
txBodyGasLimit = _totalGasLimit - overhead;
}
}
/// @notice Based on the total L2 gas limit and several other parameters of the transaction
/// returns the part of the L2 gas that will be spent on the batch's overhead.
/// @dev The details of how this function works can be checked in the documentation
/// of the fee model of ZKsync. The appropriate comments are also present
/// in the Rust implementation description of function `get_maximal_allowed_overhead`.
/// @param _encodingLength The length of the binary encoding of the transaction in bytes
function getOverheadForTransaction(
uint256 _encodingLength
) internal pure returns (uint256 batchOverheadForTransaction) {
// The overhead from taking up the transaction's slot
batchOverheadForTransaction = TX_SLOT_OVERHEAD_L2_GAS;
// The overhead for occupying the bootloader memory can be derived from encoded_len
uint256 overheadForLength = MEMORY_OVERHEAD_GAS * _encodingLength;
batchOverheadForTransaction = Math.max(batchOverheadForTransaction, overheadForLength);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 9999999,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"@ensdomains/=node_modules/@ensdomains/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"eth-gas-reporter/=node_modules/eth-gas-reporter/",
"forge-std/=lib/forge-std/src/",
"hardhat/=node_modules/hardhat/",
"murky/=lib/murky/src/",
"foundry-test/=test/foundry/",
"l2-contracts/=../l2-contracts/contracts/",
"system-contracts/=../system-contracts/",
"@openzeppelin/contracts-v4/=lib/openzeppelin-contracts-v4/contracts/",
"@openzeppelin/contracts-upgradeable-v4/=lib/openzeppelin-contracts-upgradeable-v4/contracts/",
"test-utils/=test/foundry/l1/integration/utils/",
"openzeppelin-contracts-upgradeable-v4/=lib/openzeppelin-contracts-upgradeable-v4/",
"openzeppelin-contracts-v4/=lib/openzeppelin-contracts-v4/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.