This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathImmutableSimulator.sol
45 lines (40 loc) · 2.25 KB
/
ImmutableSimulator.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "./interfaces/IImmutableSimulator.sol";
import {DEPLOYER_SYSTEM_CONTRACT} from "./Constants.sol";
/**
* @author Matter Labs
* @custom:security-contact [email protected]
* @notice System smart contract that simulates the behavior of immutable variables in Solidity.
* @dev The contract stores the immutable variables created during deployment by other contracts on his storage.
* @dev This simulator is needed so that smart contracts with the same Solidity code but different
* constructor parameters have the same bytecode.
* @dev The users are not expected to call this contract directly, only indirectly via the compiler simulations
* for the immutable variables in Solidity.
*/
contract ImmutableSimulator is IImmutableSimulator {
/// @dev mapping (contract address) => (index of immutable variable) => value
/// @notice that address uses `uint256` type to leave the option to introduce 32-byte address space in future.
mapping(uint256 => mapping(uint256 => bytes32)) internal immutableDataStorage;
/// @notice Method that returns the immutable with a certain index for a user.
/// @param _dest The address which the immutable belongs to.
/// @param _index The index of the immutable.
/// @return The value of the immutables.
function getImmutable(address _dest, uint256 _index) external view override returns (bytes32) {
return immutableDataStorage[uint256(uint160(_dest))][_index];
}
/// @notice Method used by the contract deployer to store the immutables for an account
/// @param _dest The address which to store the immutables for.
/// @param _immutables The list of the immutables.
function setImmutables(address _dest, ImmutableData[] calldata _immutables) external override {
require(msg.sender == address(DEPLOYER_SYSTEM_CONTRACT), "Callable only by the deployer system contract");
unchecked {
uint256 immutablesLength = _immutables.length;
for (uint256 i = 0; i < immutablesLength; ++i) {
uint256 index = _immutables[i].index;
bytes32 value = _immutables[i].value;
immutableDataStorage[uint256(uint160(_dest))][index] = value;
}
}
}
}