Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Sep 27, 2024
1 parent 0e65b90 commit 174fbab
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 178 deletions.
6 changes: 4 additions & 2 deletions l1-contracts/contracts/bridge/L2SharedBridgeLegacy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ contract L2SharedBridgeLegacy is IL2SharedBridgeLegacy, Initializable {
bytes calldata _data
) external {
// Only the L1 bridge counterpart can initiate and finalize the deposit.
if (AddressAliasHelper.undoL1ToL2Alias(msg.sender) != l1Bridge && AddressAliasHelper.undoL1ToL2Alias(msg.sender) != l1SharedBridge) {
if (
AddressAliasHelper.undoL1ToL2Alias(msg.sender) != l1Bridge &&
AddressAliasHelper.undoL1ToL2Alias(msg.sender) != l1SharedBridge
) {
revert InvalidCaller(msg.sender);
}

Expand All @@ -132,7 +135,6 @@ contract L2SharedBridgeLegacy is IL2SharedBridgeLegacy, Initializable {
_data: _data
});


address l2Token = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).l2TokenAddress(_l1Token);

if (l1TokenAddress[l2Token] == address(0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ contract L1AssetRouter is AssetRouterBase, IL1AssetRouter, ReentrancyGuard {
}

/// @notice Legacy function to get the L2 shared bridge address for a chain.
/// @dev In case the chain has been deployed after the gateway release,
/// @dev In case the chain has been deployed after the gateway release,
/// the returned value is 0.
function l2BridgeAddress(uint256 _chainId) external view override returns (address) {
return L1_NULLIFIER.l2BridgeAddress(_chainId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
_l1Token: _l1Token,
_amount: _amount,
_data: _data

});
}

Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/contracts/governance/L2ProxyAdminDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {ProxyAdmin} from "@openzeppelin/contracts-v4/proxy/transparent/ProxyAdmi

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice The contract that deterministically deploys a ProxyAdmin, while
/// @notice The contract that deterministically deploys a ProxyAdmin, while
/// ensuring that its owner is the aliased governance contract
contract L2ProxyAdminDeployer {
address immutable public PROXY_ADMIN_ADDRESS;
address public immutable PROXY_ADMIN_ADDRESS;

constructor(address _aliasedGovernance) {
ProxyAdmin admin = new ProxyAdmin{salt: bytes32(0)}();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/contracts/governance/TransitionaryOwner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {Ownable2Step} from "@openzeppelin/contracts-v4/access/Ownable2Step.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice The contract that is used a temporary owner for Ownable2Step contracts until the
/// @notice The contract that is used a temporary owner for Ownable2Step contracts until the
/// governance can accept the ownership
contract TransitionaryOwner {
address public immutable GOVERNANCE_ADDRESS;

constructor(address _goveranceAddress) {

Check warning on line 16 in l1-contracts/contracts/governance/TransitionaryOwner.sol

View workflow job for this annotation

GitHub Actions / typos

"goverance" should be "governance".
GOVERNANCE_ADDRESS = _goveranceAddress;

Check warning on line 17 in l1-contracts/contracts/governance/TransitionaryOwner.sol

View workflow job for this annotation

GitHub Actions / typos

"goverance" should be "governance".
}
Expand Down
6 changes: 3 additions & 3 deletions l1-contracts/contracts/upgrades/GatewayHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
pragma solidity 0.8.24;

import {IL1SharedBridgeLegacy} from "../bridge/interfaces/IL1SharedBridgeLegacy.sol";
import {IBridgehub} from "../bridgehub/IBridgehub.sol";
import {IBridgehub} from "../bridgehub/IBridgehub.sol";

import { ZKChainSpecificForceDeploymentsData} from "../state-transition/l2-deps/IL2GenesisUpgrade.sol";
import {ZKChainSpecificForceDeploymentsData} from "../state-transition/l2-deps/IL2GenesisUpgrade.sol";

import { ZKChainStorage } from "../state-transition/chain-deps/ZKChainStorage.sol";
import {ZKChainStorage} from "../state-transition/chain-deps/ZKChainStorage.sol";

library GatewayHelper {
function getZKChainSpecificForceDeploymentsData(ZKChainStorage storage s) internal view returns (bytes memory) {
Expand Down
21 changes: 11 additions & 10 deletions l1-contracts/contracts/upgrades/GatewayUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ import {PriorityQueue} from "../state-transition/libraries/PriorityQueue.sol";
import {PriorityTree} from "../state-transition/libraries/PriorityTree.sol";

import {IGatewayUpgrade} from "./IGatewayUpgrade.sol";
import {IL1SharedBridgeLegacy} from "../bridge/interfaces/IL1SharedBridgeLegacy.sol";
import {IComplexUpgrader} from "../state-transition/l2-deps/IComplexUpgrader.sol";
import {IL2GatewayUpgrade} from "../state-transition/l2-deps/IL2GatewayUpgrade.sol";
import {IBridgehub} from "../bridgehub/IBridgehub.sol";

import {IL2ContractDeployer} from "../common/interfaces/IL2ContractDeployer.sol";

import {GatewayHelper} from "./GatewayHelper.sol";

// solhint-disable-next-line gas-struct-packing
struct GatewayUpgradeEncodedInput {
IL2ContractDeployer.ForceDeployment[] baseForceDeployments;
bytes fixedForceDeploymentsData;
address ctmDeployer;
address l2GatewayUpgrade;
address oldValidatorTimelock;
address newValidatorTimelock;
bytes fixedForceDeploymentsData;
}

/// @author Matter Labs
Expand All @@ -45,15 +44,17 @@ contract GatewayUpgrade is BaseZkSyncUpgrade {
/// @notice The main function that will be called by the upgrade proxy.
/// @param _proposedUpgrade The upgrade to be executed.
function upgrade(ProposedUpgrade calldata _proposedUpgrade) public override returns (bytes32) {
GatewayUpgradeEncodedInput memory encodedInput = abi.decode(_proposedUpgrade.postUpgradeCalldata, (GatewayUpgradeEncodedInput));
GatewayUpgradeEncodedInput memory encodedInput = abi.decode(
_proposedUpgrade.postUpgradeCalldata,
(GatewayUpgradeEncodedInput)
);

bytes32 baseTokenAssetId = DataEncoding.encodeNTVAssetId(block.chainid, s.__DEPRECATED_baseToken);

s.baseTokenAssetId = baseTokenAssetId;
s.priorityTree.setup(s.priorityQueue.getTotalPriorityTxs());
s.validators[encodedInput.oldValidatorTimelock] = false;
s.validators[encodedInput.newValidatorTimelock] = true;
IBridgehub bridgehub = IBridgehub(s.bridgehub);
ProposedUpgrade memory proposedUpgrade = _proposedUpgrade;

bytes memory gatewayUpgradeCalldata = abi.encodeCall(
Expand All @@ -66,11 +67,11 @@ contract GatewayUpgrade is BaseZkSyncUpgrade {
)
);

proposedUpgrade.l2ProtocolUpgradeTx.data = abi.encodeCall(IComplexUpgrader.upgrade, (
encodedInput.l2GatewayUpgrade,
gatewayUpgradeCalldata
));
proposedUpgrade.l2ProtocolUpgradeTx.data = abi.encodeCall(
IComplexUpgrader.upgrade,
(encodedInput.l2GatewayUpgrade, gatewayUpgradeCalldata)
);

// slither-disable-next-line controlled-delegatecall
(bool success, ) = THIS_ADDRESS.delegatecall(
abi.encodeWithSelector(IGatewayUpgrade.upgradeExternal.selector, proposedUpgrade)
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/contracts/upgrades/L1GenesisUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA, SYSTEM_UPGRADE_L2_TX_TYPE, PRIORITY_T
import {SemVer} from "../common/libraries/SemVer.sol";

import {IL1SharedBridgeLegacy} from "../bridge/interfaces/IL1SharedBridgeLegacy.sol";
import {IBridgehub} from "../bridgehub/IBridgehub.sol";
import {IBridgehub} from "../bridgehub/IBridgehub.sol";

import { ZKChainSpecificForceDeploymentsData} from "../state-transition/l2-deps/IL2GenesisUpgrade.sol";
import {ZKChainSpecificForceDeploymentsData} from "../state-transition/l2-deps/IL2GenesisUpgrade.sol";

import {VerifierParams} from "../state-transition/chain-interfaces/IVerifier.sol";
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol";
Expand Down
47 changes: 14 additions & 33 deletions l1-contracts/deploy-scripts/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,7 @@ library Utils {
address bridgehubAddress,
address l1SharedBridgeProxy
) internal returns (address) {
(bytes32 bytecodeHash, bytes memory deployData) = getDeploymentCalldata(
create2salt,
bytecode,
constructorargs
);
(bytes32 bytecodeHash, bytes memory deployData) = getDeploymentCalldata(create2salt, bytecode, constructorargs);

address contractAddress = L2ContractHelper.computeCreate2Address(
msg.sender,
Expand Down Expand Up @@ -278,12 +274,13 @@ library Utils {
bytes32 bytecodeHash,
bytes memory constructorArgs
) internal view returns (address) {
return L2ContractHelper.computeCreate2Address(
L2_CREATE2_FACTORY_ADDRESS,
create2Salt,
bytecodeHash,
keccak256(constructorArgs)
);
return
L2ContractHelper.computeCreate2Address(
L2_CREATE2_FACTORY_ADDRESS,
create2Salt,
bytecodeHash,
keccak256(constructorArgs)
);
}

function getDeploymentCalldata(
Expand All @@ -293,18 +290,10 @@ library Utils {
) internal view returns (bytes32 bytecodeHash, bytes memory data) {
bytecodeHash = L2ContractHelper.hashL2Bytecode(bytecode);

data = abi.encodeWithSignature(
"create2(bytes32,bytes32,bytes)",
create2Salt,
bytecodeHash,
constructorArgs
);
data = abi.encodeWithSignature("create2(bytes32,bytes32,bytes)", create2Salt, bytecodeHash, constructorArgs);
}

function appendArray(
bytes[] memory array,
bytes memory element
) internal pure returns (bytes[] memory) {
function appendArray(bytes[] memory array, bytes memory element) internal pure returns (bytes[] memory) {
uint256 arrayLength = array.length;
bytes[] memory newArray = new bytes[](arrayLength + 1);
for (uint256 i = 0; i < arrayLength; ++i) {
Expand All @@ -313,7 +302,7 @@ library Utils {
newArray[arrayLength] = element;
return newArray;
}

/**
* @dev Deploy l2 contracts through l1, while using built-in L2 Create2Factory contract.
*/
Expand All @@ -327,20 +316,12 @@ library Utils {
address bridgehubAddress,
address l1SharedBridgeProxy
) internal returns (address) {
(bytes32 bytecodeHash, bytes memory deployData) = getDeploymentCalldata(
create2salt,
bytecode,
constructorargs
);
(bytes32 bytecodeHash, bytes memory deployData) = getDeploymentCalldata(create2salt, bytecode, constructorargs);

address contractAddress = getL2AddressViaCreate2Factory(
create2salt,
bytecodeHash,
constructorargs
);
address contractAddress = getL2AddressViaCreate2Factory(create2salt, bytecodeHash, constructorargs);

bytes[] memory _factoryDeps = appendArray(factoryDeps, bytecode);

runL1L2Transaction({
l2Calldata: deployData,
l2GasLimit: l2GasLimit,
Expand Down
44 changes: 20 additions & 24 deletions l1-contracts/deploy-scripts/upgrade/ChainUpgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,21 @@ interface LegacyChainAdmin {
function owner() external view returns (address);
}

contract ChainUpgrade is Script {
contract ChainUpgrade is Script {
using stdToml for string;

struct ChainConfig {
address deployerAddress;
address ownerAddress;
uint256 chainChainId;
address chainDiamondProxyAddress;
bool validiumMode;
bool permanentRollup;

// FIXME: From ecosystem, maybe move to a different struct
address expectedRollupL2DAValidator;
address expectedL2GatewayUpgrade;
address expectedValidiumL2DAValidator;
address permanentRollupRestriction;

address bridgehubProxyAddress;
address oldSharedBridgeProxyAddress;
}
Expand Down Expand Up @@ -67,8 +65,8 @@ contract ChainUpgrade is Script {
checkCorrectOwnerAddress();
// Preparation of chain consists of two parts:
// - Deploying l2 da validator
// - Deploying new chain admin
// - Deploying new chain admin

deployNewL2DAValidator();
deployL2GatewayUpgrade();
deployNewChainAdmin();
Expand All @@ -77,30 +75,26 @@ contract ChainUpgrade is Script {
saveOutput(outputPath);
}

function upgradeChain(
uint256 oldProtocolVersion,
Diamond.DiamondCutData memory upgradeCutData
) public {
function upgradeChain(uint256 oldProtocolVersion, Diamond.DiamondCutData memory upgradeCutData) public {
Utils.adminExecute(
output.chainAdmin,
output.accessControlRestriction,
config.chainDiamondProxyAddress,
output.chainAdmin,
output.accessControlRestriction,
config.chainDiamondProxyAddress,
abi.encodeCall(IAdmin.upgradeChainFromVersion, (oldProtocolVersion, upgradeCutData)),
0
);
}

function initializeConfig(
string memory configPath,
string memory ecosystemInputPath,
string memory ecosystemOutputPath
) internal {
config.deployerAddress = msg.sender;

// Grab config from output of l1 deployment
string memory toml = vm.readFile(configPath);


// Config file must be parsed key by key, otherwise values returned
// are parsed alfabetically and not by key.
// https://book.getfoundry.sh/cheatcodes/parse-toml
Expand All @@ -110,7 +104,7 @@ contract ChainUpgrade is Script {
config.validiumMode = toml.readBool("$.chain.validium_mode");
config.chainDiamondProxyAddress = toml.readAddress("$.chain.diamond_proxy_address");
config.permanentRollup = toml.readBool("$.chain.permanent_rollup");

toml = vm.readFile(ecosystemOutputPath);

config.expectedRollupL2DAValidator = toml.readAddress("$.contracts_config.expected_rollup_l2_da_validator");
Expand All @@ -129,7 +123,6 @@ contract ChainUpgrade is Script {
address currentAdminOwner = LegacyChainAdmin(currentChainAdmin).owner();

require(currentAdminOwner == config.ownerAddress, "Only the owner of the chain admin can call this function");

}

function deployNewL2DAValidator() internal {
Expand Down Expand Up @@ -167,7 +160,7 @@ contract ChainUpgrade is Script {
function deployNewChainAdmin() internal {
AccessControlRestriction accessControlRestriction = new AccessControlRestriction(0, config.ownerAddress);

address[] memory restrictions;
address[] memory restrictions;
if (config.permanentRollup) {
restrictions = new address[](2);
restrictions[0] = address(accessControlRestriction);
Expand All @@ -182,17 +175,21 @@ contract ChainUpgrade is Script {
output.accessControlRestriction = address(accessControlRestriction);
}

/// @dev The caller of this function needs to be the owner of the chain admin
/// of the
/// @dev The caller of this function needs to be the owner of the chain admin
/// of the
function governanceMoveToNewChainAdmin() internal {
// Firstly, we need to call the legacy chain admin to transfer the ownership to the new chain admin
Call[] memory calls = new Call[](1);
calls[0] = Call({target: config.chainDiamondProxyAddress, value: 0, data: abi.encodeCall(IAdmin.setPendingAdmin, (output.chainAdmin))});
calls[0] = Call({
target: config.chainDiamondProxyAddress,
value: 0,
data: abi.encodeCall(IAdmin.setPendingAdmin, (output.chainAdmin))
});

vm.startBroadcast(config.ownerAddress);
ChainAdmin(payable(currentChainAdmin)).multicall(calls, true);
vm.stopBroadcast();

// Now we need to accept the adminship
Utils.adminExecute({
_admin: output.chainAdmin,
Expand All @@ -211,6 +208,5 @@ contract ChainUpgrade is Script {
string memory root = vm.projectRoot();
vm.writeToml(toml, outputPath);
console.log("Output saved at:", outputPath);

}
}
Loading

0 comments on commit 174fbab

Please sign in to comment.