Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions AllContractsHashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,6 @@
"evmBytecodePath": null,
"evmDeployedBytecodeHash": null
},
{
"contractName": "system-contracts/DummyChainAssetHandler",
"zkBytecodeHash": "0x010000155973300832b2697d53a543ab1742e89f918eba767e272e79c5e6d3b2",
"zkBytecodePath": "/system-contracts/zkout/DummyChainAssetHandler.sol/DummyChainAssetHandler.json",
"evmBytecodeHash": null,
"evmBytecodePath": null,
"evmDeployedBytecodeHash": null
},
{
"contractName": "system-contracts/DummyL2AssetRouter",
"zkBytecodeHash": "0x01000013e110725a16943b61efbc6aef12898a846761162d8738500c003cce7c",
"zkBytecodePath": "/system-contracts/zkout/DummyL2AssetRouter.sol/DummyL2AssetRouter.json",
"evmBytecodeHash": null,
"evmBytecodePath": null,
"evmDeployedBytecodeHash": null
},
{
"contractName": "system-contracts/DummyL2NativeTokenVault",
"zkBytecodeHash": "0x010000173d8ca2f2fcdb53c0f8cd3404aab085d61dbb0b3810144d225f1fd449",
"zkBytecodePath": "/system-contracts/zkout/DummyL2NativeTokenVault.sol/DummyL2NativeTokenVault.json",
"evmBytecodeHash": null,
"evmBytecodePath": null,
"evmDeployedBytecodeHash": null
},
{
"contractName": "system-contracts/DummyMessageRoot",
"zkBytecodeHash": "0x010000134e39355067d9da937bb94de9853965f6a2bc037081417bbc7d922023",
"zkBytecodePath": "/system-contracts/zkout/DummyMessageRoot.sol/DummyMessageRoot.json",
"evmBytecodeHash": null,
"evmBytecodePath": null,
"evmDeployedBytecodeHash": null
},
{
"contractName": "system-contracts/ERC1967Proxy",
"zkBytecodeHash": "0x01000099061056e891546ad811105c25405ec2dcfa53acd6a2fe34a008005233",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract contract SharedL2ContractDeployer is Test, DeployIntegrationUtils {

IChainTypeManager internal chainTypeManager;

function setUp() public {
function setUp() public virtual {
standardErc20Impl = new BridgedStandardERC20();
beacon = new UpgradeableBeacon(address(standardErc20Impl));
beacon.transferOwnership(ownerWallet);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.28;

import {Test} from "forge-std/Test.sol";

import {L2ComplexUpgrader} from "contracts/l2-upgrades/L2ComplexUpgrader.sol";
import {L2_COMPLEX_UPGRADER_ADDR, L2_FORCE_DEPLOYER_ADDR} from "contracts/common/l2-helpers/L2ContractAddresses.sol";
import {MockContract} from "contracts/dev-contracts/MockContract.sol";
import {Unauthorized} from "contracts/common/L1ContractErrors.sol";
import {Utils} from "deploy-scripts/Utils.sol";

contract L2ComplexUpgraderTest is Test {
MockContract public dummyUpgrade;

function setUp() public {
bytes memory code = Utils.readZKFoundryBytecodeL1("L2ComplexUpgrader.sol", "L2ComplexUpgrader");
vm.etch(L2_COMPLEX_UPGRADER_ADDR, code);
dummyUpgrade = new MockContract();
}

function test_RevertWhen_NonForceDeployerCallsUpgrade() public {
vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, address(this)));
L2ComplexUpgrader(L2_COMPLEX_UPGRADER_ADDR).upgrade(address(dummyUpgrade), hex"deadbeef");
}

function test_SuccessfulUpgrade() public {
vm.expectEmit(true, true, false, true, L2_COMPLEX_UPGRADER_ADDR);
emit MockContract.Called(0, hex"deadbeef");

vm.prank(L2_FORCE_DEPLOYER_ADDR);
L2ComplexUpgrader(L2_COMPLEX_UPGRADER_ADDR).upgrade(address(dummyUpgrade), hex"deadbeef");
}
}
183 changes: 183 additions & 0 deletions l1-contracts/test/foundry/l2/integration/L2GenesisUpgrade.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.28;

import {Test} from "forge-std/Test.sol";

import {L2ComplexUpgrader} from "contracts/l2-upgrades/L2ComplexUpgrader.sol";
import {L2GenesisUpgrade} from "contracts/l2-upgrades/L2GenesisUpgrade.sol";
import {IL2GenesisUpgrade} from "contracts/state-transition/l2-deps/IL2GenesisUpgrade.sol";
import {L2_COMPLEX_UPGRADER_ADDR, L2_FORCE_DEPLOYER_ADDR, L2_GENESIS_UPGRADE_ADDR, L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR, L2_MESSAGE_ROOT_ADDR, L2_BRIDGEHUB_ADDR, L2_ASSET_ROUTER_ADDR, L2_WRAPPED_BASE_TOKEN_IMPL_ADDR, L2_NTV_BEACON_DEPLOYER_ADDR, L2_KNOWN_CODE_STORAGE_SYSTEM_CONTRACT_ADDR, L2_CHAIN_ASSET_HANDLER_ADDR} from "contracts/common/l2-helpers/L2ContractAddresses.sol";
import {Utils} from "deploy-scripts/Utils.sol";
import {L2ContractHelper} from "contracts/common/l2-helpers/L2ContractHelper.sol";
import {FixedForceDeploymentsData, ZKChainSpecificForceDeploymentsData} from "contracts/state-transition/l2-deps/IL2GenesisUpgrade.sol";
import {L2WrappedBaseToken} from "contracts/bridge/L2WrappedBaseToken.sol";
import {L2MessageRoot} from "contracts/bridgehub/L2MessageRoot.sol";
import {L2Bridgehub} from "contracts/bridgehub/L2Bridgehub.sol";
import {L2AssetRouter} from "contracts/bridge/asset-router/L2AssetRouter.sol";
import {L2ChainAssetHandler} from "contracts/bridgehub/L2ChainAssetHandler.sol";
import {UpgradeableBeaconDeployer} from "contracts/bridge/ntv/UpgradeableBeaconDeployer.sol";
import {SharedL2ContractDeployer} from "../../l1/integration/l2-tests-abstract/_SharedL2ContractDeployer.sol";
import {SharedL2ContractL2Deployer} from "./_SharedL2ContractL2Deployer.sol";
import {SystemContractsArgs} from "./L2Utils.sol";
import {SharedL2ContractL2Deployer} from "./_SharedL2ContractL2Deployer.sol";
import {ISystemContext} from "contracts/state-transition/l2-deps/ISystemContext.sol";
import {L2GatewayTestAbstract} from "../../l1/integration/l2-tests-abstract/L2GatewayTestAbstract.t.sol";
import {SharedL2ContractDeployer} from "../../l1/integration/l2-tests-abstract/_SharedL2ContractDeployer.sol";
import {Create2FactoryUtils} from "deploy-scripts/Create2FactoryUtils.s.sol";

contract L2GenesisUpgradeTest is Test, SharedL2ContractDeployer, SharedL2ContractL2Deployer {
uint256 constant CHAIN_ID = 270;
address ctmDeployerAddress = makeAddr("ctmDeployer");
address bridgehubOwnerAddress = makeAddr("bridgehubOwner");

bytes fixedForceDeploymentsData;
bytes additionalForceDeploymentsData;

function test() internal virtual override(SharedL2ContractDeployer, SharedL2ContractL2Deployer) {}

function initSystemContracts(
SystemContractsArgs memory _args
) internal override(SharedL2ContractDeployer, SharedL2ContractL2Deployer) {
super.initSystemContracts(_args);
}

function deployViaCreate2(
bytes memory creationCode,
bytes memory constructorArgs
) internal override(Create2FactoryUtils, SharedL2ContractL2Deployer) returns (address) {
return super.deployViaCreate2(creationCode, constructorArgs);
}

function deployL2Contracts(
uint256 _l1ChainId
) public override(SharedL2ContractL2Deployer, SharedL2ContractDeployer) {
super.deployL2Contracts(_l1ChainId);
}

function setUp() public override {
super.setUp();

// Deploy and etch L2ComplexUpgrader
bytes memory complexUpgraderCode = Utils.readZKFoundryBytecodeL1("L2ComplexUpgrader.sol", "L2ComplexUpgrader");
vm.etch(L2_COMPLEX_UPGRADER_ADDR, complexUpgraderCode);

// Deploy and etch L2GenesisUpgrade
bytes memory genesisUpgradeCode = Utils.readZKFoundryBytecodeL1("L2GenesisUpgrade.sol", "L2GenesisUpgrade");
vm.etch(L2_GENESIS_UPGRADE_ADDR, genesisUpgradeCode);

// Deploy and etch SystemContext
bytes memory systemContextCode = Utils.readZKFoundryBytecodeSystemContracts(
"SystemContext.sol",
"SystemContext"
);
vm.etch(L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR, systemContextCode);

// Deploy and etch L2WrappedBaseToken
bytes memory wrappedBaseTokenCode = Utils.readZKFoundryBytecodeL1(
"L2WrappedBaseToken.sol",
"L2WrappedBaseToken"
);
vm.etch(L2_WRAPPED_BASE_TOKEN_IMPL_ADDR, wrappedBaseTokenCode);

// Deploy and etch UpgradeableBeaconDeployer
new UpgradeableBeaconDeployer();
bytes memory upgradeableBeaconDeployerCode = Utils.readZKFoundryBytecodeL1(
"UpgradeableBeaconDeployer.sol",
"UpgradeableBeaconDeployer"
);
vm.etch(L2_NTV_BEACON_DEPLOYER_ADDR, upgradeableBeaconDeployerCode);

additionalForceDeploymentsData = abi.encode(
ZKChainSpecificForceDeploymentsData({
baseTokenAssetId: bytes32(0x0100056f53fd9e940906d998a80ed53392e5c50a8eb198baf9f78fd84ce7ec70),
l2LegacySharedBridge: address(0),
predeployedL2WethAddress: address(1),
baseTokenL1Address: address(1),
baseTokenName: "Ether",
baseTokenSymbol: "ETH"
})
);

bytes memory messageRootBytecode = Utils.readZKFoundryBytecodeL1("L2MessageRoot.sol", "L2MessageRoot");
bytes memory messageRootBytecodeInfo = abi.encode(L2ContractHelper.hashL2Bytecode(messageRootBytecode));

bytes memory l2NativeTokenVaultBytecode = Utils.readZKFoundryBytecodeL1(
"L2NativeTokenVault.sol",
"L2NativeTokenVault"
);
bytes memory l2NtvBytecodeInfo = abi.encode(L2ContractHelper.hashL2Bytecode(l2NativeTokenVaultBytecode));

bytes memory l2AssetRouterBytecode = Utils.readZKFoundryBytecodeL1("L2AssetRouter.sol", "L2AssetRouter");
bytes memory l2AssetRouterBytecodeInfo = abi.encode(L2ContractHelper.hashL2Bytecode(l2AssetRouterBytecode));

bytes memory bridgehubBytecode = Utils.readZKFoundryBytecodeL1("L2Bridgehub.sol", "L2Bridgehub");
bytes memory bridgehubBytecodeInfo = abi.encode(L2ContractHelper.hashL2Bytecode(bridgehubBytecode));

bytes memory chainAssetHandlerBytecode = Utils.readZKFoundryBytecodeL1(
"L2ChainAssetHandler.sol",
"L2ChainAssetHandler"
);
bytes memory chainAssetHandlerBytecodeInfo = abi.encode(
L2ContractHelper.hashL2Bytecode(chainAssetHandlerBytecode)
);

bytes memory beaconDeployerBytecode = Utils.readZKFoundryBytecodeL1(
"UpgradeableBeaconDeployer.sol",
"UpgradeableBeaconDeployer"
);
bytes memory beaconDeployerBytecodeInfo = abi.encode(L2ContractHelper.hashL2Bytecode(beaconDeployerBytecode));

fixedForceDeploymentsData = abi.encode(
FixedForceDeploymentsData({
l1ChainId: 1,
eraChainId: CHAIN_ID,
l1AssetRouter: address(1),
l2TokenProxyBytecodeHash: bytes32(0x0100056f53fd9e940906d998a80ed53392e5c50a8eb198baf9f78fd84ce7ec70),
aliasedL1Governance: address(1),
maxNumberOfZKChains: 100,
bridgehubBytecodeInfo: bridgehubBytecodeInfo,
l2AssetRouterBytecodeInfo: l2AssetRouterBytecodeInfo,
l2NtvBytecodeInfo: l2NtvBytecodeInfo,
messageRootBytecodeInfo: messageRootBytecodeInfo,
chainAssetHandlerBytecodeInfo: chainAssetHandlerBytecodeInfo,
beaconDeployerInfo: beaconDeployerBytecodeInfo,
// For genesis upgrade these values will always be zero
l2SharedBridgeLegacyImpl: address(0),
l2BridgedStandardERC20Impl: address(0),
dangerousTestOnlyForcedBeacon: address(0)
})
);

vm.mockCall(
L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR,
abi.encodeWithSelector(ISystemContext.setChainId.selector),
""
);
vm.mockCall(L2_BRIDGEHUB_ADDR, abi.encodeWithSelector(L2Bridgehub.initL2.selector), "");
vm.mockCall(L2_ASSET_ROUTER_ADDR, abi.encodeWithSelector(L2AssetRouter.initL2.selector), "");
vm.mockCall(L2_CHAIN_ASSET_HANDLER_ADDR, abi.encodeWithSelector(L2ChainAssetHandler.initL2.selector), "");
vm.mockCall(
L2_KNOWN_CODE_STORAGE_SYSTEM_CONTRACT_ADDR,
abi.encodeWithSelector(bytes4(keccak256("getMarker(bytes32)"))),
abi.encode(1)
);
}

function test_SuccessfulGenesisUpgrade() public {
bytes memory genesisUpgradeCalldata = abi.encodeWithSelector(
IL2GenesisUpgrade.genesisUpgrade.selector,
false, // _isZKsyncOS
CHAIN_ID,
ctmDeployerAddress,
fixedForceDeploymentsData,
additionalForceDeploymentsData
);

vm.expectEmit(true, false, false, true, L2_COMPLEX_UPGRADER_ADDR);
emit IL2GenesisUpgrade.UpgradeComplete(CHAIN_ID);

vm.prank(L2_FORCE_DEPLOYER_ADDR);
L2ComplexUpgrader(L2_COMPLEX_UPGRADER_ADDR).upgrade(L2_GENESIS_UPGRADE_ADDR, genesisUpgradeCalldata);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

40 changes: 0 additions & 40 deletions system-contracts/test/ComplexUpgrader.spec.ts

This file was deleted.

Loading
Loading