Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Latest 25 from a total of 30 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Send To L1 | 4765814 | 57 days ago | IN | 0 ETH | 0.00000266 | ||||
Send To L1 | 4765808 | 57 days ago | IN | 0 ETH | 0.00000461 | ||||
Send To L1 | 4139873 | 162 days ago | IN | 0 ETH | 0.00000315 | ||||
Send To L1 | 4139858 | 162 days ago | IN | 0 ETH | 0.00000314 | ||||
Send To L1 | 4139854 | 162 days ago | IN | 0 ETH | 0.00000358 | ||||
Send To L1 | 3736528 | 225 days ago | IN | 0 ETH | 0.00016964 | ||||
Send To L1 | 3736176 | 225 days ago | IN | 0 ETH | 0.00022942 | ||||
Send To L1 | 3714435 | 229 days ago | IN | 0 ETH | 0.00003548 | ||||
Send To L1 | 3714425 | 229 days ago | IN | 0 ETH | 0.00003983 | ||||
Send To L1 | 3415212 | 278 days ago | IN | 0 ETH | 0.00000305 | ||||
Send To L1 | 2623539 | 323 days ago | IN | 0 ETH | 0.0001061 | ||||
Send To L1 | 2610857 | 324 days ago | IN | 0 ETH | 0.00002418 | ||||
Send To L1 | 2610183 | 324 days ago | IN | 0 ETH | 0.00001186 | ||||
Send To L1 | 2610177 | 324 days ago | IN | 0 ETH | 0.00001186 | ||||
Send To L1 | 2610148 | 324 days ago | IN | 0 ETH | 0.0000136 | ||||
Send To L1 | 2607469 | 324 days ago | IN | 0 ETH | 0.00001124 | ||||
Send To L1 | 2607467 | 324 days ago | IN | 0 ETH | 0.00001123 | ||||
Send To L1 | 2607449 | 324 days ago | IN | 0 ETH | 0.00001124 | ||||
Send To L1 | 2607311 | 324 days ago | IN | 0 ETH | 0.00001123 | ||||
Send To L1 | 2607248 | 324 days ago | IN | 0 ETH | 0.00001288 | ||||
Send To L1 | 2112145 | 349 days ago | IN | 0 ETH | 0.00001396 | ||||
Send To L1 | 2107307 | 349 days ago | IN | 0 ETH | 0.00002292 | ||||
Send To L1 | 1323862 | 390 days ago | IN | 0 ETH | 0.00001442 | ||||
Send To L1 | 1323710 | 390 days ago | IN | 0 ETH | 0.00001442 | ||||
Send To L1 | 1323665 | 390 days ago | IN | 0 ETH | 0.00001652 |
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
L1Messenger
Compiler Version
v0.8.24-1.0.1
ZkSolc Version
v1.5.7
Optimization Enabled:
Yes with Mode 3
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; import {IL1Messenger, L2ToL1Log, L2_L1_LOGS_TREE_DEFAULT_LEAF_HASH, L2_TO_L1_LOG_SERIALIZE_SIZE} from "./interfaces/IL1Messenger.sol"; import {SystemContractBase} from "./abstract/SystemContractBase.sol"; import {SystemContractHelper} from "./libraries/SystemContractHelper.sol"; import {EfficientCall} from "./libraries/EfficientCall.sol"; import {Utils} from "./libraries/Utils.sol"; import {SystemLogKey, SYSTEM_CONTEXT_CONTRACT, KNOWN_CODE_STORAGE_CONTRACT, L2_TO_L1_LOGS_MERKLE_TREE_LEAVES, COMPUTATIONAL_PRICE_FOR_PUBDATA, L2_MESSAGE_ROOT} from "./Constants.sol"; import {ReconstructionMismatch, PubdataField} from "./SystemContractErrors.sol"; import {IL2DAValidator} from "./interfaces/IL2DAValidator.sol"; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice Smart contract for sending arbitrary length messages to L1 * @dev by default ZkSync can send fixed length messages on L1. * A fixed length message has 4 parameters `senderAddress` `isService`, `key`, `value`, * the first one is taken from the context, the other three are chosen by the sender. * @dev To send a variable length message we use this trick: * - This system contract accepts a arbitrary length message and sends a fixed length message with * parameters `senderAddress == this`, `marker == true`, `key == msg.sender`, `value == keccak256(message)`. * - The contract on L1 accepts all sent messages and if the message came from this system contract * it requires that the preimage of `value` be provided. */ contract L1Messenger is IL1Messenger, SystemContractBase { /// @notice Sequential hash of logs sent in the current block. /// @dev Will be reset at the end of the block to zero value. bytes32 internal chainedLogsHash; /// @notice Number of logs sent in the current block. /// @dev Will be reset at the end of the block to zero value. uint256 internal numberOfLogsToProcess; /// @notice Sequential hash of hashes of the messages sent in the current block. /// @dev Will be reset at the end of the block to zero value. bytes32 internal chainedMessagesHash; /// @notice Sequential hash of bytecode hashes that needs to published /// according to the current block execution invariant. /// @dev Will be reset at the end of the block to zero value. bytes32 internal chainedL1BytecodesRevealDataHash; /// The gas cost of processing one keccak256 round. uint256 internal constant KECCAK_ROUND_GAS_COST = 40; /// The number of bytes processed in one keccak256 round. uint256 internal constant KECCAK_ROUND_NUMBER_OF_BYTES = 136; /// The gas cost of calculation of keccak256 of bytes array of such length. function keccakGasCost(uint256 _length) internal pure returns (uint256) { return KECCAK_ROUND_GAS_COST * (_length / KECCAK_ROUND_NUMBER_OF_BYTES + 1); } /// The gas cost of processing one sha256 round. uint256 internal constant SHA256_ROUND_GAS_COST = 7; /// The number of bytes processed in one sha256 round. uint256 internal constant SHA256_ROUND_NUMBER_OF_BYTES = 64; /// The gas cost of calculation of sha256 of bytes array of such length. function sha256GasCost(uint256 _length) internal pure returns (uint256) { return SHA256_ROUND_GAS_COST * ((_length + 8) / SHA256_ROUND_NUMBER_OF_BYTES + 1); } /// @notice Sends L2ToL1Log. /// @param _isService The `isService` flag. /// @param _key The `key` part of the L2Log. /// @param _value The `value` part of the L2Log. /// @dev Can be called only by a system contract. function sendL2ToL1Log( bool _isService, bytes32 _key, bytes32 _value ) external onlyCallFromSystemContract returns (uint256 logIdInMerkleTree) { L2ToL1Log memory l2ToL1Log = L2ToL1Log({ l2ShardId: 0, isService: _isService, txNumberInBlock: SYSTEM_CONTEXT_CONTRACT.txNumberInBlock(), sender: msg.sender, key: _key, value: _value }); logIdInMerkleTree = _processL2ToL1Log(l2ToL1Log); // We need to charge cost of hashing, as it will be used in `publishPubdataAndClearState`: // - keccakGasCost(L2_TO_L1_LOG_SERIALIZE_SIZE) and keccakGasCost(64) when reconstructing L2ToL1Log // - at most 1 time keccakGasCost(64) when building the Merkle tree (as merkle tree can contain // ~2*N nodes, where the first N nodes are leaves the hash of which is calculated on the previous step). uint256 gasToPay = keccakGasCost(L2_TO_L1_LOG_SERIALIZE_SIZE) + 2 * keccakGasCost(64); SystemContractHelper.burnGas(Utils.safeCastToU32(gasToPay), uint32(L2_TO_L1_LOG_SERIALIZE_SIZE)); } /// @notice Internal function to send L2ToL1Log. function _processL2ToL1Log(L2ToL1Log memory _l2ToL1Log) internal returns (uint256 logIdInMerkleTree) { bytes32 hashedLog = keccak256( // solhint-disable-next-line func-named-parameters abi.encodePacked( _l2ToL1Log.l2ShardId, _l2ToL1Log.isService, _l2ToL1Log.txNumberInBlock, _l2ToL1Log.sender, _l2ToL1Log.key, _l2ToL1Log.value ) ); chainedLogsHash = keccak256(abi.encode(chainedLogsHash, hashedLog)); logIdInMerkleTree = numberOfLogsToProcess; ++numberOfLogsToProcess; emit L2ToL1LogSent(_l2ToL1Log); } /// @notice Public functionality to send messages to L1. /// @param _message The message intended to be sent to L1. function sendToL1(bytes calldata _message) external override returns (bytes32 hash) { uint256 gasBeforeMessageHashing = gasleft(); hash = EfficientCall.keccak(_message); uint256 gasSpentOnMessageHashing = gasBeforeMessageHashing - gasleft(); /// Store message record chainedMessagesHash = keccak256(abi.encode(chainedMessagesHash, hash)); /// Store log record L2ToL1Log memory l2ToL1Log = L2ToL1Log({ l2ShardId: 0, isService: true, txNumberInBlock: SYSTEM_CONTEXT_CONTRACT.txNumberInBlock(), sender: address(this), key: bytes32(uint256(uint160(msg.sender))), value: hash }); _processL2ToL1Log(l2ToL1Log); uint256 pubdataLen; unchecked { // 4 bytes used to encode the length of the message (see `publishPubdataAndClearState`) // L2_TO_L1_LOG_SERIALIZE_SIZE bytes used to encode L2ToL1Log pubdataLen = 4 + _message.length + L2_TO_L1_LOG_SERIALIZE_SIZE; } // We need to charge cost of hashing, as it will be used in `publishPubdataAndClearState`: // - keccakGasCost(L2_TO_L1_LOG_SERIALIZE_SIZE) and keccakGasCost(64) when reconstructing L2ToL1Log // - keccakGasCost(64) and gasSpentOnMessageHashing when reconstructing Messages // - at most 1 time keccakGasCost(64) when building the Merkle tree (as merkle tree can contain // ~2*N nodes, where the first N nodes are leaves the hash of which is calculated on the previous step). uint256 gasToPay = keccakGasCost(L2_TO_L1_LOG_SERIALIZE_SIZE) + 3 * keccakGasCost(64) + gasSpentOnMessageHashing + COMPUTATIONAL_PRICE_FOR_PUBDATA * pubdataLen; SystemContractHelper.burnGas(Utils.safeCastToU32(gasToPay), uint32(pubdataLen)); emit L1MessageSent(msg.sender, hash, _message); } /// @dev Can be called only by KnownCodesStorage system contract. /// @param _bytecodeHash Hash of bytecode being published to L1. function requestBytecodeL1Publication( bytes32 _bytecodeHash ) external override onlyCallFrom(address(KNOWN_CODE_STORAGE_CONTRACT)) { chainedL1BytecodesRevealDataHash = keccak256(abi.encode(chainedL1BytecodesRevealDataHash, _bytecodeHash)); uint256 bytecodeLen = Utils.bytecodeLenInBytes(_bytecodeHash); uint256 pubdataLen; unchecked { // 4 bytes used to encode the length of the bytecode (see `publishPubdataAndClearState`) pubdataLen = 4 + bytecodeLen; } // We need to charge cost of hashing, as it will be used in `publishPubdataAndClearState` uint256 gasToPay = sha256GasCost(bytecodeLen) + keccakGasCost(64) + COMPUTATIONAL_PRICE_FOR_PUBDATA * pubdataLen; SystemContractHelper.burnGas(Utils.safeCastToU32(gasToPay), uint32(pubdataLen)); emit BytecodeL1PublicationRequested(_bytecodeHash); } /// @notice Verifies that the {_operatorInput} reflects what occurred within the L1Batch and that /// the compressed statediffs are equivalent to the full state diffs. /// @param _l2DAValidator the address of the l2 da validator /// @param _operatorInput The total pubdata and uncompressed state diffs of transactions that were /// processed in the current L1 Batch. Pubdata consists of L2 to L1 Logs, messages, deployed bytecode, and state diffs. /// @dev Function that should be called exactly once per L1 Batch by the bootloader. /// @dev Checks that totalL2ToL1Pubdata is strictly packed data that should to be published to L1. /// @dev The data passed in also contains the encoded state diffs to be checked again, however this is aux data that is not /// part of the committed pubdata. /// @dev Performs calculation of L2ToL1Logs merkle tree root, "sends" such root and keccak256(totalL2ToL1Pubdata) /// to L1 using low-level (VM) L2Log. function publishPubdataAndClearState( address _l2DAValidator, bytes calldata _operatorInput ) 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(_operatorInput[calldataPtr:calldataPtr + 4]); if (inputL2DAValidatePubdataFunctionSig != IL2DAValidator.validatePubdata.selector) { revert ReconstructionMismatch( PubdataField.InputDAFunctionSig, bytes32(IL2DAValidator.validatePubdata.selector), bytes32(inputL2DAValidatePubdataFunctionSig) ); } calldataPtr += 4; bytes32 inputChainedLogsHash = bytes32(_operatorInput[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(_operatorInput[calldataPtr:calldataPtr + 32]); calldataPtr += 32; bytes32 inputChainedMsgsHash = bytes32(_operatorInput[calldataPtr:calldataPtr + 32]); if (inputChainedMsgsHash != chainedMessagesHash) { revert ReconstructionMismatch(PubdataField.InputMsgsHash, chainedMessagesHash, inputChainedMsgsHash); } calldataPtr += 32; bytes32 inputChainedBytecodesHash = bytes32(_operatorInput[calldataPtr:calldataPtr + 32]); if (inputChainedBytecodesHash != chainedL1BytecodesRevealDataHash) { revert ReconstructionMismatch( PubdataField.InputBytecodeHash, chainedL1BytecodesRevealDataHash, inputChainedBytecodesHash ); } calldataPtr += 32; uint256 offset = uint256(bytes32(_operatorInput[calldataPtr:calldataPtr + 32])); // The length of the pubdata input should be stored right next to the calldata. // We need to change offset by 32 - 4 = 28 bytes, since 32 bytes is the length of the offset // itself and the 4 bytes are the selector which is not included inside the offset. if (offset != calldataPtr + 28) { revert ReconstructionMismatch(PubdataField.Offset, bytes32(calldataPtr + 28), bytes32(offset)); } uint256 length = uint256(bytes32(_operatorInput[calldataPtr + 32:calldataPtr + 64])); // Shift calldata ptr past the pubdata offset and len calldataPtr += 64; /// Check logs uint32 numberOfL2ToL1Logs = uint32(bytes4(_operatorInput[calldataPtr:calldataPtr + 4])); if (numberOfL2ToL1Logs > L2_TO_L1_LOGS_MERKLE_TREE_LEAVES) { revert ReconstructionMismatch( PubdataField.NumberOfLogs, bytes32(L2_TO_L1_LOGS_MERKLE_TREE_LEAVES), bytes32(uint256(numberOfL2ToL1Logs)) ); } calldataPtr += 4; // We need to ensure that length is enough to read all logs if (length < 4 + numberOfL2ToL1Logs * L2_TO_L1_LOG_SERIALIZE_SIZE) { revert ReconstructionMismatch( PubdataField.Length, bytes32(4 + numberOfL2ToL1Logs * L2_TO_L1_LOG_SERIALIZE_SIZE), bytes32(length) ); } bytes32[] memory l2ToL1LogsTreeArray = new bytes32[](L2_TO_L1_LOGS_MERKLE_TREE_LEAVES); bytes32 reconstructedChainedLogsHash = bytes32(0); for (uint256 i = 0; i < numberOfL2ToL1Logs; ++i) { bytes32 hashedLog = EfficientCall.keccak( _operatorInput[calldataPtr:calldataPtr + L2_TO_L1_LOG_SERIALIZE_SIZE] ); calldataPtr += L2_TO_L1_LOG_SERIALIZE_SIZE; l2ToL1LogsTreeArray[i] = hashedLog; reconstructedChainedLogsHash = keccak256(abi.encode(reconstructedChainedLogsHash, hashedLog)); } if (reconstructedChainedLogsHash != chainedLogsHash) { revert ReconstructionMismatch(PubdataField.LogsHash, chainedLogsHash, reconstructedChainedLogsHash); } for (uint256 i = numberOfL2ToL1Logs; i < L2_TO_L1_LOGS_MERKLE_TREE_LEAVES; ++i) { l2ToL1LogsTreeArray[i] = L2_L1_LOGS_TREE_DEFAULT_LEAF_HASH; } uint256 nodesOnCurrentLevel = L2_TO_L1_LOGS_MERKLE_TREE_LEAVES; while (nodesOnCurrentLevel > 1) { nodesOnCurrentLevel /= 2; for (uint256 i = 0; i < nodesOnCurrentLevel; ++i) { l2ToL1LogsTreeArray[i] = keccak256( abi.encode(l2ToL1LogsTreeArray[2 * i], l2ToL1LogsTreeArray[2 * i + 1]) ); } } bytes32 localLogsRootHash = l2ToL1LogsTreeArray[0]; bytes32 aggregatedRootHash = L2_MESSAGE_ROOT.getAggregatedRoot(); bytes32 fullRootHash = keccak256(bytes.concat(localLogsRootHash, aggregatedRootHash)); if (inputChainedLogsRootHash != localLogsRootHash) { revert ReconstructionMismatch(PubdataField.InputLogsRootHash, localLogsRootHash, inputChainedLogsRootHash); } bytes32 l2DAValidatorOutputhash = bytes32(0); if (_l2DAValidator != address(0)) { bytes memory returnData = EfficientCall.call({ _gas: gasleft(), _address: _l2DAValidator, _value: 0, _data: _operatorInput, _isSystem: false }); l2DAValidatorOutputhash = abi.decode(returnData, (bytes32)); } /// Native (VM) L2 to L1 log SystemContractHelper.toL1(true, bytes32(uint256(SystemLogKey.L2_TO_L1_LOGS_TREE_ROOT_KEY)), fullRootHash); SystemContractHelper.toL1( true, bytes32(uint256(SystemLogKey.USED_L2_DA_VALIDATOR_ADDRESS_KEY)), bytes32(uint256(uint160(_l2DAValidator))) ); SystemContractHelper.toL1( true, bytes32(uint256(SystemLogKey.L2_DA_VALIDATOR_OUTPUT_HASH_KEY)), l2DAValidatorOutputhash ); /// Clear logs state chainedLogsHash = bytes32(0); numberOfLogsToProcess = 0; chainedMessagesHash = bytes32(0); chainedL1BytecodesRevealDataHash = bytes32(0); } }
// 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.20; import {IAccountCodeStorage} from "./interfaces/IAccountCodeStorage.sol"; import {INonceHolder} from "./interfaces/INonceHolder.sol"; import {IContractDeployer} from "./interfaces/IContractDeployer.sol"; import {IKnownCodesStorage} from "./interfaces/IKnownCodesStorage.sol"; import {IImmutableSimulator} from "./interfaces/IImmutableSimulator.sol"; import {IBaseToken} from "./interfaces/IBaseToken.sol"; import {IBridgehub} from "./interfaces/IBridgehub.sol"; import {IL1Messenger} from "./interfaces/IL1Messenger.sol"; import {ISystemContext} from "./interfaces/ISystemContext.sol"; import {ICompressor} from "./interfaces/ICompressor.sol"; import {IComplexUpgrader} from "./interfaces/IComplexUpgrader.sol"; import {IBootloaderUtilities} from "./interfaces/IBootloaderUtilities.sol"; import {IPubdataChunkPublisher} from "./interfaces/IPubdataChunkPublisher.sol"; import {IMessageRoot} from "./interfaces/IMessageRoot.sol"; import {ICreate2Factory} from "./interfaces/ICreate2Factory.sol"; /// @dev All the system contracts introduced by ZKsync have their addresses /// started from 2^15 in order to avoid collision with Ethereum precompiles. uint160 constant SYSTEM_CONTRACTS_OFFSET = 0x8000; // 2^15 /// @dev Unlike the value above, it is not overridden for the purpose of testing and /// is identical to the constant value actually used as the system contracts offset on /// mainnet. uint160 constant REAL_SYSTEM_CONTRACTS_OFFSET = 0x8000; /// @dev All the system contracts must be located in the kernel space, /// i.e. their addresses must be below 2^16. uint160 constant MAX_SYSTEM_CONTRACT_ADDRESS = 0xffff; // 2^16 - 1 /// @dev The offset from which the built-in, but user space contracts are located. uint160 constant USER_CONTRACTS_OFFSET = MAX_SYSTEM_CONTRACT_ADDRESS + 1; address constant ECRECOVER_SYSTEM_CONTRACT = address(0x01); address constant SHA256_SYSTEM_CONTRACT = address(0x02); address constant ECADD_SYSTEM_CONTRACT = address(0x06); address constant ECMUL_SYSTEM_CONTRACT = address(0x07); address constant ECPAIRING_SYSTEM_CONTRACT = address(0x08); /// @dev The number of gas that need to be spent for a single byte of pubdata regardless of the pubdata price. /// This variable is used to ensure the following: /// - That the long-term storage of the operator is compensated properly. /// - That it is not possible that the pubdata counter grows too high without spending proportional amount of computation. uint256 constant COMPUTATIONAL_PRICE_FOR_PUBDATA = 80; /// @dev The maximal possible address of an L1-like precompie. These precompiles maintain the following properties: /// - Their extcodehash is EMPTY_STRING_KECCAK /// - Their extcodesize is 0 despite having a bytecode formally deployed there. uint256 constant CURRENT_MAX_PRECOMPILE_ADDRESS = 0xff; address payable constant BOOTLOADER_FORMAL_ADDRESS = payable(address(SYSTEM_CONTRACTS_OFFSET + 0x01)); IAccountCodeStorage constant ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT = IAccountCodeStorage( address(SYSTEM_CONTRACTS_OFFSET + 0x02) ); INonceHolder constant NONCE_HOLDER_SYSTEM_CONTRACT = INonceHolder(address(SYSTEM_CONTRACTS_OFFSET + 0x03)); IKnownCodesStorage constant KNOWN_CODE_STORAGE_CONTRACT = IKnownCodesStorage(address(SYSTEM_CONTRACTS_OFFSET + 0x04)); IImmutableSimulator constant IMMUTABLE_SIMULATOR_SYSTEM_CONTRACT = IImmutableSimulator( address(SYSTEM_CONTRACTS_OFFSET + 0x05) ); IContractDeployer constant DEPLOYER_SYSTEM_CONTRACT = IContractDeployer(address(SYSTEM_CONTRACTS_OFFSET + 0x06)); IContractDeployer constant REAL_DEPLOYER_SYSTEM_CONTRACT = IContractDeployer(address(REAL_SYSTEM_CONTRACTS_OFFSET + 0x06)); // A contract that is allowed to deploy any codehash // on any address. To be used only during an upgrade. address constant FORCE_DEPLOYER = address(SYSTEM_CONTRACTS_OFFSET + 0x07); IL1Messenger constant L1_MESSENGER_CONTRACT = IL1Messenger(address(SYSTEM_CONTRACTS_OFFSET + 0x08)); address constant MSG_VALUE_SYSTEM_CONTRACT = address(SYSTEM_CONTRACTS_OFFSET + 0x09); IBaseToken constant BASE_TOKEN_SYSTEM_CONTRACT = IBaseToken(address(SYSTEM_CONTRACTS_OFFSET + 0x0a)); IBaseToken constant REAL_BASE_TOKEN_SYSTEM_CONTRACT = IBaseToken(address(REAL_SYSTEM_CONTRACTS_OFFSET + 0x0a)); ICreate2Factory constant L2_CREATE2_FACTORY = ICreate2Factory(address(USER_CONTRACTS_OFFSET)); address constant L2_ASSET_ROUTER = address(USER_CONTRACTS_OFFSET + 0x03); IBridgehub constant L2_BRIDGE_HUB = IBridgehub(address(USER_CONTRACTS_OFFSET + 0x02)); address constant L2_NATIVE_TOKEN_VAULT_ADDR = address(USER_CONTRACTS_OFFSET + 0x04); IMessageRoot constant L2_MESSAGE_ROOT = IMessageRoot(address(USER_CONTRACTS_OFFSET + 0x05)); // Note, that on its own this contract does not provide much functionality, but having it on a constant address // serves as a convenient storage for its bytecode to be accessible via `extcodehash`. address constant SLOAD_CONTRACT_ADDRESS = address(USER_CONTRACTS_OFFSET + 0x06); address constant WRAPPED_BASE_TOKEN_IMPL_ADDRESS = address(USER_CONTRACTS_OFFSET + 0x07); // Hardcoded because even for tests we should keep the address. (Instead `SYSTEM_CONTRACTS_OFFSET + 0x10`) // Precompile call depends on it. // And we don't want to mock this contract. address constant KECCAK256_SYSTEM_CONTRACT = address(0x8010); ISystemContext constant SYSTEM_CONTEXT_CONTRACT = ISystemContext(payable(address(SYSTEM_CONTRACTS_OFFSET + 0x0b))); ISystemContext constant REAL_SYSTEM_CONTEXT_CONTRACT = ISystemContext(payable(address(REAL_SYSTEM_CONTRACTS_OFFSET + 0x0b))); IBootloaderUtilities constant BOOTLOADER_UTILITIES = IBootloaderUtilities(address(SYSTEM_CONTRACTS_OFFSET + 0x0c)); // It will be a different value for tests, while shouldn't. But for now, this constant is not used by other contracts, so that's fine. address constant EVENT_WRITER_CONTRACT = address(SYSTEM_CONTRACTS_OFFSET + 0x0d); ICompressor constant COMPRESSOR_CONTRACT = ICompressor(address(SYSTEM_CONTRACTS_OFFSET + 0x0e)); IComplexUpgrader constant COMPLEX_UPGRADER_CONTRACT = IComplexUpgrader(address(SYSTEM_CONTRACTS_OFFSET + 0x0f)); IPubdataChunkPublisher constant PUBDATA_CHUNK_PUBLISHER = IPubdataChunkPublisher( address(SYSTEM_CONTRACTS_OFFSET + 0x11) ); /// @dev If the bitwise AND of the extraAbi[2] param when calling the MSG_VALUE_SIMULATOR /// is non-zero, the call will be assumed to be a system one. uint256 constant MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT = 1; /// @dev The maximal msg.value that context can have uint256 constant MAX_MSG_VALUE = type(uint128).max; /// @dev Prefix used during derivation of account addresses using CREATE2 /// @dev keccak256("zksyncCreate2") bytes32 constant CREATE2_PREFIX = 0x2020dba91b30cc0006188af794c2fb30dd8520db7e2c088b7fc7c103c00ca494; /// @dev Prefix used during derivation of account addresses using CREATE /// @dev keccak256("zksyncCreate") bytes32 constant CREATE_PREFIX = 0x63bae3a9951d38e8a3fbb7b70909afc1200610fc5bc55ade242f815974674f23; /// @dev Each state diff consists of 156 bytes of actual data and 116 bytes of unused padding, needed for circuit efficiency. uint256 constant STATE_DIFF_ENTRY_SIZE = 272; enum SystemLogKey { L2_TO_L1_LOGS_TREE_ROOT_KEY, PACKED_BATCH_AND_L2_BLOCK_TIMESTAMP_KEY, CHAINED_PRIORITY_TXN_HASH_KEY, NUMBER_OF_LAYER_1_TXS_KEY, // Note, that it is important that `PREV_BATCH_HASH_KEY` has position // `4` since it is the same as it was in the previous protocol version and // it is the only one that is emitted before the system contracts are upgraded. PREV_BATCH_HASH_KEY, L2_DA_VALIDATOR_OUTPUT_HASH_KEY, USED_L2_DA_VALIDATOR_ADDRESS_KEY, EXPECTED_SYSTEM_CONTRACT_UPGRADE_TX_HASH_KEY } /// @dev The number of leaves in the L2->L1 log Merkle tree. /// While formally a tree of any length is acceptable, the node supports only a constant length of 16384 leaves. uint256 constant L2_TO_L1_LOGS_MERKLE_TREE_LEAVES = 16_384; /// @dev The length of the derived key in bytes inside compressed state diffs. uint256 constant DERIVED_KEY_LENGTH = 32; /// @dev The length of the enum index in bytes inside compressed state diffs. uint256 constant ENUM_INDEX_LENGTH = 8; /// @dev The length of value in bytes inside compressed state diffs. uint256 constant VALUE_LENGTH = 32; /// @dev The length of the compressed initial storage write in bytes. uint256 constant COMPRESSED_INITIAL_WRITE_SIZE = DERIVED_KEY_LENGTH + VALUE_LENGTH; /// @dev The length of the compressed repeated storage write in bytes. uint256 constant COMPRESSED_REPEATED_WRITE_SIZE = ENUM_INDEX_LENGTH + VALUE_LENGTH; /// @dev The position from which the initial writes start in the compressed state diffs. uint256 constant INITIAL_WRITE_STARTING_POSITION = 4; /// @dev Each storage diffs consists of the following elements: /// [20bytes address][32bytes key][32bytes derived key][8bytes enum index][32bytes initial value][32bytes final value] /// @dev The offset of the derived key in a storage diff. uint256 constant STATE_DIFF_DERIVED_KEY_OFFSET = 52; /// @dev The offset of the enum index in a storage diff. uint256 constant STATE_DIFF_ENUM_INDEX_OFFSET = 84; /// @dev The offset of the final value in a storage diff. uint256 constant STATE_DIFF_FINAL_VALUE_OFFSET = 124; /// @dev Total number of bytes in a blob. Blob = 4096 field elements * 31 bytes per field element /// @dev EIP-4844 defines it as 131_072 but we use 4096 * 31 within our circuits to always fit within a field element /// @dev Our circuits will prove that a EIP-4844 blob and our internal blob are the same. uint256 constant BLOB_SIZE_BYTES = 126_976; /// @dev Max number of blobs currently supported uint256 constant MAX_NUMBER_OF_BLOBS = 6;
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; /// @title SloadContract /// @author Matter Labs /// @custom:security-contact [email protected] /// @notice This contract provides a method to read values from arbitrary storage slots /// @dev It is used by the `SystemContractHelper` library to help system contracts read /// arbitrary slots of contracts. contract SloadContract { /// @notice Reads the value stored at a specific storage slot /// @param slot The storage slot number to read from /// @return value The value stored at the specified slot as a bytes32 type function sload(bytes32 slot) external view returns (bytes32 value) { assembly { // sload retrieves the value at the given storage slot value := sload(slot) } } }
// 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.20; // 0x86bb51b8 error AddressHasNoCode(address); // 0xefce78c7 error CallerMustBeBootloader(); // 0x9eedbd2b error CallerMustBeSystemContract(); // 0x4f951510 error CompressionValueAddError(uint256 expected, uint256 actual); // 0x1e6aff87 error CompressionValueTransformError(uint256 expected, uint256 actual); // 0xc2ea251e error CompressionValueSubError(uint256 expected, uint256 actual); // 0x849acb7f error CompressorInitialWritesProcessedNotEqual(uint256 expected, uint256 actual); // 0x61a6a4b3 error CompressorEnumIndexNotEqual(uint256 expected, uint256 actual); // 0x9be48d8d error DerivedKeyNotEqualToCompressedValue(bytes32 expected, bytes32 provided); // 0xe223db5e error DictionaryDividedByEightNotGreaterThanEncodedDividedByTwo(); // 0x1c25715b error EmptyBytes32(); // 0xc06d5cb2 error EncodedAndRealBytecodeChunkNotEqual(uint64 expected, uint64 provided); // 0x2bfbfc11 error EncodedLengthNotFourTimesSmallerThanOriginal(); // 0xe95a1fbe error FailedToChargeGas(); // 0x1f70c58f error FailedToPayOperator(); // 0x9e4a3c8a error HashIsNonZero(bytes32); // 0x86302004 error HashMismatch(bytes32 expected, uint256 actual); // 0x4e23d035 error IndexOutOfBounds(); // 0x122e73e9 error IndexSizeError(); // 0x03eb8b54 error InsufficientFunds(uint256 required, uint256 actual); // 0xae962d4e error InvalidCall(); // 0x8cbd7f8b error InvalidCodeHash(CodeHashReason); // 0xb4fa3fb3 error InvalidInput(); // 0x60b85677 error InvalidNonceOrderingChange(); // 0xc6b7f67d error InvalidSig(SigField, uint256); // 0xf4a271b5 error Keccak256InvalidReturnData(); // 0xcea34703 error MalformedBytecode(BytecodeError); // 0xe90aded4 error NonceAlreadyUsed(address account, uint256 nonce); // 0x45ac24a6 error NonceIncreaseError(uint256 max, uint256 proposed); // 0x13595475 error NonceJumpError(); // 0x1f2f8478 error NonceNotUsed(address account, uint256 nonce); // 0x760a1568 error NonEmptyAccount(); // 0x536ec84b error NonEmptyMsgValue(); // 0xd018e08e error NonIncreasingTimestamp(); // 0x50df6bc3 error NotAllowedToDeployInKernelSpace(); // 0x35278d12 error Overflow(); // 0xe5ec477a error ReconstructionMismatch(PubdataField, bytes32 expected, bytes32 actual); // 0x3adb5f1d error ShaInvalidReturnData(); // 0xbd8665e2 error StateDiffLengthMismatch(); // 0x71c3da01 error SystemCallFlagRequired(); // 0xe0456dfe error TooMuchPubdata(uint256 limit, uint256 supplied); // 0x8e4a23d6 error Unauthorized(address); // 0x3e5efef9 error UnknownCodeHash(bytes32); // 0x9ba6061b error UnsupportedOperation(); // 0xff15b069 error UnsupportedPaymasterFlow(); // 0x17a84415 error UnsupportedTxType(uint256); // 0x626ade30 error ValueMismatch(uint256 expected, uint256 actual); // 0x6818f3f9 error ZeroNonceError(); // 0x4f2b5b33 error SloadContractBytecodeUnknown(); // 0x43197434 error PreviousBytecodeUnknown(); // 0x7a47c9a2 error InvalidChainId(); // 0xc84a0422 error UpgradeTransactionMustBeFirst(); // 0x543f4c07 error L2BlockNumberZero(); // 0x702a599f error PreviousL2BlockHashIsIncorrect(bytes32 correctPrevBlockHash, bytes32 expectedPrevL2BlockHash); // 0x2692f507 error CannotInitializeFirstVirtualBlock(); // 0x5e9ad9b0 error L2BlockAndBatchTimestampMismatch(uint128 l2BlockTimestamp, uint128 currentBatchTimestamp); // 0x159a6f2e error InconsistentNewBatchTimestamp(uint128 newBatchTimestamp, uint128 lastL2BlockTimestamp); // 0xdcdfb0da error NoVirtualBlocks(); // 0x141d6142 error CannotReuseL2BlockNumberFromPreviousBatch(); // 0xf34da52d error IncorrectSameL2BlockTimestamp(uint128 l2BlockTimestamp, uint128 currentL2BlockTimestamp); // 0x5822b85d error IncorrectSameL2BlockPrevBlockHash(bytes32 expectedPrevL2BlockHash, bytes32 latestL2blockHash); // 0x6d391091 error IncorrectVirtualBlockInsideMiniblock(); // 0xdf841e81 error IncorrectL2BlockHash(bytes32 expectedPrevL2BlockHash, bytes32 pendingL2BlockHash); // 0x35dbda93 error NonMonotonicL2BlockTimestamp(uint128 l2BlockTimestamp, uint128 currentL2BlockTimestamp); // 0x6ad429e8 error CurrentBatchNumberMustBeGreaterThanZero(); // 0x09c63320 error TimestampsShouldBeIncremental(uint128 newTimestamp, uint128 previousBatchTimestamp); // 0x33cb1485 error ProvidedBatchNumberIsNotCorrect(uint128 previousBatchNumber, uint128 _expectedNewNumber); // 0xaa957ece error CodeOracleCallFailed(); // 0x26772295 error ReturnedBytecodeDoesNotMatchExpectedHash(bytes32 returnedBytecode, bytes32 expectedBytecodeHash); // 0x7f08f26b error SecondCallShouldHaveCostLessGas(uint256 secondCallCost, uint256 firstCallCost); // 0xaa016ed2 error ThirdCallShouldHaveSameGasCostAsSecondCall(uint256 thirdCallCost, uint256 secondCallCost); // 0xee455381 error CallToKeccakShouldHaveSucceeded(); // 0x9c9d5e18 error KeccakReturnDataSizeShouldBe32Bytes(uint256 returnDataSize); // 0x0c69f92e error KeccakResultIsNotCorrect(bytes32 result); // 0x262f4984 error KeccakShouldStartWorkingAgain(); // 0x034e49a6 error KeccakMismatchBetweenNumberOfInputsAndOutputs(uint256 testInputsLength, uint256 expectedOutputsLength); // 0x92f5b709 error KeccakHashWasNotCalculatedCorrectly(bytes32 result, bytes32 expectedOutputs); // 0xbf961a28 error TransactionFailed(); // 0xdd629f86 error NotEnoughGas(); // 0xf0b4e88f error TooMuchGas(); // 0x8c13f15d error InvalidNewL2BlockNumber(uint256 l2BlockNumber); enum CodeHashReason { NotContractOnConstructor, NotConstructedContract } enum SigField { Length, V, S } enum PubdataField { NumberOfLogs, LogsHash, MsgHash, Bytecode, InputDAFunctionSig, InputLogsHash, InputLogsRootHash, InputMsgsHash, InputBytecodeHash, Offset, Length } enum BytecodeError { Version, NumberOfWords, Length, WordsMustBeOdd, DictionaryLength }
// 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.20; import {SystemContractHelper} from "../libraries/SystemContractHelper.sol"; import {BOOTLOADER_FORMAL_ADDRESS} from "../Constants.sol"; import {SystemCallFlagRequired, Unauthorized, CallerMustBeSystemContract, CallerMustBeBootloader} from "../SystemContractErrors.sol"; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice An abstract contract that is used to reuse modifiers across the system contracts. * @dev Solidity does not allow exporting modifiers via libraries, so * the only way to do reuse modifiers is to have a base contract * @dev Never add storage variables into this contract as some * system contracts rely on this abstract contract as on interface! */ abstract contract SystemContractBase { /// @notice Modifier that makes sure that the method /// can only be called via a system call. modifier onlySystemCall() { if (!SystemContractHelper.isSystemCall() && !SystemContractHelper.isSystemContract(msg.sender)) { revert SystemCallFlagRequired(); } _; } /// @notice Modifier that makes sure that the method /// can only be called from a system contract. modifier onlyCallFromSystemContract() { if (!SystemContractHelper.isSystemContract(msg.sender)) { revert CallerMustBeSystemContract(); } _; } /// @notice Modifier that makes sure that the method /// can only be called from a special given address. modifier onlyCallFrom(address caller) { if (msg.sender != caller) { revert Unauthorized(msg.sender); } _; } /// @notice Modifier that makes sure that the method /// can only be called from the bootloader. modifier onlyCallFromBootloader() { if (msg.sender != BOOTLOADER_FORMAL_ADDRESS) { revert CallerMustBeBootloader(); } _; } }
// 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.20; interface IAccountCodeStorage { function storeAccountConstructingCodeHash(address _address, bytes32 _hash) external; function storeAccountConstructedCodeHash(address _address, bytes32 _hash) external; function markAccountCodeHashAsConstructed(address _address) external; function getRawCodeHash(address _address) external view returns (bytes32 codeHash); function getCodeHash(uint256 _input) external view returns (bytes32 codeHash); function getCodeSize(uint256 _input) external view returns (uint256 codeSize); }
// 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.20; interface IBaseToken { function balanceOf(uint256) external view returns (uint256); function transferFromTo(address _from, address _to, uint256 _amount) external; function totalSupply() external view returns (uint256); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function mint(address _account, uint256 _amount) external; function withdraw(address _l1Receiver) external payable; function withdrawWithMessage(address _l1Receiver, bytes calldata _additionalData) external payable; event Mint(address indexed account, uint256 amount); event Transfer(address indexed from, address indexed to, uint256 value); event Withdrawal(address indexed _l2Sender, address indexed _l1Receiver, uint256 _amount); event WithdrawalWithMessage( address indexed _l2Sender, address indexed _l1Receiver, uint256 _amount, bytes _additionalData ); }
// 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.20; import {Transaction} from "../libraries/TransactionHelper.sol"; interface IBootloaderUtilities { function getTransactionHashes( Transaction calldata _transaction ) external view returns (bytes32 txHash, bytes32 signedTxHash); }
// 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.20; /// @author Matter Labs /// @custom:security-contact [email protected] interface IBridgehub { function setAddresses(address _assetRouter, address _ctmDeployer, address _messageRoot) external; function owner() external view returns (address); }
// 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.20; import {ForceDeployment} from "./IContractDeployer.sol"; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice The interface for the ComplexUpgrader contract. */ interface IComplexUpgrader { function forceDeployAndUpgrade( ForceDeployment[] calldata _forceDeployments, address _delegateTo, bytes calldata _calldata ) external payable; function upgrade(address _delegateTo, bytes calldata _calldata) external payable; }
// 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.20; // The bitmask by applying which to the compressed state diff metadata we retrieve its operation. uint8 constant OPERATION_BITMASK = 7; // The number of bits shifting the compressed state diff metadata by which we retrieve its length. uint8 constant LENGTH_BITS_OFFSET = 3; // The maximal length in bytes that an enumeration index can have. uint8 constant MAX_ENUMERATION_INDEX_SIZE = 8; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice The interface for the Compressor contract, responsible for verifying the correctness of * the compression of the state diffs and bytecodes. */ interface ICompressor { function publishCompressedBytecode( bytes calldata _bytecode, bytes calldata _rawCompressedData ) external returns (bytes32 bytecodeHash); function verifyCompressedStateDiffs( uint256 _numberOfStateDiffs, uint256 _enumerationIndexSize, bytes calldata _stateDiffs, bytes calldata _compressedStateDiffs ) external returns (bytes32 stateDiffHash); }
// 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.20; /// @notice A struct that describes a forced deployment on an address struct ForceDeployment { // The bytecode hash to put on an address bytes32 bytecodeHash; // The address on which to deploy the bytecodehash to address newAddress; // Whether to run the constructor on the force deployment bool callConstructor; // The value with which to initialize a contract uint256 value; // The constructor calldata bytes input; } interface IContractDeployer { /// @notice Defines the version of the account abstraction protocol /// that a contract claims to follow. /// - `None` means that the account is just a contract and it should never be interacted /// with as a custom account /// - `Version1` means that the account follows the first version of the account abstraction protocol enum AccountAbstractionVersion { None, Version1 } /// @notice Defines the nonce ordering used by the account /// - `Sequential` means that it is expected that the nonces are monotonic and increment by 1 /// at a time (the same as EOAs). /// - `Arbitrary` means that the nonces for the accounts can be arbitrary. The operator /// should serve the transactions from such an account on a first-come-first-serve basis. /// @dev This ordering is more of a suggestion to the operator on how the AA expects its transactions /// to be processed and is not considered as a system invariant. enum AccountNonceOrdering { Sequential, Arbitrary } struct AccountInfo { AccountAbstractionVersion supportedAAVersion; AccountNonceOrdering nonceOrdering; } event ContractDeployed( address indexed deployerAddress, bytes32 indexed bytecodeHash, address indexed contractAddress ); event AccountNonceOrderingUpdated(address indexed accountAddress, AccountNonceOrdering nonceOrdering); event AccountVersionUpdated(address indexed accountAddress, AccountAbstractionVersion aaVersion); function getNewAddressCreate2( address _sender, bytes32 _bytecodeHash, bytes32 _salt, bytes calldata _input ) external view returns (address newAddress); function getNewAddressCreate(address _sender, uint256 _senderNonce) external pure returns (address newAddress); function create2( bytes32 _salt, bytes32 _bytecodeHash, bytes calldata _input ) external payable returns (address newAddress); function create2Account( bytes32 _salt, bytes32 _bytecodeHash, bytes calldata _input, AccountAbstractionVersion _aaVersion ) external payable returns (address newAddress); /// @dev While the `_salt` parameter is not used anywhere here, /// it is still needed for consistency between `create` and /// `create2` functions (required by the compiler). function create( bytes32 _salt, bytes32 _bytecodeHash, bytes calldata _input ) external payable returns (address newAddress); /// @dev While `_salt` is never used here, we leave it here as a parameter /// for the consistency with the `create` function. function createAccount( bytes32 _salt, bytes32 _bytecodeHash, bytes calldata _input, AccountAbstractionVersion _aaVersion ) external payable returns (address newAddress); /// @notice Returns the information about a certain AA. function getAccountInfo(address _address) external view returns (AccountInfo memory info); /// @notice Can be called by an account to update its account version function updateAccountVersion(AccountAbstractionVersion _version) external; /// @notice Can be called by an account to update its nonce ordering function updateNonceOrdering(AccountNonceOrdering _nonceOrdering) external; /// @notice This method is to be used only during an upgrade to set bytecodes on specific addresses. function forceDeployOnAddresses(ForceDeployment[] calldata _deployments) external payable; }
// 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.20; import {IContractDeployer} from "./IContractDeployer.sol"; /// @custom:security-contact [email protected] /// @author Matter Labs /// @notice The contract that can be used for deterministic contract deployment. interface ICreate2Factory { /// @notice Function that calls the `create2` method of the `ContractDeployer` contract. /// @dev This function accepts the same parameters as the `create2` function of the ContractDeployer system contract, /// so that we could efficiently relay the calldata. function create2( bytes32, // _salt bytes32, // _bytecodeHash bytes calldata // _input ) external payable returns (address); /// @notice Function that calls the `create2Account` method of the `ContractDeployer` contract. /// @dev This function accepts the same parameters as the `create2Account` function of the ContractDeployer system contract, /// so that we could efficiently relay the calldata. function create2Account( bytes32, // _salt bytes32, // _bytecodeHash bytes calldata, // _input IContractDeployer.AccountAbstractionVersion // _aaVersion ) external payable returns (address); }
// 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.20; struct ImmutableData { uint256 index; bytes32 value; } interface IImmutableSimulator { function getImmutable(address _dest, uint256 _index) external view returns (bytes32); function setImmutables(address _dest, ImmutableData[] calldata _immutables) external; }
// 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.20; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice The interface for the KnownCodesStorage contract, which is responsible * for storing the hashes of the bytecodes that have been published to the network. */ interface IKnownCodesStorage { event MarkedAsKnown(bytes32 indexed bytecodeHash, bool indexed sendBytecodeToL1); function markFactoryDeps(bool _shouldSendToL1, bytes32[] calldata _hashes) external; function markBytecodeAsPublished(bytes32 _bytecodeHash) external; function getMarker(bytes32 _hash) external view returns (uint256); }
// 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.20; /// @dev The log passed from L2 /// @param l2ShardId The shard identifier, 0 - rollup, 1 - porter. All other values are not used but are reserved for the future /// @param isService A boolean flag that is part of the log along with `key`, `value`, and `sender` address. /// This field is required formally but does not have any special meaning. /// @param txNumberInBlock The L2 transaction number in a block, in which the log was sent /// @param sender The L2 address which sent the log /// @param key The 32 bytes of information that was sent in the log /// @param value The 32 bytes of information that was sent in the log // Both `key` and `value` are arbitrary 32-bytes selected by the log sender struct L2ToL1Log { uint8 l2ShardId; bool isService; uint16 txNumberInBlock; address sender; bytes32 key; bytes32 value; } /// @dev Bytes in raw L2 to L1 log /// @dev Equal to the bytes size of the tuple - (uint8 ShardId, bool isService, uint16 txNumberInBlock, address sender, bytes32 key, bytes32 value) uint256 constant L2_TO_L1_LOG_SERIALIZE_SIZE = 88; /// @dev The value of default leaf hash for L2 to L1 logs Merkle tree /// @dev An incomplete fixed-size tree is filled with this value to be a full binary tree /// @dev Actually equal to the `keccak256(new bytes(L2_TO_L1_LOG_SERIALIZE_SIZE))` bytes32 constant L2_L1_LOGS_TREE_DEFAULT_LEAF_HASH = 0x72abee45b59e344af8a6e520241c4744aff26ed411f4c4b00f8af09adada43ba; /// @dev The current version of state diff compression being used. uint256 constant STATE_DIFF_COMPRESSION_VERSION_NUMBER = 1; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice The interface of the L1 Messenger contract, responsible for sending messages to L1. */ interface IL1Messenger { // Possibly in the future we will be able to track the messages sent to L1 with // some hooks in the VM. For now, it is much easier to track them with L2 events. event L1MessageSent(address indexed _sender, bytes32 indexed _hash, bytes _message); event L2ToL1LogSent(L2ToL1Log _l2log); event BytecodeL1PublicationRequested(bytes32 _bytecodeHash); function sendToL1(bytes calldata _message) external returns (bytes32); function sendL2ToL1Log(bool _isService, bytes32 _key, bytes32 _value) external returns (uint256 logIdInMerkleTree); // This function is expected to be called only by the KnownCodesStorage system contract function requestBytecodeL1Publication(bytes32 _bytecodeHash) external; }
// 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.20; interface IL2DAValidator { function validatePubdata( // The rolling hash of the user L2->L1 logs. bytes32 _chainedLogsHash, // The root hash of the user L2->L1 logs. bytes32 _logsRootHash, // The chained hash of the L2->L1 messages bytes32 _chainedMessagesHash, // The chained hash of uncompressed bytecodes sent to L1 bytes32 _chainedBytecodesHash, // Same operator input bytes calldata _totalL2ToL1PubdataAndStateDiffs ) external returns (bytes32 outputHash); }
// 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.20; /** * @author Matter Labs * @notice MessageRoot contract is responsible for storing and aggregating the roots of the batches from different chains into the MessageRoot. * @custom:security-contact [email protected] */ interface IMessageRoot { /// @notice The aggregated root of the batches from different chains. /// @return aggregatedRoot of the batches from different chains. function getAggregatedRoot() external view returns (bytes32 aggregatedRoot); }
// 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.20; /** * @author Matter Labs * @dev Interface of the nonce holder contract -- a contract used by the system to ensure * that there is always a unique identifier for a transaction with a particular account (we call it nonce). * In other words, the pair of (address, nonce) should always be unique. * @dev Custom accounts should use methods of this contract to store nonces or other possible unique identifiers * for the transaction. */ interface INonceHolder { event ValueSetUnderNonce(address indexed accountAddress, uint256 indexed key, uint256 value); /// @dev Returns the current minimal nonce for account. function getMinNonce(address _address) external view returns (uint256); /// @dev Returns the raw version of the current minimal nonce /// (equal to minNonce + 2^128 * deployment nonce). function getRawNonce(address _address) external view returns (uint256); /// @dev Increases the minimal nonce for the msg.sender. function increaseMinNonce(uint256 _value) external returns (uint256); /// @dev Sets the nonce value `key` as used. function setValueUnderNonce(uint256 _key, uint256 _value) external; /// @dev Gets the value stored inside a custom nonce. function getValueUnderNonce(uint256 _key) external view returns (uint256); /// @dev A convenience method to increment the minimal nonce if it is equal /// to the `_expectedNonce`. function incrementMinNonceIfEquals(uint256 _expectedNonce) external; /// @dev Returns the deployment nonce for the accounts used for CREATE opcode. function getDeploymentNonce(address _address) external view returns (uint256); /// @dev Increments the deployment nonce for the account and returns the previous one. function incrementDeploymentNonce(address _address) external returns (uint256); /// @dev Determines whether a certain nonce has been already used for an account. function validateNonceUsage(address _address, uint256 _key, bool _shouldBeUsed) external view; /// @dev Returns whether a nonce has been used for an account. function isNonceUsed(address _address, uint256 _nonce) external view returns (bool); }
// 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.20; /** * @author Matter Labs * @dev The interface that is used for encoding/decoding of * different types of paymaster flows. * @notice This is NOT an interface to be implemented * by contracts. It is just used for encoding. */ interface IPaymasterFlow { function general(bytes calldata input) external; function approvalBased(address _token, uint256 _minAllowance, bytes calldata _innerInput) external; }
// 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.20; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice Interface for contract responsible chunking pubdata into the appropriate size for EIP-4844 blobs. */ interface IPubdataChunkPublisher { /// @notice Chunks pubdata into pieces that can fit into blobs. /// @param _pubdata The total l2 to l1 pubdata that will be sent via L1 blobs. /// @dev Note: This is an early implementation, in the future we plan to support up to 16 blobs per l1 batch. function chunkPubdataToBlobs(bytes calldata _pubdata) external pure returns (bytes32[] memory blobLinearHashes); }
// 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.20; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice Contract that stores some of the context variables, that may be either * block-scoped, tx-scoped or system-wide. */ interface ISystemContext { struct BlockInfo { uint128 timestamp; uint128 number; } /// @notice A structure representing the timeline for the upgrade from the batch numbers to the L2 block numbers. /// @dev It will be used for the L1 batch -> L2 block migration in Q3 2023 only. struct VirtualBlockUpgradeInfo { /// @notice In order to maintain consistent results for `blockhash` requests, we'll /// have to remember the number of the batch when the upgrade to the virtual blocks has been done. /// The hashes for virtual blocks before the upgrade are identical to the hashes of the corresponding batches. uint128 virtualBlockStartBatch; /// @notice L2 block when the virtual blocks have caught up with the L2 blocks. Starting from this block, /// all the information returned to users for block.timestamp/number, etc should be the information about the L2 blocks and /// not virtual blocks. uint128 virtualBlockFinishL2Block; } function chainId() external view returns (uint256); function origin() external view returns (address); function gasPrice() external view returns (uint256); function blockGasLimit() external view returns (uint256); function coinbase() external view returns (address); function difficulty() external view returns (uint256); function baseFee() external view returns (uint256); function txNumberInBlock() external view returns (uint16); function getBlockHashEVM(uint256 _block) external view returns (bytes32); function getBatchHash(uint256 _batchNumber) external view returns (bytes32 hash); function getBlockNumber() external view returns (uint128); function getBlockTimestamp() external view returns (uint128); function getBatchNumberAndTimestamp() external view returns (uint128 blockNumber, uint128 blockTimestamp); function getL2BlockNumberAndTimestamp() external view returns (uint128 blockNumber, uint128 blockTimestamp); function gasPerPubdataByte() external view returns (uint256 gasPerPubdataByte); function getCurrentPubdataSpent() external view returns (uint256 currentPubdataSpent); function setChainId(uint256 _newChainId) external; }
// 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.20; import {SystemContractHelper, ADDRESS_MASK} from "./SystemContractHelper.sol"; import {SystemContractsCaller, CalldataForwardingMode, RAW_FAR_CALL_BY_REF_CALL_ADDRESS, SYSTEM_CALL_BY_REF_CALL_ADDRESS, MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT, MIMIC_CALL_BY_REF_CALL_ADDRESS} from "./SystemContractsCaller.sol"; import {Utils} from "./Utils.sol"; import {SHA256_SYSTEM_CONTRACT, KECCAK256_SYSTEM_CONTRACT, MSG_VALUE_SYSTEM_CONTRACT} from "../Constants.sol"; import {Keccak256InvalidReturnData, ShaInvalidReturnData} from "../SystemContractErrors.sol"; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice This library is used to perform ultra-efficient calls using zkEVM-specific features. * @dev EVM calls always accept a memory slice as input and return a memory slice as output. * Therefore, even if the user has a ready-made calldata slice, they still need to copy it to memory * before calling. This is especially inefficient for large inputs (proxies, multi-calls, etc.). * In turn, zkEVM operates over a fat pointer, which is a set of (memory page, offset, start, length) in the memory/calldata/returndata. * This allows forwarding the calldata slice as is, without copying it to memory. * @dev Fat pointer is not just an integer, it is an extended data type supported on the VM level. * zkEVM creates the wellformed fat pointers for all the calldata/returndata regions, later * the contract may manipulate the already created fat pointers to forward a slice of the data, but not * to create new fat pointers! * @dev The allowed operation on fat pointers are: * 1. `ptr.add` - Transforms `ptr.offset` into `ptr.offset + u32(_value)`. If overflow happens then it panics. * 2. `ptr.sub` - Transforms `ptr.offset` into `ptr.offset - u32(_value)`. If underflow happens then it panics. * 3. `ptr.pack` - Do the concatenation between the lowest 128 bits of the pointer itself and the highest 128 bits of `_value`. It is typically used to prepare the ABI for external calls. * 4. `ptr.shrink` - Transforms `ptr.length` into `ptr.length - u32(_shrink)`. If underflow happens then it panics. * @dev The call opcodes accept the fat pointer and change it to its canonical form before passing it to the child call * 1. `ptr.start` is transformed into `ptr.offset + ptr.start` * 2. `ptr.length` is transformed into `ptr.length - ptr.offset` * 3. `ptr.offset` is transformed into `0` */ library EfficientCall { /// @notice Call the `keccak256` without copying calldata to memory. /// @param _data The preimage data. /// @return The `keccak256` hash. function keccak(bytes calldata _data) internal view returns (bytes32) { bytes memory returnData = staticCall(gasleft(), KECCAK256_SYSTEM_CONTRACT, _data); if (returnData.length != 32) { revert Keccak256InvalidReturnData(); } return bytes32(returnData); } /// @notice Call the `sha256` precompile without copying calldata to memory. /// @param _data The preimage data. /// @return The `sha256` hash. function sha(bytes calldata _data) internal view returns (bytes32) { bytes memory returnData = staticCall(gasleft(), SHA256_SYSTEM_CONTRACT, _data); if (returnData.length != 32) { revert ShaInvalidReturnData(); } return bytes32(returnData); } /// @notice Perform a `call` without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _value The `msg.value` to send. /// @param _data The calldata to use for the call. /// @param _isSystem Whether the call should contain the `isSystem` flag. /// @return returnData The copied to memory return data. function call( uint256 _gas, address _address, uint256 _value, bytes calldata _data, bool _isSystem ) internal returns (bytes memory returnData) { bool success = rawCall({_gas: _gas, _address: _address, _value: _value, _data: _data, _isSystem: _isSystem}); returnData = _verifyCallResult(success); } /// @notice Perform a `staticCall` without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _data The calldata to use for the call. /// @return returnData The copied to memory return data. function staticCall( uint256 _gas, address _address, bytes calldata _data ) internal view returns (bytes memory returnData) { bool success = rawStaticCall(_gas, _address, _data); returnData = _verifyCallResult(success); } /// @notice Perform a `delegateCall` without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _data The calldata to use for the call. /// @return returnData The copied to memory return data. function delegateCall( uint256 _gas, address _address, bytes calldata _data ) internal returns (bytes memory returnData) { bool success = rawDelegateCall(_gas, _address, _data); returnData = _verifyCallResult(success); } /// @notice Perform a `mimicCall` (a call with custom msg.sender) without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _data The calldata to use for the call. /// @param _whoToMimic The `msg.sender` for the next call. /// @param _isConstructor Whether the call should contain the `isConstructor` flag. /// @param _isSystem Whether the call should contain the `isSystem` flag. /// @return returnData The copied to memory return data. function mimicCall( uint256 _gas, address _address, bytes calldata _data, address _whoToMimic, bool _isConstructor, bool _isSystem ) internal returns (bytes memory returnData) { bool success = rawMimicCall({ _gas: _gas, _address: _address, _data: _data, _whoToMimic: _whoToMimic, _isConstructor: _isConstructor, _isSystem: _isSystem }); returnData = _verifyCallResult(success); } /// @notice Perform a `call` without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _value The `msg.value` to send. /// @param _data The calldata to use for the call. /// @param _isSystem Whether the call should contain the `isSystem` flag. /// @return success whether the call was successful. function rawCall( uint256 _gas, address _address, uint256 _value, bytes calldata _data, bool _isSystem ) internal returns (bool success) { if (_value == 0) { _loadFarCallABIIntoActivePtr(_gas, _data, false, _isSystem); address callAddr = RAW_FAR_CALL_BY_REF_CALL_ADDRESS; assembly { success := call(_address, callAddr, 0, 0, 0xFFFF, 0, 0) } } else { _loadFarCallABIIntoActivePtr(_gas, _data, false, true); // If there is provided `msg.value` call the `MsgValueSimulator` to forward ether. address msgValueSimulator = MSG_VALUE_SYSTEM_CONTRACT; address callAddr = SYSTEM_CALL_BY_REF_CALL_ADDRESS; // We need to supply the mask to the MsgValueSimulator to denote // that the call should be a system one. uint256 forwardMask = _isSystem ? MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT : 0; assembly { success := call(msgValueSimulator, callAddr, _value, _address, 0xFFFF, forwardMask, 0) } } } /// @notice Perform a `staticCall` without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _data The calldata to use for the call. /// @return success whether the call was successful. function rawStaticCall(uint256 _gas, address _address, bytes calldata _data) internal view returns (bool success) { _loadFarCallABIIntoActivePtr(_gas, _data, false, false); address callAddr = RAW_FAR_CALL_BY_REF_CALL_ADDRESS; assembly { success := staticcall(_address, callAddr, 0, 0xFFFF, 0, 0) } } /// @notice Perform a `delegatecall` without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _data The calldata to use for the call. /// @return success whether the call was successful. function rawDelegateCall(uint256 _gas, address _address, bytes calldata _data) internal returns (bool success) { _loadFarCallABIIntoActivePtr(_gas, _data, false, false); address callAddr = RAW_FAR_CALL_BY_REF_CALL_ADDRESS; assembly { success := delegatecall(_address, callAddr, 0, 0xFFFF, 0, 0) } } /// @notice Perform a `mimicCall` (call with custom msg.sender) without copying calldata to memory. /// @param _gas The gas to use for the call. /// @param _address The address to call. /// @param _data The calldata to use for the call. /// @param _whoToMimic The `msg.sender` for the next call. /// @param _isConstructor Whether the call should contain the `isConstructor` flag. /// @param _isSystem Whether the call should contain the `isSystem` flag. /// @return success whether the call was successful. /// @dev If called not in kernel mode, it will result in a revert (enforced by the VM) function rawMimicCall( uint256 _gas, address _address, bytes calldata _data, address _whoToMimic, bool _isConstructor, bool _isSystem ) internal returns (bool success) { _loadFarCallABIIntoActivePtr(_gas, _data, _isConstructor, _isSystem); address callAddr = MIMIC_CALL_BY_REF_CALL_ADDRESS; uint256 cleanupMask = ADDRESS_MASK; assembly { // Clearing values before usage in assembly, since Solidity // doesn't do it by default _whoToMimic := and(_whoToMimic, cleanupMask) success := call(_address, callAddr, 0, 0, _whoToMimic, 0, 0) } } /// @dev Verify that a low-level call was successful, and revert if it wasn't, by bubbling the revert reason. /// @param _success Whether the call was successful. /// @return returnData The copied to memory return data. function _verifyCallResult(bool _success) private pure returns (bytes memory returnData) { if (_success) { uint256 size; assembly { size := returndatasize() } returnData = new bytes(size); assembly { returndatacopy(add(returnData, 0x20), 0, size) } } else { propagateRevert(); } } /// @dev Propagate the revert reason from the current call to the caller. function propagateRevert() internal pure { assembly { let size := returndatasize() returndatacopy(0, 0, size) revert(0, size) } } /// @dev Load the far call ABI into active ptr, that will be used for the next call by reference. /// @param _gas The gas to be passed to the call. /// @param _data The calldata to be passed to the call. /// @param _isConstructor Whether the call is a constructor call. /// @param _isSystem Whether the call is a system call. function _loadFarCallABIIntoActivePtr( uint256 _gas, bytes calldata _data, bool _isConstructor, bool _isSystem ) private view { SystemContractHelper.loadCalldataIntoActivePtr(); uint256 dataOffset; assembly { dataOffset := _data.offset } // Safe to cast, offset is never bigger than `type(uint32).max` SystemContractHelper.ptrAddIntoActive(uint32(dataOffset)); // Safe to cast, `data.length` is never bigger than `type(uint32).max` uint32 shrinkTo = uint32(msg.data.length - (_data.length + dataOffset)); SystemContractHelper.ptrShrinkIntoActive(shrinkTo); uint32 gas = Utils.safeCastToU32(_gas); uint256 farCallAbi = SystemContractsCaller.getFarCallABIWithEmptyFatPointer({ gasPassed: gas, // Only rollup is supported for now shardId: 0, forwardingMode: CalldataForwardingMode.ForwardFatPointer, isConstructorCall: _isConstructor, isSystemCall: _isSystem }); SystemContractHelper.ptrPackIntoActivePtr(farCallAbi); } }
// 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.20; /** * @author Matter Labs * @custom:security-contact [email protected] * @notice This library provides RLP encoding functionality. */ library RLPEncoder { function encodeAddress(address _val) internal pure returns (bytes memory encoded) { // The size is equal to 20 bytes of the address itself + 1 for encoding bytes length in RLP. encoded = new bytes(0x15); bytes20 shiftedVal = bytes20(_val); assembly { // In the first byte we write the encoded length as 0x80 + 0x14 == 0x94. mstore(add(encoded, 0x20), 0x9400000000000000000000000000000000000000000000000000000000000000) // Write address data without stripping zeros. mstore(add(encoded, 0x21), shiftedVal) } } function encodeUint256(uint256 _val) internal pure returns (bytes memory encoded) { unchecked { if (_val < 128) { encoded = new bytes(1); // Handle zero as a non-value, since stripping zeroes results in an empty byte array encoded[0] = (_val == 0) ? bytes1(uint8(128)) : bytes1(uint8(_val)); } else { uint256 hbs = _highestByteSet(_val); encoded = new bytes(hbs + 2); encoded[0] = bytes1(uint8(hbs + 0x81)); uint256 lbs = 31 - hbs; uint256 shiftedVal = _val << (lbs * 8); assembly { mstore(add(encoded, 0x21), shiftedVal) } } } } /// @notice Encodes the size of bytes in RLP format. /// @param _len The length of the bytes to encode. It has a `uint64` type since as larger values are not supported. /// NOTE: panics if the length is 1 since the length encoding is ambiguous in this case. function encodeNonSingleBytesLen(uint64 _len) internal pure returns (bytes memory) { assert(_len != 1); return _encodeLength(_len, 0x80); } /// @notice Encodes the size of list items in RLP format. /// @param _len The length of the bytes to encode. It has a `uint64` type since as larger values are not supported. function encodeListLen(uint64 _len) internal pure returns (bytes memory) { return _encodeLength(_len, 0xc0); } function _encodeLength(uint64 _len, uint256 _offset) private pure returns (bytes memory encoded) { unchecked { if (_len < 56) { encoded = new bytes(1); encoded[0] = bytes1(uint8(_len + _offset)); } else { uint256 hbs = _highestByteSet(uint256(_len)); encoded = new bytes(hbs + 2); encoded[0] = bytes1(uint8(_offset + hbs + 56)); uint256 lbs = 31 - hbs; uint256 shiftedVal = uint256(_len) << (lbs * 8); assembly { mstore(add(encoded, 0x21), shiftedVal) } } } } /// @notice Computes the index of the highest byte set in number. /// @notice Uses little endian ordering (The least significant byte has index `0`). /// NOTE: returns `0` for `0` function _highestByteSet(uint256 _number) private pure returns (uint256 hbs) { unchecked { if (_number > type(uint128).max) { _number >>= 128; hbs += 16; } if (_number > type(uint64).max) { _number >>= 64; hbs += 8; } if (_number > type(uint32).max) { _number >>= 32; hbs += 4; } if (_number > type(uint16).max) { _number >>= 16; hbs += 2; } if (_number > type(uint8).max) { ++hbs; } } } }
// 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.20; import {MAX_SYSTEM_CONTRACT_ADDRESS, DEPLOYER_SYSTEM_CONTRACT, FORCE_DEPLOYER, KNOWN_CODE_STORAGE_CONTRACT, SLOAD_CONTRACT_ADDRESS} from "../Constants.sol"; import {ForceDeployment, IContractDeployer} from "../interfaces/IContractDeployer.sol"; import {SloadContract} from "../SloadContract.sol"; import {CalldataForwardingMode, SystemContractsCaller, MIMIC_CALL_CALL_ADDRESS, CALLFLAGS_CALL_ADDRESS, CODE_ADDRESS_CALL_ADDRESS, EVENT_WRITE_ADDRESS, EVENT_INITIALIZE_ADDRESS, GET_EXTRA_ABI_DATA_ADDRESS, LOAD_CALLDATA_INTO_ACTIVE_PTR_CALL_ADDRESS, META_CODE_SHARD_ID_OFFSET, META_CALLER_SHARD_ID_OFFSET, META_SHARD_ID_OFFSET, META_AUX_HEAP_SIZE_OFFSET, META_HEAP_SIZE_OFFSET, META_PUBDATA_PUBLISHED_OFFSET, META_CALL_ADDRESS, PTR_CALLDATA_CALL_ADDRESS, PTR_ADD_INTO_ACTIVE_CALL_ADDRESS, PTR_SHRINK_INTO_ACTIVE_CALL_ADDRESS, PTR_PACK_INTO_ACTIVE_CALL_ADDRESS, PRECOMPILE_CALL_ADDRESS, SET_CONTEXT_VALUE_CALL_ADDRESS, TO_L1_CALL_ADDRESS} from "./SystemContractsCaller.sol"; import {IndexOutOfBounds, FailedToChargeGas, SloadContractBytecodeUnknown, PreviousBytecodeUnknown} from "../SystemContractErrors.sol"; uint256 constant UINT32_MASK = type(uint32).max; uint256 constant UINT64_MASK = type(uint64).max; uint256 constant UINT128_MASK = type(uint128).max; uint256 constant ADDRESS_MASK = type(uint160).max; /// @notice NOTE: The `getZkSyncMeta` that is used to obtain this struct will experience a breaking change in 2024. struct ZkSyncMeta { uint32 pubdataPublished; uint32 heapSize; uint32 auxHeapSize; uint8 shardId; uint8 callerShardId; uint8 codeShardId; } enum Global { CalldataPtr, CallFlags, ExtraABIData1, ExtraABIData2, ReturndataPtr } /** * @author Matter Labs * @custom:security-contact [email protected] * @notice Library used for accessing zkEVM-specific opcodes, needed for the development * of system contracts. * @dev While this library will be eventually available to public, some of the provided * methods won't work for non-system contracts and also breaking changes at short notice are possible. * We do not recommend this library for external use. */ library SystemContractHelper { /// @notice Send an L2Log to L1. /// @param _isService The `isService` flag. /// @param _key The `key` part of the L2Log. /// @param _value The `value` part of the L2Log. /// @dev The meaning of all these parameters is context-dependent, but they /// have no intrinsic meaning per se. function toL1(bool _isService, bytes32 _key, bytes32 _value) internal { address callAddr = TO_L1_CALL_ADDRESS; assembly { // Ensuring that the type is bool _isService := and(_isService, 1) // This `success` is always 0, but the method always succeeds // (except for the cases when there is not enough gas) // solhint-disable-next-line no-unused-vars let success := call(_isService, callAddr, _key, _value, 0xFFFF, 0, 0) } } /// @notice Get address of the currently executed code. /// @dev This allows differentiating between `call` and `delegatecall`. /// During the former `this` and `codeAddress` are the same, while /// during the latter they are not. function getCodeAddress() internal view returns (address addr) { address callAddr = CODE_ADDRESS_CALL_ADDRESS; assembly { addr := staticcall(0, callAddr, 0, 0xFFFF, 0, 0) } } /// @notice Provide a compiler hint, by placing calldata fat pointer into virtual `ACTIVE_PTR`, /// that can be manipulated by `ptr.add`/`ptr.sub`/`ptr.pack`/`ptr.shrink` later. /// @dev This allows making a call by forwarding calldata pointer to the child call. /// It is a much more efficient way to forward calldata, than standard EVM bytes copying. function loadCalldataIntoActivePtr() internal view { address callAddr = LOAD_CALLDATA_INTO_ACTIVE_PTR_CALL_ADDRESS; assembly { pop(staticcall(0, callAddr, 0, 0xFFFF, 0, 0)) } } /// @notice Compiler simulation of the `ptr.pack` opcode for the virtual `ACTIVE_PTR` pointer. /// @dev Do the concatenation between lowest part of `ACTIVE_PTR` and highest part of `_farCallAbi` /// forming packed fat pointer for a far call or ret ABI when necessary. /// Note: Panics if the lowest 128 bits of `_farCallAbi` are not zeroes. function ptrPackIntoActivePtr(uint256 _farCallAbi) internal view { address callAddr = PTR_PACK_INTO_ACTIVE_CALL_ADDRESS; assembly { pop(staticcall(_farCallAbi, callAddr, 0, 0xFFFF, 0, 0)) } } /// @notice Compiler simulation of the `ptr.add` opcode for the virtual `ACTIVE_PTR` pointer. /// @dev Transforms `ACTIVE_PTR.offset` into `ACTIVE_PTR.offset + u32(_value)`. If overflow happens then it panics. function ptrAddIntoActive(uint32 _value) internal view { address callAddr = PTR_ADD_INTO_ACTIVE_CALL_ADDRESS; uint256 cleanupMask = UINT32_MASK; assembly { // Clearing input params as they are not cleaned by Solidity by default _value := and(_value, cleanupMask) pop(staticcall(_value, callAddr, 0, 0xFFFF, 0, 0)) } } /// @notice Compiler simulation of the `ptr.shrink` opcode for the virtual `ACTIVE_PTR` pointer. /// @dev Transforms `ACTIVE_PTR.length` into `ACTIVE_PTR.length - u32(_shrink)`. If underflow happens then it panics. function ptrShrinkIntoActive(uint32 _shrink) internal view { address callAddr = PTR_SHRINK_INTO_ACTIVE_CALL_ADDRESS; uint256 cleanupMask = UINT32_MASK; assembly { // Clearing input params as they are not cleaned by Solidity by default _shrink := and(_shrink, cleanupMask) pop(staticcall(_shrink, callAddr, 0, 0xFFFF, 0, 0)) } } /// @notice packs precompile parameters into one word /// @param _inputMemoryOffset The memory offset in 32-byte words for the input data for calling the precompile. /// @param _inputMemoryLength The length of the input data in words. /// @param _outputMemoryOffset The memory offset in 32-byte words for the output data. /// @param _outputMemoryLength The length of the output data in words. /// @param _perPrecompileInterpreted The constant, the meaning of which is defined separately for /// each precompile. For information, please read the documentation of the precompilecall log in /// the VM. function packPrecompileParams( uint32 _inputMemoryOffset, uint32 _inputMemoryLength, uint32 _outputMemoryOffset, uint32 _outputMemoryLength, uint64 _perPrecompileInterpreted ) internal pure returns (uint256 rawParams) { rawParams = _inputMemoryOffset; rawParams |= uint256(_inputMemoryLength) << 32; rawParams |= uint256(_outputMemoryOffset) << 64; rawParams |= uint256(_outputMemoryLength) << 96; rawParams |= uint256(_perPrecompileInterpreted) << 192; } /// @notice Call precompile with given parameters. /// @param _rawParams The packed precompile params. They can be retrieved by /// the `packPrecompileParams` method. /// @param _gasToBurn The number of gas to burn during this call. /// @param _pubdataToSpend The number of pubdata bytes to burn during the call. /// @return success Whether the call was successful. /// @dev The list of currently available precompiles sha256, keccak256, ecrecover. /// NOTE: The precompile type depends on `this` which calls precompile, which means that only /// system contracts corresponding to the list of precompiles above can do `precompileCall`. /// @dev If used not in the `sha256`, `keccak256` or `ecrecover` contracts, it will just burn the gas provided. /// @dev This method is `unsafe` because it does not check whether there is enough gas to burn. function unsafePrecompileCall( uint256 _rawParams, uint32 _gasToBurn, uint32 _pubdataToSpend ) internal view returns (bool success) { address callAddr = PRECOMPILE_CALL_ADDRESS; uint256 params = uint256(_gasToBurn) + (uint256(_pubdataToSpend) << 32); uint256 cleanupMask = UINT64_MASK; assembly { // Clearing input params as they are not cleaned by Solidity by default params := and(params, cleanupMask) success := staticcall(_rawParams, callAddr, params, 0xFFFF, 0, 0) } } /// @notice Set `msg.value` to next far call. /// @param _value The msg.value that will be used for the *next* call. /// @dev If called not in kernel mode, it will result in a revert (enforced by the VM) function setValueForNextFarCall(uint128 _value) internal returns (bool success) { uint256 cleanupMask = UINT128_MASK; address callAddr = SET_CONTEXT_VALUE_CALL_ADDRESS; assembly { // Clearing input params as they are not cleaned by Solidity by default _value := and(_value, cleanupMask) success := call(0, callAddr, _value, 0, 0xFFFF, 0, 0) } } /// @notice Initialize a new event. /// @param initializer The event initializing value. /// @param value1 The first topic or data chunk. function eventInitialize(uint256 initializer, uint256 value1) internal { address callAddr = EVENT_INITIALIZE_ADDRESS; assembly { pop(call(initializer, callAddr, value1, 0, 0xFFFF, 0, 0)) } } /// @notice Continue writing the previously initialized event. /// @param value1 The first topic or data chunk. /// @param value2 The second topic or data chunk. function eventWrite(uint256 value1, uint256 value2) internal { address callAddr = EVENT_WRITE_ADDRESS; assembly { pop(call(value1, callAddr, value2, 0, 0xFFFF, 0, 0)) } } /// @notice Get the packed representation of the `ZkSyncMeta` from the current context. /// @notice NOTE: The behavior of this function will experience a breaking change in 2024. /// @return meta The packed representation of the ZkSyncMeta. /// @dev The fields in ZkSyncMeta are NOT tightly packed, i.e. there is a special rule on how /// they are packed. For more information, please read the documentation on ZkSyncMeta. function getZkSyncMetaBytes() internal view returns (uint256 meta) { address callAddr = META_CALL_ADDRESS; assembly { meta := staticcall(0, callAddr, 0, 0xFFFF, 0, 0) } } /// @notice Returns the bits [offset..offset+size-1] of the meta. /// @param meta Packed representation of the ZkSyncMeta. /// @param offset The offset of the bits. /// @param size The size of the extracted number in bits. /// @return result The extracted number. function extractNumberFromMeta(uint256 meta, uint256 offset, uint256 size) internal pure returns (uint256 result) { // Firstly, we delete all the bits after the field uint256 shifted = (meta << (256 - size - offset)); // Then we shift everything back result = (shifted >> (256 - size)); } /// @notice Given the packed representation of `ZkSyncMeta`, retrieves the number of pubdata /// bytes published in the batch so far. /// @notice NOTE: The behavior of this function will experience a breaking change in 2024. /// @param meta Packed representation of the ZkSyncMeta. /// @return pubdataPublished The amount of pubdata published in the system so far. function getPubdataPublishedFromMeta(uint256 meta) internal pure returns (uint32 pubdataPublished) { pubdataPublished = uint32(extractNumberFromMeta(meta, META_PUBDATA_PUBLISHED_OFFSET, 32)); } /// @notice Given the packed representation of `ZkSyncMeta`, retrieves the number of the current size /// of the heap in bytes. /// @param meta Packed representation of the ZkSyncMeta. /// @return heapSize The size of the memory in bytes byte. /// @dev The following expression: getHeapSizeFromMeta(getZkSyncMetaBytes()) is /// equivalent to the MSIZE in Solidity. function getHeapSizeFromMeta(uint256 meta) internal pure returns (uint32 heapSize) { heapSize = uint32(extractNumberFromMeta(meta, META_HEAP_SIZE_OFFSET, 32)); } /// @notice Given the packed representation of `ZkSyncMeta`, retrieves the number of the current size /// of the auxiliary heap in bytes. /// @param meta Packed representation of the ZkSyncMeta. /// @return auxHeapSize The size of the auxiliary memory in bytes byte. /// @dev You can read more on auxiliary memory in the VM1.2 documentation. function getAuxHeapSizeFromMeta(uint256 meta) internal pure returns (uint32 auxHeapSize) { auxHeapSize = uint32(extractNumberFromMeta(meta, META_AUX_HEAP_SIZE_OFFSET, 32)); } /// @notice Given the packed representation of `ZkSyncMeta`, retrieves the shardId of `this`. /// @param meta Packed representation of the ZkSyncMeta. /// @return shardId The shardId of `this`. /// @dev Currently only shard 0 (zkRollup) is supported. function getShardIdFromMeta(uint256 meta) internal pure returns (uint8 shardId) { shardId = uint8(extractNumberFromMeta(meta, META_SHARD_ID_OFFSET, 8)); } /// @notice Given the packed representation of `ZkSyncMeta`, retrieves the shardId of /// the msg.sender. /// @param meta Packed representation of the ZkSyncMeta. /// @return callerShardId The shardId of the msg.sender. /// @dev Currently only shard 0 (zkRollup) is supported. function getCallerShardIdFromMeta(uint256 meta) internal pure returns (uint8 callerShardId) { callerShardId = uint8(extractNumberFromMeta(meta, META_CALLER_SHARD_ID_OFFSET, 8)); } /// @notice Given the packed representation of `ZkSyncMeta`, retrieves the shardId of /// the currently executed code. /// @param meta Packed representation of the ZkSyncMeta. /// @return codeShardId The shardId of the currently executed code. /// @dev Currently only shard 0 (zkRollup) is supported. function getCodeShardIdFromMeta(uint256 meta) internal pure returns (uint8 codeShardId) { codeShardId = uint8(extractNumberFromMeta(meta, META_CODE_SHARD_ID_OFFSET, 8)); } /// @notice Retrieves the ZkSyncMeta structure. /// @notice NOTE: The behavior of this function will experience a breaking change in 2024. /// @return meta The ZkSyncMeta execution context parameters. function getZkSyncMeta() internal view returns (ZkSyncMeta memory meta) { uint256 metaPacked = getZkSyncMetaBytes(); meta.pubdataPublished = getPubdataPublishedFromMeta(metaPacked); meta.heapSize = getHeapSizeFromMeta(metaPacked); meta.auxHeapSize = getAuxHeapSizeFromMeta(metaPacked); meta.shardId = getShardIdFromMeta(metaPacked); meta.callerShardId = getCallerShardIdFromMeta(metaPacked); meta.codeShardId = getCodeShardIdFromMeta(metaPacked); } /// @notice Returns the call flags for the current call. /// @return callFlags The bitmask of the callflags. /// @dev Call flags is the value of the first register /// at the start of the call. /// @dev The zero bit of the callFlags indicates whether the call is /// a constructor call. The first bit of the callFlags indicates whether /// the call is a system one. function getCallFlags() internal view returns (uint256 callFlags) { address callAddr = CALLFLAGS_CALL_ADDRESS; assembly { callFlags := staticcall(0, callAddr, 0, 0xFFFF, 0, 0) } } /// @notice Returns the current calldata pointer. /// @return ptr The current calldata pointer. /// @dev NOTE: This file is just an integer and it cannot be used /// to forward the calldata to the next calls in any way. function getCalldataPtr() internal view returns (uint256 ptr) { address callAddr = PTR_CALLDATA_CALL_ADDRESS; assembly { ptr := staticcall(0, callAddr, 0, 0xFFFF, 0, 0) } } /// @notice Returns the N-th extraAbiParam for the current call. /// @return extraAbiData The value of the N-th extraAbiParam for this call. /// @dev It is equal to the value of the (N+2)-th register /// at the start of the call. function getExtraAbiData(uint256 index) internal view returns (uint256 extraAbiData) { // Note that there are only 10 accessible registers (indices 0-9 inclusively) if (index > 9) { revert IndexOutOfBounds(); } address callAddr = GET_EXTRA_ABI_DATA_ADDRESS; assembly { extraAbiData := staticcall(index, callAddr, 0, 0xFFFF, 0, 0) } } /// @notice Returns whether the current call is a system call. /// @return `true` or `false` based on whether the current call is a system call. function isSystemCall() internal view returns (bool) { uint256 callFlags = getCallFlags(); // When the system call is passed, the 2-bit is set to 1 return (callFlags & 2) != 0; } /// @notice Returns whether the address is a system contract. /// @param _address The address to test /// @return `true` or `false` based on whether the `_address` is a system contract. function isSystemContract(address _address) internal pure returns (bool) { return uint160(_address) <= uint160(MAX_SYSTEM_CONTRACT_ADDRESS); } /// @notice Method used for burning a certain amount of gas. /// @param _gasToPay The number of gas to burn. /// @param _pubdataToSpend The number of pubdata bytes to burn during the call. function burnGas(uint32 _gasToPay, uint32 _pubdataToSpend) internal view { bool precompileCallSuccess = unsafePrecompileCall( 0, // The precompile parameters are formal ones. We only need the precompile call to burn gas. _gasToPay, _pubdataToSpend ); if (!precompileCallSuccess) { revert FailedToChargeGas(); } } /// @notice Performs a `mimicCall` to an address. /// @param _to The address to call. /// @param _whoToMimic The address to mimic. /// @param _data The data to pass to the call. /// @return success Whether the call was successful. /// @return returndata The return data of the call. function mimicCall( address _to, address _whoToMimic, bytes memory _data ) internal returns (bool success, bytes memory returndata) { // In zkSync, no memory-related values can exceed uint32, so it is safe to convert here uint32 dataStart; uint32 dataLength = uint32(_data.length); assembly { dataStart := add(_data, 0x20) } uint256 farCallAbi = SystemContractsCaller.getFarCallABI({ dataOffset: 0, memoryPage: 0, dataStart: dataStart, dataLength: dataLength, gasPassed: uint32(gasleft()), shardId: 0, forwardingMode: CalldataForwardingMode.UseHeap, isConstructorCall: false, isSystemCall: false }); address callAddr = MIMIC_CALL_CALL_ADDRESS; uint256 rtSize; assembly { success := call(_to, callAddr, 0, farCallAbi, _whoToMimic, 0, 0) rtSize := returndatasize() } returndata = new bytes(rtSize); assembly { returndatacopy(add(returndata, 0x20), 0, rtSize) } } /// @notice Force deploys some bytecode hash to an address /// without invoking the constructor. /// @param _addr The address to force-deploy the bytecodehash to. /// @param _bytecodeHash The bytecode hash to force-deploy. function forceDeployNoConstructor(address _addr, bytes32 _bytecodeHash) internal { ForceDeployment[] memory deployments = new ForceDeployment[](1); deployments[0] = ForceDeployment({ bytecodeHash: _bytecodeHash, newAddress: _addr, callConstructor: false, value: 0, input: hex"" }); mimicCallWithPropagatedRevert( address(DEPLOYER_SYSTEM_CONTRACT), FORCE_DEPLOYER, abi.encodeCall(IContractDeployer.forceDeployOnAddresses, deployments) ); } /// @notice Reads a certain storage slot from a contract. /// @param _addr The address to read the slot from. /// @param _key The key to read. /// @return result The value stored at slot `_key` under the address `_addr`. /// @dev zkEVM similarly to EVM only has an opcode to read /// from the current contract's storage. However, sometimes system contracts /// may require to read private storage slots of a contract. In order to provide /// generic functionality to read arbitrary storage slots from other contracts, the following /// scheme is used: /// 1. Force-deploy `SloadContract` to the address. /// 2. Read the required slot. /// 3. Force-deploy the previous bytecode back. /// @dev Note, that the function will overwrite the account states of the `_addr`, i.e. /// this function should NEVER be used against custom accounts. function forcedSload(address _addr, bytes32 _key) internal returns (bytes32 result) { bytes32 sloadContractBytecodeHash; address sloadContractAddress = SLOAD_CONTRACT_ADDRESS; assembly { sloadContractBytecodeHash := extcodehash(sloadContractAddress) } // Just in case, that the `sloadContractBytecodeHash` is known if (KNOWN_CODE_STORAGE_CONTRACT.getMarker(sloadContractBytecodeHash) == 0) { revert SloadContractBytecodeUnknown(); } bytes32 previoushHash; assembly { previoushHash := extcodehash(_addr) } // Just in case, double checking that the previous bytecode is known. // It may be needed since `previoushHash` could be non-zero and unknown if it is // equal to keccak(""). It is the case for used default accounts. if (KNOWN_CODE_STORAGE_CONTRACT.getMarker(previoushHash) == 0) { revert PreviousBytecodeUnknown(); } forceDeployNoConstructor(_addr, sloadContractBytecodeHash); result = SloadContract(_addr).sload(_key); forceDeployNoConstructor(_addr, previoushHash); } /// @notice Performs a `mimicCall` to an address, while ensuring that the call /// was successful /// @param _to The address to call. /// @param _whoToMimic The address to mimic. /// @param _data The data to pass to the call. function mimicCallWithPropagatedRevert(address _to, address _whoToMimic, bytes memory _data) internal { (bool success, bytes memory returnData) = mimicCall(_to, _whoToMimic, _data); if (!success) { // Propagate revert reason assembly { revert(add(returnData, 0x20), returndatasize()) } } } }
// 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.20; import {MSG_VALUE_SYSTEM_CONTRACT, MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT} from "../Constants.sol"; import {Utils} from "./Utils.sol"; // Addresses used for the compiler to be replaced with the // ZKsync-specific opcodes during the compilation. // IMPORTANT: these are just compile-time constants and are used // only if used in-place by Yul optimizer. address constant TO_L1_CALL_ADDRESS = address((1 << 16) - 1); address constant CODE_ADDRESS_CALL_ADDRESS = address((1 << 16) - 2); address constant PRECOMPILE_CALL_ADDRESS = address((1 << 16) - 3); address constant META_CALL_ADDRESS = address((1 << 16) - 4); address constant MIMIC_CALL_CALL_ADDRESS = address((1 << 16) - 5); address constant SYSTEM_MIMIC_CALL_CALL_ADDRESS = address((1 << 16) - 6); address constant MIMIC_CALL_BY_REF_CALL_ADDRESS = address((1 << 16) - 7); address constant SYSTEM_MIMIC_CALL_BY_REF_CALL_ADDRESS = address((1 << 16) - 8); address constant RAW_FAR_CALL_CALL_ADDRESS = address((1 << 16) - 9); address constant RAW_FAR_CALL_BY_REF_CALL_ADDRESS = address((1 << 16) - 10); address constant SYSTEM_CALL_CALL_ADDRESS = address((1 << 16) - 11); address constant SYSTEM_CALL_BY_REF_CALL_ADDRESS = address((1 << 16) - 12); address constant SET_CONTEXT_VALUE_CALL_ADDRESS = address((1 << 16) - 13); address constant SET_PUBDATA_PRICE_CALL_ADDRESS = address((1 << 16) - 14); address constant INCREMENT_TX_COUNTER_CALL_ADDRESS = address((1 << 16) - 15); address constant PTR_CALLDATA_CALL_ADDRESS = address((1 << 16) - 16); address constant CALLFLAGS_CALL_ADDRESS = address((1 << 16) - 17); address constant PTR_RETURNDATA_CALL_ADDRESS = address((1 << 16) - 18); address constant EVENT_INITIALIZE_ADDRESS = address((1 << 16) - 19); address constant EVENT_WRITE_ADDRESS = address((1 << 16) - 20); address constant LOAD_CALLDATA_INTO_ACTIVE_PTR_CALL_ADDRESS = address((1 << 16) - 21); address constant LOAD_LATEST_RETURNDATA_INTO_ACTIVE_PTR_CALL_ADDRESS = address((1 << 16) - 22); address constant PTR_ADD_INTO_ACTIVE_CALL_ADDRESS = address((1 << 16) - 23); address constant PTR_SHRINK_INTO_ACTIVE_CALL_ADDRESS = address((1 << 16) - 24); address constant PTR_PACK_INTO_ACTIVE_CALL_ADDRESS = address((1 << 16) - 25); address constant MULTIPLICATION_HIGH_ADDRESS = address((1 << 16) - 26); address constant GET_EXTRA_ABI_DATA_ADDRESS = address((1 << 16) - 27); // All the offsets are in bits uint256 constant META_PUBDATA_PUBLISHED_OFFSET = 0 * 8; uint256 constant META_HEAP_SIZE_OFFSET = 8 * 8; uint256 constant META_AUX_HEAP_SIZE_OFFSET = 12 * 8; uint256 constant META_SHARD_ID_OFFSET = 28 * 8; uint256 constant META_CALLER_SHARD_ID_OFFSET = 29 * 8; uint256 constant META_CODE_SHARD_ID_OFFSET = 30 * 8; /// @notice The way to forward the calldata: /// - Use the current heap (i.e. the same as on EVM). /// - Use the auxiliary heap. /// - Forward via a pointer /// @dev Note, that currently, users do not have access to the auxiliary /// heap and so the only type of forwarding that will be used by the users /// are UseHeap and ForwardFatPointer for forwarding a slice of the current calldata /// to the next call. enum CalldataForwardingMode { UseHeap, ForwardFatPointer, UseAuxHeap } /** * @author Matter Labs * @custom:security-contact [email protected] * @notice A library that allows calling contracts with the `isSystem` flag. * @dev It is needed to call ContractDeployer and NonceHolder. */ library SystemContractsCaller { /// @notice Makes a call with the `isSystem` flag. /// @param gasLimit The gas limit for the call. /// @param to The address to call. /// @param value The value to pass with the transaction. /// @param data The calldata. /// @return success Whether the transaction has been successful. /// @dev Note, that the `isSystem` flag can only be set when calling system contracts. function systemCall(uint32 gasLimit, address to, uint256 value, bytes memory data) internal returns (bool success) { address callAddr = SYSTEM_CALL_CALL_ADDRESS; uint32 dataStart; assembly { dataStart := add(data, 0x20) } uint32 dataLength = Utils.safeCastToU32(data.length); uint256 farCallAbi = SystemContractsCaller.getFarCallABI({ dataOffset: 0, memoryPage: 0, dataStart: dataStart, dataLength: dataLength, gasPassed: gasLimit, // Only rollup is supported for now shardId: 0, forwardingMode: CalldataForwardingMode.UseHeap, isConstructorCall: false, isSystemCall: true }); if (value == 0) { // Doing the system call directly assembly { success := call(to, callAddr, 0, 0, farCallAbi, 0, 0) } } else { address msgValueSimulator = MSG_VALUE_SYSTEM_CONTRACT; // We need to supply the mask to the MsgValueSimulator to denote // that the call should be a system one. uint256 forwardMask = MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT; assembly { success := call(msgValueSimulator, callAddr, value, to, farCallAbi, forwardMask, 0) } } } /// @notice Makes a call with the `isSystem` flag. /// @param gasLimit The gas limit for the call. /// @param to The address to call. /// @param value The value to pass with the transaction. /// @param data The calldata. /// @return success Whether the transaction has been successful. /// @return returnData The returndata of the transaction (revert reason in case the transaction has failed). /// @dev Note, that the `isSystem` flag can only be set when calling system contracts. function systemCallWithReturndata( uint32 gasLimit, address to, uint128 value, bytes memory data ) internal returns (bool success, bytes memory returnData) { success = systemCall(gasLimit, to, value, data); uint256 size; assembly { size := returndatasize() } returnData = new bytes(size); assembly { returndatacopy(add(returnData, 0x20), 0, size) } } /// @notice Makes a call with the `isSystem` flag. /// @param gasLimit The gas limit for the call. /// @param to The address to call. /// @param value The value to pass with the transaction. /// @param data The calldata. /// @return returnData The returndata of the transaction. In case the transaction reverts, the error /// bubbles up to the parent frame. /// @dev Note, that the `isSystem` flag can only be set when calling system contracts. function systemCallWithPropagatedRevert( uint32 gasLimit, address to, uint128 value, bytes memory data ) internal returns (bytes memory returnData) { bool success; (success, returnData) = systemCallWithReturndata(gasLimit, to, value, data); if (!success) { assembly { let size := mload(returnData) revert(add(returnData, 0x20), size) } } } /// @notice Calculates the packed representation of the FarCallABI. /// @param dataOffset Calldata offset in memory. Provide 0 unless using custom pointer. /// @param memoryPage Memory page to use. Provide 0 unless using custom pointer. /// @param dataStart The start of the calldata slice. Provide the offset in memory /// if not using custom pointer. /// @param dataLength The calldata length. Provide the length of the calldata in bytes /// unless using custom pointer. /// @param gasPassed The gas to pass with the call. /// @param shardId Of the account to call. Currently only 0 is supported. /// @param forwardingMode The forwarding mode to use: /// - provide CalldataForwardingMode.UseHeap when using your current memory /// - provide CalldataForwardingMode.ForwardFatPointer when using custom pointer. /// @param isConstructorCall Whether the call will be a call to the constructor /// (ignored when the caller is not a system contract). /// @param isSystemCall Whether the call will have the `isSystem` flag. /// @return farCallAbi The far call ABI. /// @dev The `FarCallABI` has the following structure: /// pub struct FarCallABI { /// pub memory_quasi_fat_pointer: FatPointer, /// pub gas_passed: u32, /// pub shard_id: u8, /// pub forwarding_mode: FarCallForwardPageType, /// pub constructor_call: bool, /// pub to_system: bool, /// } /// /// The FatPointer struct: /// /// pub struct FatPointer { /// pub offset: u32, // offset relative to `start` /// pub memory_page: u32, // memory page where slice is located /// pub start: u32, // absolute start of the slice /// pub length: u32, // length of the slice /// } /// /// @dev Note, that the actual layout is the following: /// /// [0..32) bits -- the calldata offset /// [32..64) bits -- the memory page to use. Can be left blank in most of the cases. /// [64..96) bits -- the absolute start of the slice /// [96..128) bits -- the length of the slice. /// [128..192) bits -- empty bits. /// [192..224) bits -- gasPassed. /// [224..232) bits -- forwarding_mode /// [232..240) bits -- shard id. /// [240..248) bits -- constructor call flag /// [248..256] bits -- system call flag function getFarCallABI( uint32 dataOffset, uint32 memoryPage, uint32 dataStart, uint32 dataLength, uint32 gasPassed, uint8 shardId, CalldataForwardingMode forwardingMode, bool isConstructorCall, bool isSystemCall ) internal pure returns (uint256 farCallAbi) { // Fill in the call parameter fields farCallAbi = getFarCallABIWithEmptyFatPointer({ gasPassed: gasPassed, shardId: shardId, forwardingMode: forwardingMode, isConstructorCall: isConstructorCall, isSystemCall: isSystemCall }); // Fill in the fat pointer fields farCallAbi |= dataOffset; farCallAbi |= (uint256(memoryPage) << 32); farCallAbi |= (uint256(dataStart) << 64); farCallAbi |= (uint256(dataLength) << 96); } /// @notice Calculates the packed representation of the FarCallABI with zero fat pointer fields. /// @param gasPassed The gas to pass with the call. /// @param shardId Of the account to call. Currently only 0 is supported. /// @param forwardingMode The forwarding mode to use: /// - provide CalldataForwardingMode.UseHeap when using your current memory /// - provide CalldataForwardingMode.ForwardFatPointer when using custom pointer. /// @param isConstructorCall Whether the call will be a call to the constructor /// (ignored when the caller is not a system contract). /// @param isSystemCall Whether the call will have the `isSystem` flag. /// @return farCallAbiWithEmptyFatPtr The far call ABI with zero fat pointer fields. function getFarCallABIWithEmptyFatPointer( uint32 gasPassed, uint8 shardId, CalldataForwardingMode forwardingMode, bool isConstructorCall, bool isSystemCall ) internal pure returns (uint256 farCallAbiWithEmptyFatPtr) { farCallAbiWithEmptyFatPtr |= (uint256(gasPassed) << 192); farCallAbiWithEmptyFatPtr |= (uint256(forwardingMode) << 224); farCallAbiWithEmptyFatPtr |= (uint256(shardId) << 232); if (isConstructorCall) { farCallAbiWithEmptyFatPtr |= (1 << 240); } if (isSystemCall) { farCallAbiWithEmptyFatPtr |= (1 << 248); } } }
// 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.20; import {IERC20} from "../openzeppelin/token/ERC20/IERC20.sol"; import {SafeERC20} from "../openzeppelin/token/ERC20/utils/SafeERC20.sol"; import {IPaymasterFlow} from "../interfaces/IPaymasterFlow.sol"; import {BASE_TOKEN_SYSTEM_CONTRACT, BOOTLOADER_FORMAL_ADDRESS} from "../Constants.sol"; import {RLPEncoder} from "./RLPEncoder.sol"; import {EfficientCall} from "./EfficientCall.sol"; import {UnsupportedTxType, InvalidInput, UnsupportedPaymasterFlow} from "../SystemContractErrors.sol"; /// @dev The type id of ZKsync's EIP-712-signed transaction. uint8 constant EIP_712_TX_TYPE = 0x71; /// @dev The type id of legacy transactions. uint8 constant LEGACY_TX_TYPE = 0x0; /// @dev The type id of legacy transactions. uint8 constant EIP_2930_TX_TYPE = 0x01; /// @dev The type id of EIP1559 transactions. uint8 constant EIP_1559_TX_TYPE = 0x02; /// @notice Structure used to represent a ZKsync transaction. struct Transaction { // The type of the transaction. uint256 txType; // The caller. uint256 from; // The callee. uint256 to; // The gasLimit to pass with the transaction. // It has the same meaning as Ethereum's gasLimit. uint256 gasLimit; // The maximum amount of gas the user is willing to pay for a byte of pubdata. uint256 gasPerPubdataByteLimit; // The maximum fee per gas that the user is willing to pay. // It is akin to EIP1559's maxFeePerGas. uint256 maxFeePerGas; // The maximum priority fee per gas that the user is willing to pay. // It is akin to EIP1559's maxPriorityFeePerGas. uint256 maxPriorityFeePerGas; // The transaction's paymaster. If there is no paymaster, it is equal to 0. uint256 paymaster; // The nonce of the transaction. uint256 nonce; // The value to pass with the transaction. uint256 value; // In the future, we might want to add some // new fields to the struct. The `txData` struct // is to be passed to account and any changes to its structure // would mean a breaking change to these accounts. In order to prevent this, // we should keep some fields as "reserved". // It is also recommended that their length is fixed, since // it would allow easier proof integration (in case we will need // some special circuit for preprocessing transactions). uint256[4] reserved; // The transaction's calldata. bytes data; // The signature of the transaction. bytes signature; // The properly formatted hashes of bytecodes that must be published on L1 // with the inclusion of this transaction. Note, that a bytecode has been published // before, the user won't pay fees for its republishing. bytes32[] factoryDeps; // The input to the paymaster. bytes paymasterInput; // Reserved dynamic type for the future use-case. Using it should be avoided, // But it is still here, just in case we want to enable some additional functionality. bytes reservedDynamic; } /** * @author Matter Labs * @custom:security-contact [email protected] * @notice Library is used to help custom accounts to work with common methods for the Transaction type. */ library TransactionHelper { using SafeERC20 for IERC20; /// @notice The EIP-712 typehash for the contract's domain bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId)"); bytes32 internal constant EIP712_TRANSACTION_TYPE_HASH = keccak256( "Transaction(uint256 txType,uint256 from,uint256 to,uint256 gasLimit,uint256 gasPerPubdataByteLimit,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,uint256 paymaster,uint256 nonce,uint256 value,bytes data,bytes32[] factoryDeps,bytes paymasterInput)" ); /// @notice Whether the token is Ethereum. /// @param _addr The address of the token /// @return `true` or `false` based on whether the token is Ether. /// @dev This method assumes that address is Ether either if the address is 0 (for convenience) /// or if the address is the address of the L2BaseToken system contract. function isEthToken(uint256 _addr) internal pure returns (bool) { return _addr == uint256(uint160(address(BASE_TOKEN_SYSTEM_CONTRACT))) || _addr == 0; } /// @notice Calculate the suggested signed hash of the transaction, /// i.e. the hash that is signed by EOAs and is recommended to be signed by other accounts. function encodeHash(Transaction calldata _transaction) internal view returns (bytes32 resultHash) { if (_transaction.txType == LEGACY_TX_TYPE) { resultHash = _encodeHashLegacyTransaction(_transaction); } else if (_transaction.txType == EIP_712_TX_TYPE) { resultHash = _encodeHashEIP712Transaction(_transaction); } else if (_transaction.txType == EIP_1559_TX_TYPE) { resultHash = _encodeHashEIP1559Transaction(_transaction); } else if (_transaction.txType == EIP_2930_TX_TYPE) { resultHash = _encodeHashEIP2930Transaction(_transaction); } else { // Currently no other transaction types are supported. // Any new transaction types will be processed in a similar manner. revert UnsupportedTxType(_transaction.txType); } } /// @notice Encode hash of the ZKsync native transaction type. /// @return keccak256 hash of the EIP-712 encoded representation of transaction function _encodeHashEIP712Transaction(Transaction calldata _transaction) private view returns (bytes32) { bytes32 structHash = keccak256( // solhint-disable-next-line func-named-parameters abi.encode( EIP712_TRANSACTION_TYPE_HASH, _transaction.txType, _transaction.from, _transaction.to, _transaction.gasLimit, _transaction.gasPerPubdataByteLimit, _transaction.maxFeePerGas, _transaction.maxPriorityFeePerGas, _transaction.paymaster, _transaction.nonce, _transaction.value, EfficientCall.keccak(_transaction.data), keccak256(abi.encodePacked(_transaction.factoryDeps)), EfficientCall.keccak(_transaction.paymasterInput) ) ); bytes32 domainSeparator = keccak256( abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256("zkSync"), keccak256("2"), block.chainid) ); return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } /// @notice Encode hash of the legacy transaction type. /// @return keccak256 of the serialized RLP encoded representation of transaction function _encodeHashLegacyTransaction(Transaction calldata _transaction) private view returns (bytes32) { // Hash of legacy transactions are encoded as one of the: // - RLP(nonce, gasPrice, gasLimit, to, value, data, chainId, 0, 0) // - RLP(nonce, gasPrice, gasLimit, to, value, data) // // In this RLP encoding, only the first one above list appears, so we encode each element // inside list and then concatenate the length of all elements with them. bytes memory encodedNonce = RLPEncoder.encodeUint256(_transaction.nonce); // Encode `gasPrice` and `gasLimit` together to prevent "stack too deep error". bytes memory encodedGasParam; { bytes memory encodedGasPrice = RLPEncoder.encodeUint256(_transaction.maxFeePerGas); bytes memory encodedGasLimit = RLPEncoder.encodeUint256(_transaction.gasLimit); encodedGasParam = bytes.concat(encodedGasPrice, encodedGasLimit); } bytes memory encodedTo = RLPEncoder.encodeAddress(address(uint160(_transaction.to))); bytes memory encodedValue = RLPEncoder.encodeUint256(_transaction.value); // Encode only the length of the transaction data, and not the data itself, // so as not to copy to memory a potentially huge transaction data twice. bytes memory encodedDataLength; { // Safe cast, because the length of the transaction data can't be so large. uint64 txDataLen = uint64(_transaction.data.length); if (txDataLen != 1) { // If the length is not equal to one, then only using the length can it be encoded definitely. encodedDataLength = RLPEncoder.encodeNonSingleBytesLen(txDataLen); } else if (_transaction.data[0] >= 0x80) { // If input is a byte in [0x80, 0xff] range, RLP encoding will concatenates 0x81 with the byte. encodedDataLength = hex"81"; } // Otherwise the length is not encoded at all. } // Encode `chainId` according to EIP-155, but only if the `chainId` is specified in the transaction. bytes memory encodedChainId; if (_transaction.reserved[0] != 0) { encodedChainId = bytes.concat(RLPEncoder.encodeUint256(block.chainid), hex"80_80"); } bytes memory encodedListLength; unchecked { uint256 listLength = encodedNonce.length + encodedGasParam.length + encodedTo.length + encodedValue.length + encodedDataLength.length + _transaction.data.length + encodedChainId.length; // Safe cast, because the length of the list can't be so large. encodedListLength = RLPEncoder.encodeListLen(uint64(listLength)); } return keccak256( // solhint-disable-next-line func-named-parameters bytes.concat( encodedListLength, encodedNonce, encodedGasParam, encodedTo, encodedValue, encodedDataLength, _transaction.data, encodedChainId ) ); } /// @notice Encode hash of the EIP2930 transaction type. /// @return keccak256 of the serialized RLP encoded representation of transaction function _encodeHashEIP2930Transaction(Transaction calldata _transaction) private view returns (bytes32) { // Hash of EIP2930 transactions is encoded the following way: // H(0x01 || RLP(chain_id, nonce, gas_price, gas_limit, destination, amount, data, access_list)) // // Note, that on ZKsync access lists are not supported and should always be empty. // Encode all fixed-length params to avoid "stack too deep error" bytes memory encodedFixedLengthParams; { bytes memory encodedChainId = RLPEncoder.encodeUint256(block.chainid); bytes memory encodedNonce = RLPEncoder.encodeUint256(_transaction.nonce); bytes memory encodedGasPrice = RLPEncoder.encodeUint256(_transaction.maxFeePerGas); bytes memory encodedGasLimit = RLPEncoder.encodeUint256(_transaction.gasLimit); bytes memory encodedTo = RLPEncoder.encodeAddress(address(uint160(_transaction.to))); bytes memory encodedValue = RLPEncoder.encodeUint256(_transaction.value); // solhint-disable-next-line func-named-parameters encodedFixedLengthParams = bytes.concat( encodedChainId, encodedNonce, encodedGasPrice, encodedGasLimit, encodedTo, encodedValue ); } // Encode only the length of the transaction data, and not the data itself, // so as not to copy to memory a potentially huge transaction data twice. bytes memory encodedDataLength; { // Safe cast, because the length of the transaction data can't be so large. uint64 txDataLen = uint64(_transaction.data.length); if (txDataLen != 1) { // If the length is not equal to one, then only using the length can it be encoded definitely. encodedDataLength = RLPEncoder.encodeNonSingleBytesLen(txDataLen); } else if (_transaction.data[0] >= 0x80) { // If input is a byte in [0x80, 0xff] range, RLP encoding will concatenates 0x81 with the byte. encodedDataLength = hex"81"; } // Otherwise the length is not encoded at all. } // On ZKsync, access lists are always zero length (at least for now). bytes memory encodedAccessListLength = RLPEncoder.encodeListLen(0); bytes memory encodedListLength; unchecked { uint256 listLength = encodedFixedLengthParams.length + encodedDataLength.length + _transaction.data.length + encodedAccessListLength.length; // Safe cast, because the length of the list can't be so large. encodedListLength = RLPEncoder.encodeListLen(uint64(listLength)); } return keccak256( // solhint-disable-next-line func-named-parameters bytes.concat( "\x01", encodedListLength, encodedFixedLengthParams, encodedDataLength, _transaction.data, encodedAccessListLength ) ); } /// @notice Encode hash of the EIP1559 transaction type. /// @return keccak256 of the serialized RLP encoded representation of transaction function _encodeHashEIP1559Transaction(Transaction calldata _transaction) private view returns (bytes32) { // Hash of EIP1559 transactions is encoded the following way: // H(0x02 || RLP(chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list)) // // Note, that on ZKsync access lists are not supported and should always be empty. // Encode all fixed-length params to avoid "stack too deep error" bytes memory encodedFixedLengthParams; { bytes memory encodedChainId = RLPEncoder.encodeUint256(block.chainid); bytes memory encodedNonce = RLPEncoder.encodeUint256(_transaction.nonce); bytes memory encodedMaxPriorityFeePerGas = RLPEncoder.encodeUint256(_transaction.maxPriorityFeePerGas); bytes memory encodedMaxFeePerGas = RLPEncoder.encodeUint256(_transaction.maxFeePerGas); bytes memory encodedGasLimit = RLPEncoder.encodeUint256(_transaction.gasLimit); bytes memory encodedTo = RLPEncoder.encodeAddress(address(uint160(_transaction.to))); bytes memory encodedValue = RLPEncoder.encodeUint256(_transaction.value); // solhint-disable-next-line func-named-parameters encodedFixedLengthParams = bytes.concat( encodedChainId, encodedNonce, encodedMaxPriorityFeePerGas, encodedMaxFeePerGas, encodedGasLimit, encodedTo, encodedValue ); } // Encode only the length of the transaction data, and not the data itself, // so as not to copy to memory a potentially huge transaction data twice. bytes memory encodedDataLength; { // Safe cast, because the length of the transaction data can't be so large. uint64 txDataLen = uint64(_transaction.data.length); if (txDataLen != 1) { // If the length is not equal to one, then only using the length can it be encoded definitely. encodedDataLength = RLPEncoder.encodeNonSingleBytesLen(txDataLen); } else if (_transaction.data[0] >= 0x80) { // If input is a byte in [0x80, 0xff] range, RLP encoding will concatenates 0x81 with the byte. encodedDataLength = hex"81"; } // Otherwise the length is not encoded at all. } // On ZKsync, access lists are always zero length (at least for now). bytes memory encodedAccessListLength = RLPEncoder.encodeListLen(0); bytes memory encodedListLength; unchecked { uint256 listLength = encodedFixedLengthParams.length + encodedDataLength.length + _transaction.data.length + encodedAccessListLength.length; // Safe cast, because the length of the list can't be so large. encodedListLength = RLPEncoder.encodeListLen(uint64(listLength)); } return keccak256( // solhint-disable-next-line func-named-parameters bytes.concat( "\x02", encodedListLength, encodedFixedLengthParams, encodedDataLength, _transaction.data, encodedAccessListLength ) ); } /// @notice Processes the common paymaster flows, e.g. setting proper allowance /// for tokens, etc. For more information on the expected behavior, check out /// the "Paymaster flows" section in the documentation. function processPaymasterInput(Transaction calldata _transaction) internal { if (_transaction.paymasterInput.length < 4) { revert InvalidInput(); } bytes4 paymasterInputSelector = bytes4(_transaction.paymasterInput[0:4]); if (paymasterInputSelector == IPaymasterFlow.approvalBased.selector) { if (_transaction.paymasterInput.length < 68) { revert InvalidInput(); } // While the actual data consists of address, uint256 and bytes data, // the data is needed only for the paymaster, so we ignore it here for the sake of optimization (address token, uint256 minAllowance) = abi.decode(_transaction.paymasterInput[4:68], (address, uint256)); address paymaster = address(uint160(_transaction.paymaster)); uint256 currentAllowance = IERC20(token).allowance(address(this), paymaster); if (currentAllowance < minAllowance) { // Some tokens, e.g. USDT require that the allowance is firsty set to zero // and only then updated to the new value. IERC20(token).safeApprove(paymaster, 0); IERC20(token).safeApprove(paymaster, minAllowance); } } else if (paymasterInputSelector == IPaymasterFlow.general.selector) { // Do nothing. general(bytes) paymaster flow means that the paymaster must interpret these bytes on his own. } else { revert UnsupportedPaymasterFlow(); } } /// @notice Pays the required fee for the transaction to the bootloader. /// @dev Currently it pays the maximum amount "_transaction.maxFeePerGas * _transaction.gasLimit", /// it will change in the future. function payToTheBootloader(Transaction calldata _transaction) internal returns (bool success) { address bootloaderAddr = BOOTLOADER_FORMAL_ADDRESS; uint256 amount = _transaction.maxFeePerGas * _transaction.gasLimit; assembly { success := call(gas(), bootloaderAddr, amount, 0, 0, 0, 0) } } // Returns the balance required to process the transaction. function totalRequiredBalance(Transaction calldata _transaction) internal pure returns (uint256 requiredBalance) { if (address(uint160(_transaction.paymaster)) != address(0)) { // Paymaster pays for the fee requiredBalance = _transaction.value; } else { // The user should have enough balance for both the fee and the value of the transaction requiredBalance = _transaction.maxFeePerGas * _transaction.gasLimit + _transaction.value; } } }
// 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.20; import {EfficientCall} from "./EfficientCall.sol"; import {MalformedBytecode, BytecodeError, Overflow} from "../SystemContractErrors.sol"; /** * @author Matter Labs * @custom:security-contact [email protected] * @dev Common utilities used in ZKsync system contracts */ library Utils { /// @dev Bit mask of bytecode hash "isConstructor" marker bytes32 internal constant IS_CONSTRUCTOR_BYTECODE_HASH_BIT_MASK = 0x00ff000000000000000000000000000000000000000000000000000000000000; /// @dev Bit mask to set the "isConstructor" marker in the bytecode hash bytes32 internal constant SET_IS_CONSTRUCTOR_MARKER_BIT_MASK = 0x0001000000000000000000000000000000000000000000000000000000000000; function safeCastToU128(uint256 _x) internal pure returns (uint128) { if (_x > type(uint128).max) { revert Overflow(); } return uint128(_x); } function safeCastToU32(uint256 _x) internal pure returns (uint32) { if (_x > type(uint32).max) { revert Overflow(); } return uint32(_x); } function safeCastToU24(uint256 _x) internal pure returns (uint24) { if (_x > type(uint24).max) { revert Overflow(); } return uint24(_x); } /// @return codeLength The bytecode length in bytes function bytecodeLenInBytes(bytes32 _bytecodeHash) internal pure returns (uint256 codeLength) { codeLength = bytecodeLenInWords(_bytecodeHash) << 5; // _bytecodeHash * 32 } /// @return codeLengthInWords The bytecode length in machine words function bytecodeLenInWords(bytes32 _bytecodeHash) internal pure returns (uint256 codeLengthInWords) { unchecked { codeLengthInWords = uint256(uint8(_bytecodeHash[2])) * 256 + uint256(uint8(_bytecodeHash[3])); } } /// @notice Denotes whether bytecode hash corresponds to a contract that already constructed function isContractConstructed(bytes32 _bytecodeHash) internal pure returns (bool) { return _bytecodeHash[1] == 0x00; } /// @notice Denotes whether bytecode hash corresponds to a contract that is on constructor or has already been constructed function isContractConstructing(bytes32 _bytecodeHash) internal pure returns (bool) { return _bytecodeHash[1] == 0x01; } /// @notice Sets "isConstructor" flag to TRUE for the bytecode hash /// @param _bytecodeHash The bytecode hash for which it is needed to set the constructing flag /// @return The bytecode hash with "isConstructor" flag set to TRUE function constructingBytecodeHash(bytes32 _bytecodeHash) internal pure returns (bytes32) { // Clear the "isConstructor" marker and set it to 0x01. return constructedBytecodeHash(_bytecodeHash) | SET_IS_CONSTRUCTOR_MARKER_BIT_MASK; } /// @notice Sets "isConstructor" flag to FALSE for the bytecode hash /// @param _bytecodeHash The bytecode hash for which it is needed to set the constructing flag /// @return The bytecode hash with "isConstructor" flag set to FALSE function constructedBytecodeHash(bytes32 _bytecodeHash) internal pure returns (bytes32) { return _bytecodeHash & ~IS_CONSTRUCTOR_BYTECODE_HASH_BIT_MASK; } /// @notice Validate the bytecode format and calculate its hash. /// @param _bytecode The bytecode to hash. /// @return hashedBytecode The 32-byte hash of the bytecode. /// Note: The function reverts the execution if the bytecode has non expected format: /// - Bytecode bytes length is not a multiple of 32 /// - Bytecode bytes length is not less than 2^21 bytes (2^16 words) /// - Bytecode words length is not odd function hashL2Bytecode(bytes calldata _bytecode) internal view returns (bytes32 hashedBytecode) { // Note that the length of the bytecode must be provided in 32-byte words. if (_bytecode.length % 32 != 0) { revert MalformedBytecode(BytecodeError.Length); } uint256 lengthInWords = _bytecode.length / 32; // bytecode length must be less than 2^16 words if (lengthInWords >= 2 ** 16) { revert MalformedBytecode(BytecodeError.NumberOfWords); } // bytecode length in words must be odd if (lengthInWords % 2 == 0) { revert MalformedBytecode(BytecodeError.WordsMustBeOdd); } hashedBytecode = EfficientCall.sha(_bytecode) & 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // Setting the version of the hash hashedBytecode = (hashedBytecode | bytes32(uint256(1 << 248))); // Setting the length hashedBytecode = hashedBytecode | bytes32(lengthInWords << 224); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) // 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.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Permit.sol) // 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.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) // 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.0; import {IERC20} from "../IERC20.sol"; import {IERC20Permit} from "../extensions/IERC20Permit.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn( token, abi.encodeWithSelector(token.transfer.selector, to, value) ); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn( token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value) ); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn( token, abi.encodeWithSelector(token.approve.selector, spender, value) ); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn( token, abi.encodeWithSelector( token.approve.selector, spender, newAllowance ) ); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require( oldAllowance >= value, "SafeERC20: decreased allowance below zero" ); uint256 newAllowance = oldAllowance - value; _callOptionalReturn( token, abi.encodeWithSelector( token.approve.selector, spender, newAllowance ) ); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit({owner: owner, spender: spender, value: value, deadline : deadline, v: v, r: r, s: s}); uint256 nonceAfter = token.nonces(owner); require( nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed" ); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall( data, "SafeERC20: low-level call failed" ); if (returndata.length > 0) { // Return data is optional require( abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed" ); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) // 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.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require( address(this).balance >= amount, "Address: insufficient balance" ); (bool success, ) = recipient.call{value: amount}(""); require( success, "Address: unable to send value, recipient may have reverted" ); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue( target, data, 0, "Address: low-level call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue( target, data, value, "Address: low-level call with value failed" ); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require( address(this).balance >= value, "Address: insufficient balance for call" ); (bool success, bytes memory returndata) = target.call{value: value}( data ); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall( target, data, "Address: low-level static call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall( target, data, "Address: low-level delegate call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
{ "codegen": "yul", "enableEraVMExtensions": true, "evmVersion": "paris", "forceEVMLA": false, "libraries": {}, "metadata": {}, "optimizer": { "disable_system_request_memoization": true, "enabled": true, "fallback_to_optimizing_for_size": false, "mode": "3" }, "outputSelection": { "*": { "*": [ "abi", "metadata" ], "": [ "ast" ] } }, "remappings": [ "@openzeppelin/contracts-v4/=lib/openzeppelin-contracts-v4/contracts/", "@openzeppelin/contracts-upgradeable-v4/=lib/openzeppelin-contracts-upgradeable-v4/contracts/", "ds-test/=lib/openzeppelin-contracts-upgradeable-v4/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts-upgradeable-v4/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts-upgradeable-v4/=lib/openzeppelin-contracts-upgradeable-v4/", "openzeppelin-contracts-v4/=lib/openzeppelin-contracts-v4/" ], "suppressedErrors": [ "sendtransfer" ], "viaIR": false }
Contract ABI
API[{"inputs":[],"name":"CallerMustBeBootloader","type":"error"},{"inputs":[],"name":"CallerMustBeSystemContract","type":"error"},{"inputs":[],"name":"FailedToChargeGas","type":"error"},{"inputs":[],"name":"Keccak256InvalidReturnData","type":"error"},{"inputs":[],"name":"Overflow","type":"error"},{"inputs":[{"internalType":"enum PubdataField","name":"","type":"uint8"},{"internalType":"bytes32","name":"expected","type":"bytes32"},{"internalType":"bytes32","name":"actual","type":"bytes32"}],"name":"ReconstructionMismatch","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"_bytecodeHash","type":"bytes32"}],"name":"BytecodeL1PublicationRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"bytes32","name":"_hash","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"_message","type":"bytes"}],"name":"L1MessageSent","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint8","name":"l2ShardId","type":"uint8"},{"internalType":"bool","name":"isService","type":"bool"},{"internalType":"uint16","name":"txNumberInBlock","type":"uint16"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"bytes32","name":"value","type":"bytes32"}],"indexed":false,"internalType":"struct L2ToL1Log","name":"_l2log","type":"tuple"}],"name":"L2ToL1LogSent","type":"event"},{"inputs":[{"internalType":"address","name":"_l2DAValidator","type":"address"},{"internalType":"bytes","name":"_operatorInput","type":"bytes"}],"name":"publishPubdataAndClearState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_bytecodeHash","type":"bytes32"}],"name":"requestBytecodeL1Publication","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_isService","type":"bool"},{"internalType":"bytes32","name":"_key","type":"bytes32"},{"internalType":"bytes32","name":"_value","type":"bytes32"}],"name":"sendL2ToL1Log","outputs":[{"internalType":"uint256","name":"logIdInMerkleTree","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_message","type":"bytes"}],"name":"sendToL1","outputs":[{"internalType":"bytes32","name":"hash","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
e9f18c170000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000007c0000000000000000000000000000000000000000000000000000000000000088000000000000000000000000000000000000000000000000000000000000009400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000ac00000000000000000000000000000000000000000000000000000000000000b800000000000000000000000000000000000000000000000000000000000000c400000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000dc00000000000000000000000000000000000000000000000000000000000000e800000000000000000000000000000000000000000000000000000000000000f40000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010c001000007f845e3f2ab16646632231e4fee11627449b45067fa0e7c76ba114d0600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000100001147fcb33fbc266df8067be8b51d68ad9362a6204de5a6b2279c613d1200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000010000179d3c90b59acbc8fbda5ba2389cc80dfa840840e5183d44ea3c9b013100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000100008f337dc5cc92411071569be5cd4bfd755adf20021c8a0e316c4834c4ef00000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000010000d941fe2d54aa725915db7d63795e02ced38fa2709d736631e30792ccb200000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000001000007f845e3f2ab16646632231e4fee11627449b45067fa0e7c76ba114d0600000000000000000000000000000000000000000000000000000000000080010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000001000075c32c6af70ed4fd798a3fca41f2984e7440e2d2937858d700637e065500000000000000000000000000000000000000000000000000000000000080020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000010000e52e563c15152eb655ea2d1b633c1409b61afa74065d05e93107a7e22300000000000000000000000000000000000000000000000000000000000080030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000100007d4be0212415ae3920fbd92c2547f5419ac8da07bb7e29488472a434a200000000000000000000000000000000000000000000000000000000000080040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000100003d467f114197fad7d1e6bb58867710524d5c8d200558a213f5429cbf8400000000000000000000000000000000000000000000000000000000000080050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000100055578bdf1a737843d2278c672bfa9be2c17183a7e9b00052845aa5d240a00000000000000000000000000000000000000000000000000000000000080060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000100028debc3f96ddf2c6630fb28ac7b4ae198ad453fdc08df2e81e6d2a4aa0b00000000000000000000000000000000000000000000000000000000000080080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000001000063d13c3fdbd042669053befb649f89c1dd0de3d7a0542486e89b6a7f0000000000000000000000000000000000000000000000000000000000000080090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000001000101dbb3209311751d4f335ac6909943e19a1c3d26cdd27db01adb509db0000000000000000000000000000000000000000000000000000000000000800a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000001000181e472c23b9b5e9b971dec1971183ab06fb5932ea469ee207cc4a668da000000000000000000000000000000000000000000000000000000000000800b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000010007c95cdffb79ed99ad5fb842d3bab4084e2d49028df8ee3f7c2d543f7ebe000000000000000000000000000000000000000000000000000000000000800c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000100001752ddb6f7d76adaf32594816c0bda5b9c17d6fd86e90a06acba2e4cb6000000000000000000000000000000000000000000000000000000000000800d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000010001670943abd41e5b14499ae7bd0b99406a7d3cc406d9251c138d87f573c0000000000000000000000000000000000000000000000000000000000000800e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000001000055de10df9214a2628ab870a3bc2154a6e7f8c0479a7bad15c875aec050000000000000000000000000000000000000000000000000000000000000800f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000001000021e3954694ddb9479f31cabe797467b4ea3b92ab64fd81e9b5e53f130000000000000000000000000000000000000000000000000000000000000080100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x0002000000000002000e0000000000020001000000010355000000000301001900000060053002700000023c0050019d0000008004000039000000400040043f0000023c035001970000000102200190000000310000c13d000000040230008c000001250000413d000000000201043b000000e0022002700000023e0620009c000000390000213d000002410420009c000000710000613d000002420220009c000001250000c13d0000000002000416000000000202004b000001250000c13d000000040230008a000000600220008c000001250000413d0000000401100370000000000301043b000000000103004b0000000001000019000000010100c039000000000113004b000001250000c13d0000000002000411000002810120009c000000ec0000413d0000025701000041000000800010043f0000002001000039000000840010043f0000003401000039000000a40010043f0000028301000041000000c40010043f0000028401000041000000e40010043f0000028501000041000008ec000104300000000001000416000000000101004b000001250000c13d0000002001000039000001000010044300000120000004430000023d01000041000008eb0001042e0000023f0620009c000000ae0000613d000002400220009c000001250000c13d0000000002000416000000000202004b000001250000c13d000000040230008a000000200220008c000001250000413d0000000402100370000000000202043b000002430620009c000001250000213d00000023062000390000024407000041000000000836004b000000000800001900000000080780190000024406600197000000000906004b0000000007008019000002440660009c000000000708c019000000000607004b000001250000c13d0000000406200039000000000661034f000000000706043b000002430670009c000001250000213d00000024082000390000000002870019000000000323004b000001250000413d00000000090004140000000003000414000002450630009c0000014a0000413d000000440140003900000259020000410000000000210435000000240140003900000008020000390000000000210435000002570100004100000000001404350000000401400039000000200200003900000000002104350000023c010000410000023c0240009c0000000004018019000000400140021000000258011001c7000008ec000104300000000002000416000000000202004b000001250000c13d000000040230008a000000200220008c000001250000413d0000000002000411000080040220008c000000e20000c13d0000000401100370000000000201043b0000000301000039000d00000001001d000000000101041a000000a00010043f000e00000002001d000000c00020043f0000004001000039000000800010043f000000e001000039000000400010043f0000023c0100004100000000020004140000023c0320009c0000000002018019000000c00120021000000287011001c7000080100200003908ea08e00000040f0000000102200190000001250000613d000000000101043b0000000d02000029000000000012041b00000000010004130000023c031001970000000e06000029000000e0016002700000ffff0210018f000000050120021000000004041001bf00000000514300a900000000544100d9000000000343004b0000019d0000c13d0000000102200270000000010320003900000007423000c9000000075420011a000000000343004b0000019d0000c13d0000000001210019000002880210009c000001df0000413d000000400100043d00000044021000390000025903000041000000000032043500000024021000390000000803000039000005ee0000013d0000000002000416000000000202004b000001250000c13d000000040230008a000000200220008c000001250000413d0000000402100370000000000202043b000002430420009c000001250000213d00000023042000390000024405000041000000000634004b000000000600001900000000060580190000024404400197000000000704004b0000000005008019000002440440009c000000000506c019000000000405004b000001250000c13d0000000404200039000000000541034f000000000505043b000b00000005001d000002430550009c000001250000213d0000002402200039000a00000002001d0000000b02200029000000000232004b000001250000213d0000000002000411000080010220008c000001a30000c13d0000000b02000029000000040220008c000001250000413d0000002002400039000000000221034f000000000402043b0000025c0240009c0000029b0000413d0000025701000041000000800010043f0000002001000039000000840010043f0000001401000039000000a40010043f0000028001000041000000e90000013d0000025701000041000000800010043f0000002001000039000000840010043f0000001401000039000000a40010043f0000028601000041000000c40010043f0000025b01000041000008ec00010430000e00000003001d000d00000002001d0000024b01000041000000800010043f0000023c0100004100000000020004140000023c0320009c0000000002018019000000c00120021000000282011001c70000800b0200003908ea08e00000040f000000000301001900000060033002700000023c03300197000000200430008c000000000403001900000020040080390000001f0540018f00000005064002720000010a0000613d00000000070000190000000508700210000000000981034f000000000909043b000000800880003900000000009804350000000107700039000000000867004b000001020000413d000000000705004b000001190000613d0000000506600210000000000761034f00000003055002100000008006600039000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f00000000005604350000000102200190000001270000613d0000001f01400039000000600210018f00000080082001bf000000400080043f000000200130008c0000000e05000029000001250000413d000000800100043d0000ffff0310008c000001ab0000a13d0000000001000019000008ec00010430000000400200043d0000001f0430018f0000000505300272000001340000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b0000012c0000413d000000000604004b000001430000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f00000000001504350000023c010000410000023c0420009c000000000201801900000040012002100000006002300210000000000121019f000008ec00010430000e00000009001d000d00000007001d000c00000008001d0000023c04800197000000000141034f00000000022500490000023c0220019700000000012103df000000c002300210000002460220019700000247022001c700000000012103af000080100200003908ea08e50000040f000000000301001900000060033002700000023c033001970000000102200190000001ea0000613d0000003f023000390000024804200197000000400200043d0000000004420019000000000524004b00000000050000190000000105004039000002430640009c000001db0000213d0000000105500190000001db0000c13d000000400040043f00000000043204360000001f053000390000000505500272000001780000613d00000000060000310000000106600367000000000700001900000005087002100000000009840019000000000886034f000000000808043b00000000008904350000000107700039000000000857004b000001700000413d000000000500004b0000017a0000613d0000001f0530018f00000005033002720000000e09000029000001870000613d000000000600001900000005076002100000000008740019000000000771034f000000000707043b00000000007804350000000106600039000000000736004b0000017f0000413d000000000605004b000001960000613d0000000503300210000000000131034f00000000033400190000000305500210000000000603043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f00000000001304350000000001020433000000200110008c000005e80000c13d00000000040404330000000002000414000000000129004b000003ad0000813d0000027e0100004100000000001004350000001101000039000000040010043f0000027f01000041000008ec000104300000025701000041000000800010043f0000002001000039000000840010043f0000001f01000039000000a40010043f0000025a01000041000000e90000013d0000014003200039000000400030043f0000000000080435000000a003200039000b00000003001d00000000005304350000024f04000041000000000305004b0000000004006019000000e003200039000e00000003001d0000000d090000290000000000930435000000c003200039000900000003001d000000000013043500000001030003670000002405300370000000000505043b000001200720003900000100022001bf000a00000002001d00000000005204350000004402300370000000000602043b000c00000007001d00000000006704350000000002080433000000f807200210000000400200043d0000002003200039000000000073043500000021072000390000000000470435000000f00110021000000022042000390000000000140435000000600190021000000024042000390000000000140435000000580120003900000000006104350000003801200039000000000051043500000058010000390000000000120435000002500120009c000002050000a13d0000027e0100004100000000001004350000004101000039000001a00000013d00000028011000390000000002100420000000400100043d000000000202004b000002880000c13d00000044021000390000025603000041000000000032043500000024021000390000001403000039000005ee0000013d0000001f0430018f0000000502300272000001f50000613d00000000050000190000000506500210000000000761034f000000000707043b00000000007604350000000105500039000000000625004b000001ee0000413d000000000504004b000002030000613d00000003044002100000000502200210000000000502043300000000054501cf000000000545022f000000000121034f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001204350000006001300210000008ec000104300000008001200039000000400010043f0000023c010000410000023c0430009c0000000003018019000000400330021000000000020204330000023c0420009c00000000020180190000006002200210000000000232019f00000000030004140000023c0430009c0000000003018019000000c001300210000000000121019f0000024a011001c70000801002000039000d00000008001d08ea08e00000040f0000000102200190000001250000613d000000000201043b000000400100043d0000004003100039000000000400041a00000000002304350000002002100039000000000042043500000040030000390000000000310435000002490310009c000001db0000213d0000006003100039000000400030043f0000023c030000410000023c0420009c0000000002038019000000400220021000000000010104330000023c0410009c00000000010380190000006001100210000000000121019f00000000020004140000023c0420009c0000000002038019000000c002200210000000000112019f0000024a011001c7000080100200003908ea08e00000040f0000000102200190000001250000613d000000000101043b000000000010041b0000000103000039000000000203041a000000010100008a000800000002001d000000000112004b0000019d0000613d00000008010000290000000101100039000000000013041b0000000d010000290000000001010433000000ff0110018f000000400200043d00000000011204360000000b040000290000000004040433000000000404004b0000000004000019000000010400c0390000000000410435000000090100002900000000010104330000ffff0110018f000000400420003900000000001404350000000e0100002900000000010104330000024e01100197000000600420003900000000001404350000000a010000290000000001010433000000800420003900000000001404350000000c010000290000000001010433000000a00420003900000000001404350000023c050000410000023c0120009c000000000205801900000000010004140000023c0410009c00000000010580190000004002200210000000c001100210000000000121019f00000251011001c70000800d02000039000002520400004108ea08db0000040f0000000101200190000001250000613d00000078010000390000000003100420000000400100043d0000023c0210009c0000023c0200004100000000020140190000004002200210000000000303004b000005020000c13d0000004403100039000002560400004100000000004304350000002403100039000000140400003900000000004304350000025703000041000000000031043500000004011000390000002003000039000000000031043500000258012001c7000008ec0001043000000000006104350000023c0200004100000000030004140000023c0430009c00000000030280190000023c0410009c00000000010280190000004001100210000000c002300210000000000112019f00000289011001c70000800d0200003900000001030000390000028a0400004108ea08db0000040f0000000101200190000001250000613d0000000001000019000008eb0001042e000000000131034f000600000004001d000000e0064002700000025d02000041000000400020043f0000080002000039000700000002001d000000800020043f000000a00200003900000000030000190000000504300210000000000441034f000000000404043b00000000024204360000000103300039000008000430008c000002a50000413d00000004020000390000000601000029000002470110009c00000000080000190000030a0000813d000000000100041a000000000118004b000003980000c13d000d00000002001d0000000601000029000002610110009c000002c20000213d0000026201000041000000800200043d000000000262004b000003060000a13d0000000502600210000000a0022000390000000000120435000007ff0260008c0000000106600039000002b90000413d000900400000003d000880100000003d0000000701000029000600000001001d000700010010027800000000040000190000000101400210000000800200043d000000000312004b000003060000a13d00000001011001bf000000000212004b000003060000a13d0000000501100210000000a0011000390000000002010433000e00000004001d0000000601400210000000a001100039000c00000001001d0000000003010433000000400100043d000000400410003900000000002404350000002002100039000000000032043500000009030000290000000000310435000002490310009c000001db0000213d0000006003100039000000400030043f0000023c0320009c0000023c040000410000000002048019000000400220021000000000010104330000023c0310009c00000000010480190000006001100210000000000121019f00000000020004140000023c0320009c0000000002048019000000c002200210000000000112019f0000024a011001c7000000080200002908ea08e00000040f0000000102200190000001250000613d000000800200043d0000000e04000029000000000242004b000003060000a13d00000005024002100000000c02200069000000000101043b00000000001204350000000104400039000000070140006c000002c80000413d0000000601000029000000030110008c000002c40000213d000000800100043d000000000101004b000005060000c13d0000027e0100004100000000001004350000003201000039000001a00000013d0000000401000039000900590000009200000000070000190000000008000019000800000006001d0000005803100039000d00000003001d0000000b0230006c000001250000213d0000000a0210002900000000010004140000023c03200197000000090420006c0000019d0000213d00000058022000390000000004000031000000000524004b0000019d0000413d000c00000008001d000e00000007001d00000001033003670000023c0510009c000000a70000213d00000000022400490000023c0220019700000000022303df000000c001100210000002460110019700000247011001c700000000011203af000080100200003908ea08e50000040f000000000301001900000060033002700000023c033001970000000102200190000004ca0000613d0000003f023000390000024804200197000000400200043d0000000004420019000000000524004b00000000050000190000000105004039000002430640009c000001db0000213d0000000105500190000001db0000c13d000000400040043f00000000043204360000001f0530003900000005055002720000034a0000613d00000000060000310000000106600367000000000700001900000005087002100000000009840019000000000886034f000000000808043b00000000008904350000000107700039000000000857004b000003420000413d000000000500004b0000034c0000613d0000000505300272000003570000613d000000000600001900000005076002100000000008740019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b0000034f0000413d0000001f03300190000003660000613d0000000505500210000000000151034f00000000055400190000000303300210000000000605043300000000063601cf000000000636022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000161019f00000000001504350000000001020433000000200110008c0000000e030000290000000c05000029000005e80000c13d000000800100043d000000000131004b000003060000a13d00000000020404330000000501300210000000a0011000390000000000210435000000400100043d00000040031000390000000000230435000000400200003900000000022104360000000000520435000002490310009c000001db0000213d0000006003100039000000400030043f0000023c0320009c0000023c040000410000000002048019000000400220021000000000010104330000023c0310009c00000000010480190000006001100210000000000121019f00000000020004140000023c0320009c0000000002048019000000c002200210000000000112019f0000024a011001c7000080100200003908ea08e00000040f000000010220019000000008060000290000000e07000029000001250000613d000000000801043b0000000107700039000000000167004b0000000d0200002900000000010200190000030f0000413d000002b10000013d000000400100043d00000064021000390000025e03000041000000000032043500000044021000390000025f03000041000000000032043500000024021000390000003c030000390000000000320435000002570200004100000000002104350000000402100039000000200300003900000000003204350000023c020000410000023c0310009c0000000001028019000000400110021000000260011001c7000008ec00010430000800000002001d0000000201000039000b00000001001d000000000301041a000000400100043d0000004002100039000a00000004001d0000000000420435000000200210003900000000003204350000004003000039000900000003001d0000000000310435000002490310009c000001db0000213d0000006003100039000000400030043f0000023c040000410000023c0320009c0000000002048019000000400220021000000000010104330000023c0310009c00000000010480190000006001100210000000000121019f00000000020004140000023c0320009c0000000002048019000000c002200210000000000112019f0000024a011001c7000080100200003908ea08e00000040f0000000102200190000001250000613d000000000101043b0000000b02000029000000000012041b0000024b01000041000000400400043d000b00000004001d000000000014043500000000010004140000023c0210009c0000023c0300004100000000010380190000023c0240009c00000000030440190000004002300210000000c001100210000000000121019f0000024c011001c70000800b0200003908ea08e00000040f0000000b0a000029000000000301001900000060033002700000023c03300197000000200430008c000000000403001900000020040080390000001f0540018f0000000506400272000003f70000613d0000000007000019000000050870021000000000098a0019000000000881034f000000000808043b00000000008904350000000107700039000000000867004b000003ef0000413d00000000090a0019000000000705004b000004070000613d0000000506600210000000000761034f00000000066900190000000305500210000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f00000000005604350000000102200190000004e50000613d0000001f01400039000000600110018f0000000002910019000000000112004b00000000010000190000000101004039000700000002001d000002430220009c000001db0000213d0000000101100190000001db0000c13d0000000701000029000000400010043f000000200130008c000001250000413d00000000010904330000ffff0210008c000001250000213d00000007020000290000024d0220009c000001db0000213d0000000703000029000000c002300039000000400020043f00000000040004100000024e024001970000006005300039000500000005001d000000000025043500000020053000390000000102000039000b00000002001d000300000005001d0000000000250435000000a0023000390000000a07000029000600000002001d000000000072043500000080023000390000000008000411000400000002001d000000000082043500000000000304350000004002300039000200000002001d0000000000120435000000400200043d0000002003200039000000000003043500000021052000390000024f060000410000000000650435000000f0011002100000002205200039000000000015043500000060014002100000002404200039000000000014043500000058012000390000000000710435000000580100003900000000001204350000003801200039000100000008001d0000000000810435000002500120009c000001db0000213d0000008001200039000000400010043f0000023c010000410000023c0430009c0000000003018019000000400330021000000000020204330000023c0420009c00000000020180190000006002200210000000000232019f00000000030004140000023c0430009c0000000003018019000000c001300210000000000121019f0000024a011001c7000080100200003908ea08e00000040f0000000102200190000001250000613d000000000201043b000000400100043d0000004003100039000000000400041a00000000002304350000002002100039000000000042043500000009030000290000000000310435000002490310009c000001db0000213d0000006003100039000000400030043f0000023c030000410000023c0420009c0000000002038019000000400220021000000000010104330000023c0410009c00000000010380190000006001100210000000000121019f00000000020004140000023c0420009c0000000002038019000000c002200210000000000112019f0000024a011001c7000080100200003908ea08e00000040f0000000102200190000001250000613d000000000101043b000000000010041b0000000b01000029000000000101041a000000010200008a000000000221004b0000019d0000613d00000001011000390000000b03000029000000000013041b00000007010000290000000001010433000000ff0110018f000000400200043d000000000112043600000003040000290000000004040433000000000404004b0000000004000019000000010400c0390000000000410435000000020100002900000000010104330000ffff0110018f00000040042000390000000000140435000000050100002900000000010104330000024e0110019700000060042000390000000000140435000000040100002900000000010104330000008004200039000000000014043500000006010000290000000001010433000000a00420003900000000001404350000023c010000410000023c0420009c000000000201801900000000050004140000023c0450009c00000000050180190000004001200210000000c002500210000000000112019f00000251011001c70000800d02000039000002520400004108ea08db0000040f00000001012001900000000d01000029000001250000613d0000005c0210003900000000010004130000023c0310019700000000412300a90000025302200197000002530410019700000000422400d9000000000223004b00000008030000290000019d0000c13d0000000e02300069000000a001100039000000000121001a0000019d0000413d000002450210009c000006c80000413d000000400400043d000000600000013d0000001f0430018f0000000502300272000004d50000613d00000000050000190000000506500210000000000761034f000000000707043b00000000007604350000000105500039000000000625004b000004ce0000413d000000000504004b000004e30000613d00000003044002100000000502200210000000000502043300000000054501cf000000000545022f000000000121034f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001204350000006001300210000008ec00010430000000400200043d0000001f0430018f0000000505300272000004f20000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000004ea0000413d000000000604004b000005010000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000001430000013d0000000803000029000000000031043500000255012001c7000008eb0001042e000000050100008a000800000001001d0000000d0110006b0000019d0000213d0000000d0100002900000004031000390000000b0130006c000001250000213d000000a00100043d000500000001001d0000000d020000290000000a012000290000000101100367000000000101043b000002470210009c00000000090000190000055a0000813d0000000201000039000400000001001d000000000101041a000000000119004b000005fa0000c13d0000000002030019000000080120006c0000019d0000213d00000004032000390000000b0130006c000001250000213d0000000a012000290000000101100367000000000101043b000002470210009c00000000090000190000062d0000813d00000000050300190000000301000039000d00000001001d000000000101041a000000000119004b000006cd0000c13d0000000b0150006c000003060000813d0000000a015000290000000102000367000000000312034f000000000303043b00000274033001970000024f0330009c000007200000c13d0000000004050019000000080340006c0000019d0000213d00000004034000390000000b0430006c000001250000213d0000000101100039000000000112034f000000000101043b0000000b0430006c000003060000813d000000e8011002700000000a03300029000000000432034f0000000503500039000c00000031001e000000000504043b0000019d0000413d0000000c060000290000000b0460006c000001250000213d0000000c04000029000002770440009c0000075a0000413d000000400100043d00000044021000390000027d030000410000000000320435000002570200004100000000002104350000002402100039000000200300003900000000003204350000000402100039000005f30000013d000700e00010027800000000080000190000000009000019000000080130006c0000019d0000213d00000004023000390000000b0120006c000001250000213d0000000a033000290000000101000367000000000331034f000000000303043b000000e003300270000000000723001a0000019d0000413d0000000b0470006c000001250000213d0000000a02200029000000000323001a0000023c0420019700000000020004140000019d0000413d0000000005000031000000000635004b0000019d0000413d000e00000009001d000c00000008001d000d00000007001d0000023c0620009c000000a70000213d000000000141034f00000000033500490000023c0330019700000000013103df000000c002200210000002460220019700000247022001c700000000012103af000080100200003908ea08e50000040f000000000301001900000060033002700000023c033001970000000102200190000006120000613d0000003f023000390000024804200197000000400200043d0000000004420019000000000524004b00000000050000190000000105004039000002430640009c000001db0000213d0000000105500190000001db0000c13d000000400040043f00000000043204360000001f053000390000000505500272000005a20000613d00000000060000310000000106600367000000000700001900000005087002100000000009840019000000000886034f000000000808043b00000000008904350000000107700039000000000857004b0000059a0000413d000000000500004b000005a40000613d00000005053002720000000e09000029000005b00000613d000000000600001900000005076002100000000008740019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000005a80000413d0000001f03300190000005bf0000613d0000000505500210000000000151034f00000000055400190000000303300210000000000605043300000000063601cf000000000636022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000161019f00000000001504350000000001020433000000200110008c000005e80000c13d0000000002040433000000400100043d000000400310003900000000002304350000002002100039000000000092043500000009030000290000000000310435000002490310009c000001db0000213d0000006003100039000000400030043f0000023c0320009c0000023c040000410000000002048019000000400220021000000000010104330000023c0310009c00000000010480190000006001100210000000000121019f00000000020004140000023c0320009c0000000002048019000000c002200210000000000112019f0000024a011001c7000080100200003908ea08e00000040f00000001022001900000000d030000290000000c08000029000001250000613d000000000901043b0000000108800039000000070180006c0000055d0000413d000005170000013d000000400100043d00000044021000390000026303000041000000000032043500000024021000390000001f030000390000000000320435000002570200004100000000002104350000000402100039000000200300003900000000003204350000023c020000410000023c0310009c0000000001028019000000400110021000000258011001c7000008ec00010430000000400100043d000000840210003900000264030000410000000000320435000000640210003900000265030000410000000000320435000000440210003900000266030000410000000000320435000000240210003900000044030000390000000000320435000002570200004100000000002104350000000402100039000000200300003900000000003204350000023c020000410000023c0310009c0000000001028019000000400110021000000267011001c7000008ec000104300000001f0430018f00000005023002720000061d0000613d00000000050000190000000506500210000000000761034f000000000707043b00000000007604350000000105500039000000000625004b000006160000413d000000000504004b0000062b0000613d00000003044002100000000502200210000000000502043300000000054501cf000000000545022f000000000121034f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001204350000006001300210000008ec00010430000600e00010027800000000080000190000000009000019000000080130006c0000019d0000213d00000004023000390000000b0120006c000001250000213d0000000a033000290000000101000367000000000331034f000000000303043b000000e00a30027000000000072a001a0000019d0000413d0000000b0470006c000001250000213d00000268043001980000072a0000c13d0000026a0430009c0000072e0000813d0000026b03300198000007320000613d0000000a0220002900000000032a001a0000023c0420019700000000020004140000019d0000413d0000000005000031000000000635004b0000019d0000413d000d0000000a001d000e00000009001d000700000008001d000c00000007001d0000023c0620009c000000a70000213d000000000141034f00000000033500490000023c0330019700000000013103df000000c002200210000002460220019700000247022001c700000000012103af000000020200003908ea08e50000040f000000000301001900000060033002700000023c033001970000000102200190000007390000613d0000003f023000390000024804200197000000400200043d0000000004420019000000000524004b00000000050000190000000105004039000002430640009c000001db0000213d0000000105500190000001db0000c13d000000400040043f00000000043204360000001f0530003900000005055002720000000d0a0000290000067d0000613d00000000060000310000000106600367000000000700001900000005087002100000000009840019000000000886034f000000000808043b00000000008904350000000107700039000000000857004b000006750000413d000000000500004b0000067f0000613d00000005053002720000000e090000290000068b0000613d000000000600001900000005076002100000000008740019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000006830000413d0000001f033001900000069a0000613d0000000505500210000000000151034f00000000055400190000000303300210000000000605043300000000063601cf000000000636022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000161019f0000000000150435000000400100043d0000000002020433000000200220008c000007540000c13d00000000020404330000026d02200197000000db03a002100000026e03300197000000000223019f0000024f022001c7000000400310003900000000002304350000002002100039000000000092043500000009030000290000000000310435000002490310009c000001db0000213d0000006003100039000000400030043f0000023c0320009c0000023c040000410000000002048019000000400220021000000000010104330000023c0310009c00000000010480190000006001100210000000000121019f00000000020004140000023c0320009c0000000002048019000000c002200210000000000112019f0000024a011001c7000080100200003908ea08e00000040f00000001022001900000000c030000290000000708000029000001250000613d000000000901043b0000000108800039000000060180006c000006300000413d000005280000013d0000000002100420000000400100043d000000000202004b000006da0000c13d000001e40000013d000000400100043d00000084021000390000027103000041000000000032043500000064021000390000027203000041000000000032043500000044021000390000027303000041000000000032043500000024021000390000005e03000039000006060000013d000000200200003900000000022104360000000d0500002900000000005204350000001f0350018f00000040021000390000000c0400002900000001044003670000000505500272000006ed0000613d000000000600001900000005076002100000000008720019000000000774034f000000000707043b00000000007804350000000106600039000000000756004b000006e50000413d000000000603004b000006fc0000613d0000000505500210000000000454034f00000000055200190000000303300210000000000605043300000000063601cf000000000636022f000000000404043b0000010003300089000000000434022f00000000033401cf000000000363019f00000000003504350000000d03000029000000000232001900000000000204350000005f02300039000000200300008a000000000232016f0000023c040000410000023c0310009c000000000104801900000040011002100000023c0320009c00000000020480190000006002200210000000000121019f00000000020004140000023c0320009c0000000002048019000000c002200210000000000112019f0000024a011001c70000800d020000390000000303000039000002540400004100000001050000290000000a0600002908ea08db0000040f0000000101200190000001250000613d000000400100043d0000000a0200002900000000002104350000023c0210009c0000023c01008041000000400110021000000255011001c7000008eb0001042e000000400100043d00000064021000390000027503000041000000000032043500000044021000390000027603000041000000000032043500000024021000390000002703000039000003a10000013d000000400100043d00000044021000390000026903000041000007350000013d000000400100043d00000044021000390000027003000041000007350000013d000000400100043d00000044021000390000026f03000041000000000032043500000024021000390000000403000029000005ee0000013d0000001f0430018f0000000502300272000007440000613d00000000050000190000000506500210000000000761034f000000000707043b00000000007604350000000105500039000000000625004b0000073d0000413d000000000504004b000007520000613d00000003044002100000000502200210000000000502043300000000054501cf000000000545022f000000000121034f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001204350000006001300210000008ec0001043000000044021000390000026c03000041000000000032043500000024021000390000001903000039000005ee0000013d0000000c0400002900000004064000390000000b0460006c000001250000213d0000000c070000290000000a04700029000000000442034f000000000804043b000000e00780027000000110947000c9000002470880009c000007690000413d00000000987400d9000001100880008c0000019d0000c13d0000000009640019000900000009001d0000000b0890006c000001250000213d000000f805500270000000400a00043d0000004408a00039000000800900003900000000009804350000002408a000390000000000580435000002780500004100000000005a04350000000a066000290000008405a0003900000000004504350000000405a000390000000000750435000000000862034f0000001f0740018f000e0000000a001d000000a406a0003900000005094002720000078a0000613d000000000a000019000000050ba00210000000000cb60019000000000bb8034f000000000b0b043b0000000000bc0435000000010aa00039000000000b9a004b000007820000413d0000000a03300029000000000a07004b0000079a0000613d0000000509900210000000000898034f00000000099600190000000307700210000000000a090433000000000a7a01cf000000000a7a022f000000000808043b0000010007700089000000000878022f00000000077801cf0000000007a7019f0000000000790435000000000746001900000000000704350000001f044000390000027904400197000000000646001900000000045600490000000e0500002900000064055000390000000000450435000000000432034f0000001f0310018f00000000021604360000000505100272000007b10000613d000000000600001900000005076002100000000008720019000000000774034f000000000707043b00000000007804350000000106600039000000000756004b000007a90000413d000000000603004b000007c00000613d0000000505500210000000000454034f00000000055200190000000303300210000000000605043300000000063601cf000000000636022f000000000404043b0000010003300089000000000434022f00000000033401cf000000000363019f0000000000350435000000000312001900000000000304350000001f011000390000027a011001970000000e04000029000000000141004900000000012100190000023c020000410000023c0340009c0000000003020019000000000304401900000040033002100000023c0410009c00000000010280190000006001100210000000000131019f00000000030004140000023c0430009c0000000003028019000000c002300210000000000112019f0000800e0200003908ea08db0000040f000000000301001900000060033002700000023c03300197000000200430008c000000000403001900000020040080390000001f0540018f0000000506400272000007e90000613d000000000700001900000005087002100000000e09800029000000000881034f000000000808043b00000000008904350000000107700039000000000867004b000007e10000413d000000000705004b000007f80000613d0000000506600210000000000761034f0000000e066000290000000305500210000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f000000000056043500000001022001900000081e0000613d0000001f01400039000000600210018f0000000e01200029000000000221004b00000000020000190000000102004039000002430410009c000001db0000213d0000000102200190000001db0000c13d000000400010043f000000200230008c000001250000413d00000009030000290000000b0230006c0000083b0000c13d0000000e010000290000000001010433000e00000001001d0000000501000029000000000010041d0000000a010000290000000c0200002908ea08440000040f0000000102000039000000000012041d00000004010000290000000e03000029000000000031041d000000000000041b000000000002041b000000000001041b0000000d01000029000000000001041b0000000001000019000008eb0001042e000000400200043d0000001f0430018f00000005053002720000082b0000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000008230000413d000000000604004b0000083a0000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000001430000013d00000064021000390000027b03000041000000000032043500000044021000390000027c03000041000000000032043500000024021000390000002a03000039000003a10000013d00000000030004140000000004120019000000000224004b000000000500001900000001050040390000023c0210019700000001015001900000089d0000c13d0000000001000031000000000541004b0000089d0000413d0000000102200367000002450530009c000008a10000813d00000000014100490000023c0110019700000000011203df000000c002300210000002460220019700000247022001c700000000012103af000080100200003908ea08e50000040f000000000301001900000060033002700000023c033001970000000102200190000008a80000613d0000003f023000390000024804200197000000400200043d0000000004420019000000000524004b00000000050000190000000105004039000002430640009c000008c30000213d0000000105500190000008c30000c13d000000400040043f00000000043204360000001f0530003900000005055002720000087b0000613d00000000060000310000000106600367000000000700001900000005087002100000000009840019000000000886034f000000000808043b00000000008904350000000107700039000000000857004b000008730000413d000000000500004b0000087d0000613d0000001f0530018f0000000503300272000008890000613d000000000600001900000005076002100000000008740019000000000771034f000000000707043b00000000007804350000000106600039000000000736004b000008810000413d000000000605004b000008980000613d0000000503300210000000000131034f00000000033400190000000305500210000000000603043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f00000000001304350000000001020433000000200110008c000008c90000c13d0000000001040433000000000001042d0000027e0100004100000000001004350000001101000039000008c60000013d000000400100043d00000044021000390000025903000041000000000032043500000024021000390000000803000039000008cf0000013d0000001f0430018f0000000502300272000008b30000613d00000000050000190000000506500210000000000761034f000000000707043b00000000007604350000000105500039000000000625004b000008ac0000413d000000000504004b000008c10000613d00000003044002100000000502200210000000000502043300000000054501cf000000000545022f000000000121034f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001204350000006001300210000008ec000104300000027e0100004100000000001004350000004101000039000000040010043f0000027f01000041000008ec00010430000000400100043d00000044021000390000026303000041000000000032043500000024021000390000001f030000390000000000320435000002570200004100000000002104350000000402100039000000200300003900000000003204350000023c020000410000023c0310009c0000000001028019000000400110021000000258011001c7000008ec00010430000008de002104210000000102000039000000000001042d0000000002000019000000000001042d000008e3002104230000000102000039000000000001042d0000000002000019000000000001042d000008e8002104230000000102000039000000000001042d0000000002000019000000000001042d000008ea00000432000008eb0001042e000008ec0001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000628b636d00000000000000000000000000000000000000000000000000000000628b636e0000000000000000000000000000000000000000000000000000000062f84b240000000000000000000000000000000000000000000000000000000039b34c6e0000000000000000000000000000000000000000000000000000000056079ac8000000000000000000000000000000000000000000000000ffffffffffffffff8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000ffffffff000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ffffffe0000000000000000000000000000000000000000000000000ffffffffffffff9f02000000000000000000000000000000000000000000000000000000000000008ac84c0e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffff3f000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffff7f02000000000000000000000000000000000000c000000000000000000000000027fe8c0b49f49507b9d4fe5968c9f49edfe5c9df277d433a07a0717ede97638d00000000000000000000000000000000ffffffffffffffffffffffffffffffff3a36e47291f4201faf137fab081d92295bce2d53be2c6ca68ba82c7faa9ce24100000000000000000000000000000000000000200000000000000000000000004661696c656420746f206368617267652067617300000000000000000000000008c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000640000000000000000000000004f766572666c6f7700000000000000000000000000000000000000000000000043616c6c61626c65206f6e6c792062792074686520626f6f746c6f61646572000000000000000000000000000000000000000064000000800000000000000000000008010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100a06e6f7420657175616c20746f20636861696e65644c6f677348617368000000007265636f6e7374727563746564436861696e65644c6f677348617368206973200000000000000000000000000000000000000084000000000000000000000000000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff72abee45b59e344af8a6e520241c4744aff26ed411f4c4b00f8af09adada43ba6b656363616b3235362072657475726e656420696e76616c69642064617461004861736800000000000000000000000000000000000000000000000000000000206973206e6f7420657175616c20746f20636861696e65644d657373616765737265636f6e7374727563746564436861696e65644d657373616765734861736800000000000000000000000000000000000000a40000000000000000000000000000001f00000000000000000000000000000000000000000000000000000000706f000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000007368612072657475726e656420696e76616c696420646174610000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff06ffffff000000000000000000000000000000000000000000000000000000007072000000000000000000000000000000000000000000000000000000000000707000000000000000000000000000000000000000000000000000000000000061696e65644c3142797465636f64657352657665616c44617461486173680000657665616c4461746148617368206973206e6f7420657175616c20746f2063687265636f6e7374727563746564436861696e65644c3142797465636f64657352ff0000000000000000000000000000000000000000000000000000000000000069736d61746368000000000000000000000000000000000000000000000000007374617465206469666620636f6d7072657373696f6e2076657273696f6e206d000000000000000000000000000000000000000000000000000000000007ef416006d8b500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ffffffffe00000000000000000000000000000000000000000000000000000000001ffffe064617461206172726179000000000000000000000000000000000000000000004578747261206461746120696e2074686520746f74616c4c32546f4c315075624c31204d657373656e676572207075626461746120697320746f6f206c6f6e674e487b71000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000000000000000000000546f6f206d616e79204c322d3e4c31206c6f67730000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000400000080000000000000000054686973206d6574686f642072657175697265207468652063616c6c657220746f2062652073797374656d20636f6e74726163740000000000000000000000000000000000000000000000000000000000000084000000800000000000000000496e617070726f7072696174652063616c6c65720000000000000000000000000200000000000000000000000000000000000040000000a0000000000000000000000000000000000000000000000000000000000000000000000000ffffffd80200000000000000000000000000000000000020000000000000000000000000480d3c9f727b5e5c1203d4c61fb185d37f08e6b2dc5e9bbf98591b1a7addf57c000000000000000000000000000000000000000000000000000000000000000015c01a918940dac2a253ab310e43929c786589c3c4d91ba407284e66e20211fe
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.