From 175da537f2e9b37fb75ba442a1dc552f46b6d4ec Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Mon, 16 Dec 2024 22:41:21 +0400 Subject: [PATCH] fix: lint, links, delete files from them --- README.md | 3 +- docs/README.md | 1 - l1-contracts/src.ts/deploy.ts | 7 - .../foundry/l1/integration/GatewayTests.t.sol | 317 ------------------ .../l2/unit/erc20/L2Erc20BridgeTest.t.sol | 137 -------- .../test/foundry/l2/unit/utils/L2Utils.sol | 167 --------- .../test/foundry/l2/unit/weth/WETH.t.sol | 118 ------- .../contracts/PubdataChunkPublisher.sol | 1 - 8 files changed, 1 insertion(+), 750 deletions(-) delete mode 100644 l1-contracts/test/foundry/l1/integration/GatewayTests.t.sol delete mode 100644 l1-contracts/test/foundry/l2/unit/erc20/L2Erc20BridgeTest.t.sol delete mode 100644 l1-contracts/test/foundry/l2/unit/utils/L2Utils.sol delete mode 100644 l1-contracts/test/foundry/l2/unit/weth/WETH.t.sol diff --git a/README.md b/README.md index 8c776af4c..e4e7a2f56 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,7 @@ decentralization. Since it's EVM compatible (Solidity/Vyper), 99% of Ethereum pr or re-auditing a single line of code. ZKsync Era also uses an LLVM-based compiler that will eventually let developers write smart contracts in C++, Rust and other popular languages. -This repository contains both L1 and L2 ZKsync smart contracts. For their description see the -[system overview](docs/overview.md). +This repository contains both L1 and L2 ZKsync smart contracts. ## Disclaimer diff --git a/docs/README.md b/docs/README.md index b027c1801..334158148 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,7 +3,6 @@ The order of the files here only roughly represents the order of reading. A lot of topics are intertwined, so it is recommended to read everything first to have a complete picture and then refer to specific documents for more details. - [Glossary](./glossary.md) -- [Overview](./overview.md) - Contracts of an individual chain - [ZK Chain basics](./settlement_contracts/zkchain_basics.md) - Data availability diff --git a/l1-contracts/src.ts/deploy.ts b/l1-contracts/src.ts/deploy.ts index de51c702b..4747418c7 100644 --- a/l1-contracts/src.ts/deploy.ts +++ b/l1-contracts/src.ts/deploy.ts @@ -212,13 +212,6 @@ export class Deployer { l2SharedBridgeLegacyImpl: ethers.constants.AddressZero, l2BridgedStandardERC20Impl: ethers.constants.AddressZero, }; - const messageRootDeployment = { - bytecodeHash: ethers.utils.hexlify(hashL2Bytecode(messageRootZKBytecode)), - newAddress: L2_MESSAGE_ROOT_ADDRESS, - callConstructor: true, - value: 0, - input: ethers.utils.defaultAbiCoder.encode(["address"], [L2_BRIDGEHUB_ADDRESS]), - }; return ethers.utils.defaultAbiCoder.encode([FIXED_FORCE_DEPLOYMENTS_DATA_ABI_STRING], [fixedForceDeploymentsData]); } diff --git a/l1-contracts/test/foundry/l1/integration/GatewayTests.t.sol b/l1-contracts/test/foundry/l1/integration/GatewayTests.t.sol deleted file mode 100644 index 1e7e64457..000000000 --- a/l1-contracts/test/foundry/l1/integration/GatewayTests.t.sol +++ /dev/null @@ -1,317 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.24; - -import {Test} from "forge-std/Test.sol"; -import {Vm} from "forge-std/Vm.sol"; -import "forge-std/console.sol"; - -import {L2TransactionRequestDirect, L2TransactionRequestTwoBridgesOuter, BridgehubMintCTMAssetData, BridgehubBurnCTMAssetData} from "contracts/bridgehub/IBridgehub.sol"; -import {TestnetERC20Token} from "contracts/dev-contracts/TestnetERC20Token.sol"; -import {MailboxFacet} from "contracts/state-transition/chain-deps/facets/Mailbox.sol"; -import {GettersFacet} from "contracts/state-transition/chain-deps/facets/Getters.sol"; -import {IMailbox} from "contracts/state-transition/chain-interfaces/IMailbox.sol"; -import {IExecutor} from "contracts/state-transition/chain-interfaces/IExecutor.sol"; -import {L1ContractDeployer} from "./_SharedL1ContractDeployer.t.sol"; -import {TokenDeployer} from "./_SharedTokenDeployer.t.sol"; -import {ZKChainDeployer} from "./_SharedZKChainDeployer.t.sol"; -import {GatewayDeployer} from "./_SharedGatewayDeployer.t.sol"; -import {L2TxMocker} from "./_SharedL2TxMocker.t.sol"; -import {ETH_TOKEN_ADDRESS, SETTLEMENT_LAYER_RELAY_SENDER} from "contracts/common/Config.sol"; -import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA, DEFAULT_L2_LOGS_TREE_ROOT_HASH, EMPTY_STRING_KECCAK} from "contracts/common/Config.sol"; -import {L2CanonicalTransaction} from "contracts/common/Messaging.sol"; -import {L2Message} from "contracts/common/Messaging.sol"; -import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol"; -import {L2_BASE_TOKEN_SYSTEM_CONTRACT_ADDR} from "contracts/common/L2ContractAddresses.sol"; -import {IL1ERC20Bridge} from "contracts/bridge/interfaces/IL1ERC20Bridge.sol"; -import {IL1AssetRouter} from "contracts/bridge/asset-router/IL1AssetRouter.sol"; - -import {Ownable} from "@openzeppelin/contracts-v4/access/Ownable.sol"; -import {IZKChain} from "contracts/state-transition/chain-interfaces/IZKChain.sol"; -import {IChainTypeManager} from "contracts/state-transition/IChainTypeManager.sol"; -import {AdminFacet} from "contracts/state-transition/chain-deps/facets/Admin.sol"; -import {AddressAliasHelper} from "contracts/vendor/AddressAliasHelper.sol"; -import {TxStatus} from "contracts/common/Messaging.sol"; -import {DataEncoding} from "contracts/common/libraries/DataEncoding.sol"; -import {IncorrectBridgeHubAddress} from "contracts/common/L1ContractErrors.sol"; - -contract GatewayTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer, L2TxMocker, GatewayDeployer { - uint256 constant TEST_USERS_COUNT = 10; - address[] public users; - address[] public l2ContractAddresses; - - uint256 migratingChainId = 10; - uint256 gatewayChainId = 11; - uint256 mintChainId = 12; - - // generate MAX_USERS addresses and append it to users array - function _generateUserAddresses() internal { - require(users.length == 0, "Addresses already generated"); - - for (uint256 i = 0; i < TEST_USERS_COUNT; i++) { - address newAddress = makeAddr(string(abi.encode("account", i))); - users.push(newAddress); - } - } - - function prepare() public { - _generateUserAddresses(); - - _deployL1Contracts(); - _deployTokens(); - _registerNewTokens(tokens); - - _deployEra(); - _deployZKChain(ETH_TOKEN_ADDRESS); - acceptPendingAdmin(); - _deployZKChain(ETH_TOKEN_ADDRESS); - acceptPendingAdmin(); - // _deployZKChain(tokens[0]); - // _deployZKChain(tokens[0]); - // _deployZKChain(tokens[1]); - // _deployZKChain(tokens[1]); - - for (uint256 i = 0; i < zkChainIds.length; i++) { - address contractAddress = makeAddr(string(abi.encode("contract", i))); - l2ContractAddresses.push(contractAddress); - - _addL2ChainContract(zkChainIds[i], contractAddress); - // _registerL2SharedBridge(zkChainIds[i], contractAddress); - } - - _initializeGatewayScript(); - - vm.deal(Ownable(l1Script.getBridgehubProxyAddress()).owner(), 100000000000000000000000000000000000); - vm.deal(l1Script.getOwnerAddress(), 100000000000000000000000000000000000); - IZKChain chain = IZKChain(IBridgehub(l1Script.getBridgehubProxyAddress()).getZKChain(migratingChainId)); - IZKChain chain2 = IZKChain(IBridgehub(l1Script.getBridgehubProxyAddress()).getZKChain(gatewayChainId)); - vm.deal(chain.getAdmin(), 100000000000000000000000000000000000); - vm.deal(chain2.getAdmin(), 100000000000000000000000000000000000); - - // vm.deal(msg.sender, 100000000000000000000000000000000000); - // vm.deal(l1Script.getBridgehubProxyAddress(), 100000000000000000000000000000000000); - } - - function setUp() public { - prepare(); - } - - // - function test_registerGateway() public { - gatewayScript.registerGateway(); - } - - // - function test_moveChainToGateway() public { - gatewayScript.registerGateway(); - gatewayScript.moveChainToGateway(); - // require(bridgehub.settlementLayer()) - } - - function test_l2Registration() public { - gatewayScript.registerGateway(); - gatewayScript.moveChainToGateway(); - gatewayScript.registerL2Contracts(); - } - - function test_finishMoveChain() public { - finishMoveChain(); - } - - function test_startMessageToL3() public { - finishMoveChain(); - IBridgehub bridgehub = IBridgehub(l1Script.getBridgehubProxyAddress()); - uint256 expectedValue = 1000000000000000000000; - - L2TransactionRequestDirect memory request = _createL2TransactionRequestDirect( - migratingChainId, - expectedValue, - 0, - 72000000, - 800, - "0x" - ); - bridgehub.requestL2TransactionDirect{value: expectedValue}(request); - } - - function test_forwardToL3OnGateway() public { - finishMoveChain(); - - IBridgehub bridgehub = IBridgehub(l1Script.getBridgehubProxyAddress()); - vm.chainId(12345); - vm.startBroadcast(SETTLEMENT_LAYER_RELAY_SENDER); - bridgehub.forwardTransactionOnGateway(mintChainId, bytes32(0), 0); - vm.stopBroadcast(); - } - - function test_recoverFromFailedChainMigration() public { - gatewayScript.registerGateway(); - gatewayScript.moveChainToGateway(); - - // Setup - IBridgehub bridgehub = IBridgehub(l1Script.getBridgehubProxyAddress()); - IChainTypeManager ctm = IChainTypeManager(l1Script.getCTM()); - bytes32 assetId = bridgehub.ctmAssetIdFromChainId(migratingChainId); - bytes memory transferData; - - { - IZKChain chain = IZKChain(bridgehub.getZKChain(migratingChainId)); - bytes memory initialDiamondCut = l1Script.getInitialDiamondCutData(); - bytes memory chainData = abi.encode(chain.getProtocolVersion()); - bytes memory ctmData = abi.encode(address(1), msg.sender, ctm.protocolVersion(), initialDiamondCut); - BridgehubBurnCTMAssetData memory data = BridgehubBurnCTMAssetData({ - chainId: migratingChainId, - ctmData: ctmData, - chainData: chainData - }); - transferData = abi.encode(data); - } - - address chainAdmin = IZKChain(bridgehub.getZKChain(migratingChainId)).getAdmin(); - IL1AssetRouter assetRouter = IL1AssetRouter(address(bridgehub.sharedBridge())); - bytes32 l2TxHash = keccak256("l2TxHash"); - uint256 l2BatchNumber = 5; - uint256 l2MessageIndex = 0; - uint16 l2TxNumberInBatch = 0; - bytes32[] memory merkleProof = new bytes32[](1); - bytes32 txDataHash = keccak256(bytes.concat(bytes1(0x01), abi.encode(chainAdmin, assetId, transferData))); - - // Mock Call for Msg Inclusion - vm.mockCall( - address(bridgehub), - abi.encodeWithSelector( - IBridgehub.proveL1ToL2TransactionStatus.selector, - migratingChainId, - l2TxHash, - l2BatchNumber, - l2MessageIndex, - l2TxNumberInBatch, - merkleProof, - TxStatus.Failure - ), - abi.encode(true) - ); - - // Set Deposit Happened - vm.startBroadcast(address(bridgeHub)); - assetRouter.bridgehubConfirmL2Transaction({ - _chainId: migratingChainId, - _txDataHash: txDataHash, - _txHash: l2TxHash - }); - vm.stopBroadcast(); - - vm.startBroadcast(); - l1Nullifier.bridgeRecoverFailedTransfer({ - _chainId: migratingChainId, - _depositSender: chainAdmin, - _assetId: assetId, - _assetData: transferData, - _l2TxHash: l2TxHash, - _l2BatchNumber: l2BatchNumber, - _l2MessageIndex: l2MessageIndex, - _l2TxNumberInBatch: l2TxNumberInBatch, - _merkleProof: merkleProof - }); - vm.stopBroadcast(); - } - - function test_registerAlreadyDeployedZKChain() public { - gatewayScript.registerGateway(); - IChainTypeManager stm = IChainTypeManager(l1Script.getCTM()); - IBridgehub bridgehub = IBridgehub(l1Script.getBridgehubProxyAddress()); - address owner = Ownable(address(bridgeHub)).owner(); - - { - uint256 chainId = currentZKChainId++; - bytes32 baseTokenAssetId = DataEncoding.encodeNTVAssetId(chainId, ETH_TOKEN_ADDRESS); - - address chain = _deployZkChain( - chainId, - baseTokenAssetId, - address(bridgehub.sharedBridge()), - owner, - stm.protocolVersion(), - stm.storedBatchZero(), - address(bridgehub) - ); - - address stmAddr = IZKChain(chain).getChainTypeManager(); - - vm.startBroadcast(owner); - bridgeHub.addChainTypeManager(stmAddr); - bridgeHub.addTokenAssetId(baseTokenAssetId); - bridgeHub.registerAlreadyDeployedZKChain(chainId, chain); - vm.stopBroadcast(); - - address bridgeHubStmForChain = bridgeHub.chainTypeManager(chainId); - bytes32 bridgeHubBaseAssetIdForChain = bridgeHub.baseTokenAssetId(chainId); - address bridgeHubChainAddressForChain = bridgeHub.getZKChain(chainId); - address bhAddr = IZKChain(chain).getBridgehub(); - - assertEq(bridgeHubStmForChain, stmAddr); - assertEq(bridgeHubBaseAssetIdForChain, baseTokenAssetId); - assertEq(bridgeHubChainAddressForChain, chain); - assertEq(bhAddr, address(bridgeHub)); - } - - { - uint256 chainId = currentZKChainId++; - bytes32 baseTokenAssetId = DataEncoding.encodeNTVAssetId(chainId, ETH_TOKEN_ADDRESS); - address chain = _deployZkChain( - chainId, - baseTokenAssetId, - address(bridgehub.sharedBridge()), - owner, - stm.protocolVersion(), - stm.storedBatchZero(), - address(bridgehub.sharedBridge()) - ); - - address stmAddr = IZKChain(chain).getChainTypeManager(); - - vm.startBroadcast(owner); - bridgeHub.addTokenAssetId(baseTokenAssetId); - vm.expectRevert( - abi.encodeWithSelector(IncorrectBridgeHubAddress.selector, address(bridgehub.sharedBridge())) - ); - bridgeHub.registerAlreadyDeployedZKChain(chainId, chain); - vm.stopBroadcast(); - } - } - - function finishMoveChain() public { - IBridgehub bridgehub = IBridgehub(l1Script.getBridgehubProxyAddress()); - IChainTypeManager ctm = IChainTypeManager(l1Script.getCTM()); - IZKChain migratingChain = IZKChain(bridgehub.getZKChain(migratingChainId)); - bytes32 assetId = bridgehub.ctmAssetIdFromChainId(migratingChainId); - - vm.startBroadcast(Ownable(address(bridgehub)).owner()); - bridgehub.registerSettlementLayer(gatewayChainId, true); - vm.stopBroadcast(); - - bytes32 baseTokenAssetId = keccak256("baseTokenAssetId"); - bytes memory initialDiamondCut = l1Script.getInitialDiamondCutData(); - bytes memory chainData = abi.encode(AdminFacet(address(migratingChain)).prepareChainCommitment()); - bytes memory ctmData = abi.encode(baseTokenAssetId, msg.sender, ctm.protocolVersion(), initialDiamondCut); - BridgehubMintCTMAssetData memory data = BridgehubMintCTMAssetData({ - chainId: mintChainId, - baseTokenAssetId: baseTokenAssetId, - ctmData: ctmData, - chainData: chainData - }); - bytes memory bridgehubMintData = abi.encode(data); - vm.startBroadcast(address(bridgehub.sharedBridge())); - uint256 currentChainId = block.chainid; - vm.chainId(migratingChainId); - bridgehub.bridgeMint(gatewayChainId, assetId, bridgehubMintData); - vm.stopBroadcast(); - vm.chainId(currentChainId); - - assertEq(bridgehub.baseTokenAssetId(mintChainId), baseTokenAssetId); - IZKChain mintedZKChain = IZKChain(bridgehub.getZKChain(mintChainId)); - assertEq(mintedZKChain.getBaseTokenAssetId(), baseTokenAssetId); - } - - // add this to be excluded from coverage report - function test() internal override {} -} diff --git a/l1-contracts/test/foundry/l2/unit/erc20/L2Erc20BridgeTest.t.sol b/l1-contracts/test/foundry/l2/unit/erc20/L2Erc20BridgeTest.t.sol deleted file mode 100644 index 1b9535108..000000000 --- a/l1-contracts/test/foundry/l2/unit/erc20/L2Erc20BridgeTest.t.sol +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.20; - -// solhint-disable gas-custom-errors - -import {Test} from "forge-std/Test.sol"; -import "forge-std/console.sol"; - -import {BridgedStandardERC20} from "contracts/bridge/BridgedStandardERC20.sol"; -import {L2AssetRouter} from "contracts/bridge/asset-router/L2AssetRouter.sol"; -import {IL2NativeTokenVault} from "contracts/bridge/ntv/IL2NativeTokenVault.sol"; - -import {UpgradeableBeacon} from "@openzeppelin/contracts-v4/proxy/beacon/UpgradeableBeacon.sol"; -import {BeaconProxy} from "@openzeppelin/contracts-v4/proxy/beacon/BeaconProxy.sol"; - -import {L2_ASSET_ROUTER_ADDR, L2_NATIVE_TOKEN_VAULT_ADDR} from "contracts/common/L2ContractAddresses.sol"; - -import {AddressAliasHelper} from "contracts/vendor/AddressAliasHelper.sol"; - -import {L2Utils} from "../utils/L2Utils.sol"; - -contract L2Erc20BridgeTest is Test { - // We need to emulate a L1->L2 transaction from the L1 bridge to L2 counterpart. - // It is a bit easier to use EOA and it is sufficient for the tests. - address internal l1BridgeWallet = address(1); - address internal aliasedL1BridgeWallet; - - // The owner of the beacon and the native token vault - address internal ownerWallet = address(2); - - BridgedStandardERC20 internal standardErc20Impl; - - UpgradeableBeacon internal beacon; - BeaconProxy internal proxy; - - uint256 internal constant L1_CHAIN_ID = 9; - uint256 internal ERA_CHAIN_ID = 270; - - // We won't actually deploy an L1 token in these tests, but we need some address for it. - address internal L1_TOKEN_ADDRESS = 0x1111100000000000000000000000000000011111; - - string internal constant TOKEN_DEFAULT_NAME = "TestnetERC20Token"; - string internal constant TOKEN_DEFAULT_SYMBOL = "TET"; - uint8 internal constant TOKEN_DEFAULT_DECIMALS = 18; - - function setUp() public { - aliasedL1BridgeWallet = AddressAliasHelper.applyL1ToL2Alias(l1BridgeWallet); - - standardErc20Impl = new BridgedStandardERC20(); - beacon = new UpgradeableBeacon(address(standardErc20Impl)); - beacon.transferOwnership(ownerWallet); - - // One of the purposes of deploying it here is to publish its bytecode - BeaconProxy beaconProxy = new BeaconProxy(address(beacon), new bytes(0)); - proxy = beaconProxy; - bytes32 beaconProxyBytecodeHash; - assembly { - beaconProxyBytecodeHash := extcodehash(beaconProxy) - } - - L2Utils.initSystemContracts(); - L2Utils.forceDeployAssetRouter(L1_CHAIN_ID, ERA_CHAIN_ID, l1BridgeWallet, address(0)); - L2Utils.forceDeployNativeTokenVault({ - _l1ChainId: L1_CHAIN_ID, - _aliasedOwner: ownerWallet, - _l2TokenProxyBytecodeHash: beaconProxyBytecodeHash, - _legacySharedBridge: address(0), - _l2TokenBeacon: address(beacon), - _contractsDeployedAlready: true - }); - } - - function performDeposit(address depositor, address receiver, uint256 amount) internal { - vm.prank(aliasedL1BridgeWallet); - L2AssetRouter(L2_ASSET_ROUTER_ADDR).finalizeDeposit({ - _l1Sender: depositor, - _l2Receiver: receiver, - _l1Token: L1_TOKEN_ADDRESS, - _amount: amount, - _data: L2Utils.encodeTokenData(TOKEN_DEFAULT_NAME, TOKEN_DEFAULT_SYMBOL, TOKEN_DEFAULT_DECIMALS) - }); - } - - function initializeTokenByDeposit() internal returns (address l2TokenAddress) { - performDeposit(makeAddr("someDepositor"), makeAddr("someReeiver"), 1); - - l2TokenAddress = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).l2TokenAddress(L1_TOKEN_ADDRESS); - require(l2TokenAddress != address(0), "Token not initialized"); - } - - function test_shouldFinalizeERC20Deposit() public { - address depositor = makeAddr("depositor"); - address receiver = makeAddr("receiver"); - - performDeposit(depositor, receiver, 100); - - address l2TokenAddress = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).l2TokenAddress(L1_TOKEN_ADDRESS); - - assertEq(BridgedStandardERC20(l2TokenAddress).balanceOf(receiver), 100); - assertEq(BridgedStandardERC20(l2TokenAddress).totalSupply(), 100); - assertEq(BridgedStandardERC20(l2TokenAddress).name(), TOKEN_DEFAULT_NAME); - assertEq(BridgedStandardERC20(l2TokenAddress).symbol(), TOKEN_DEFAULT_SYMBOL); - assertEq(BridgedStandardERC20(l2TokenAddress).decimals(), TOKEN_DEFAULT_DECIMALS); - } - - function test_governanceShouldBeAbleToReinitializeToken() public { - address l2TokenAddress = initializeTokenByDeposit(); - - BridgedStandardERC20.ERC20Getters memory getters = BridgedStandardERC20.ERC20Getters({ - ignoreName: false, - ignoreSymbol: false, - ignoreDecimals: false - }); - - vm.prank(ownerWallet); - BridgedStandardERC20(l2TokenAddress).reinitializeToken(getters, "TestTokenNewName", "TTN", 2); - assertEq(BridgedStandardERC20(l2TokenAddress).name(), "TestTokenNewName"); - assertEq(BridgedStandardERC20(l2TokenAddress).symbol(), "TTN"); - // The decimals should stay the same - assertEq(BridgedStandardERC20(l2TokenAddress).decimals(), 18); - } - - function test_governanceShouldNotBeAbleToSkipInitializerVersions() public { - address l2TokenAddress = initializeTokenByDeposit(); - - BridgedStandardERC20.ERC20Getters memory getters = BridgedStandardERC20.ERC20Getters({ - ignoreName: false, - ignoreSymbol: false, - ignoreDecimals: false - }); - - vm.expectRevert(); - vm.prank(ownerWallet); - BridgedStandardERC20(l2TokenAddress).reinitializeToken(getters, "TestTokenNewName", "TTN", 20); - } -} diff --git a/l1-contracts/test/foundry/l2/unit/utils/L2Utils.sol b/l1-contracts/test/foundry/l2/unit/utils/L2Utils.sol deleted file mode 100644 index 2c46774f4..000000000 --- a/l1-contracts/test/foundry/l2/unit/utils/L2Utils.sol +++ /dev/null @@ -1,167 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.20; - -import {Vm} from "forge-std/Vm.sol"; - -import {DEPLOYER_SYSTEM_CONTRACT, L2_ASSET_ROUTER_ADDR, L2_NATIVE_TOKEN_VAULT_ADDR} from "contracts/common/L2ContractAddresses.sol"; -import {IContractDeployer, L2ContractHelper} from "contracts/common/libraries/L2ContractHelper.sol"; - -import {L2AssetRouter} from "contracts/bridge/asset-router/L2AssetRouter.sol"; -import {L2NativeTokenVault} from "contracts/bridge/ntv/L2NativeTokenVault.sol"; - -import {ETH_TOKEN_ADDRESS} from "contracts/common/Config.sol"; - -import {DataEncoding} from "contracts/common/libraries/DataEncoding.sol"; - -library L2Utils { - address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); - Vm internal constant vm = Vm(VM_ADDRESS); - - address internal constant L2_FORCE_DEPLOYER_ADDR = address(0x8007); - - string internal constant L2_ASSET_ROUTER_PATH = "./zkout/L2AssetRouter.sol/L2AssetRouter.json"; - string internal constant L2_NATIVE_TOKEN_VAULT_PATH = "./zkout/L2NativeTokenVault.sol/L2NativeTokenVault.json"; - - /// @notice Returns the bytecode of a given era contract from a `zkout` folder. - function readEraBytecode(string memory _filename) internal returns (bytes memory bytecode) { - string memory artifact = vm.readFile( - // solhint-disable-next-line func-named-parameters - string.concat("./zkout/", _filename, ".sol/", _filename, ".json") - ); - - bytecode = vm.parseJsonBytes(artifact, ".bytecode.object"); - } - - /// @notice Returns the bytecode of a given system contract. - function readSystemContractsBytecode(string memory _filename) internal view returns (bytes memory) { - string memory file = vm.readFile( - // solhint-disable-next-line func-named-parameters - string.concat( - "../system-contracts/artifacts-zk/contracts-preprocessed/", - _filename, - ".sol/", - _filename, - ".json" - ) - ); - bytes memory bytecode = vm.parseJson(file, "$.bytecode"); - return bytecode; - } - - /** - * @dev Initializes the system contracts. - * @dev It is a hack needed to make the tests be able to call system contracts directly. - */ - function initSystemContracts() internal { - bytes memory contractDeployerBytecode = readSystemContractsBytecode("ContractDeployer"); - vm.etch(DEPLOYER_SYSTEM_CONTRACT, contractDeployerBytecode); - } - - /// @notice Deploys the L2AssetRouter contract. - /// @param _l1ChainId The chain ID of the L1 chain. - /// @param _eraChainId The chain ID of the era chain. - /// @param _l1AssetRouter The address of the L1 asset router. - /// @param _legacySharedBridge The address of the legacy shared bridge. - function forceDeployAssetRouter( - uint256 _l1ChainId, - uint256 _eraChainId, - address _l1AssetRouter, - address _legacySharedBridge - ) internal { - // to ensure that the bytecode is known - bytes32 ethAssetId = DataEncoding.encodeNTVAssetId(_l1ChainId, ETH_TOKEN_ADDRESS); - { - new L2AssetRouter(_l1ChainId, _eraChainId, _l1AssetRouter, _legacySharedBridge, ethAssetId); - } - - bytes memory bytecode = readEraBytecode("L2AssetRouter"); - - bytes32 bytecodehash = L2ContractHelper.hashL2Bytecode(bytecode); - - IContractDeployer.ForceDeployment[] memory deployments = new IContractDeployer.ForceDeployment[](1); - deployments[0] = IContractDeployer.ForceDeployment({ - bytecodeHash: bytecodehash, - newAddress: L2_ASSET_ROUTER_ADDR, - callConstructor: true, - value: 0, - input: abi.encode(_l1ChainId, _eraChainId, _l1AssetRouter, _legacySharedBridge, ethAssetId) - }); - - vm.prank(L2_FORCE_DEPLOYER_ADDR); - IContractDeployer(DEPLOYER_SYSTEM_CONTRACT).forceDeployOnAddresses(deployments); - } - - /// @notice Deploys the L2NativeTokenVault contract. - /// @param _l1ChainId The chain ID of the L1 chain. - /// @param _aliasedOwner The address of the aliased owner. - /// @param _l2TokenProxyBytecodeHash The hash of the L2 token proxy bytecode. - /// @param _legacySharedBridge The address of the legacy shared bridge. - /// @param _l2TokenBeacon The address of the L2 token beacon. - /// @param _contractsDeployedAlready Whether the contracts are deployed already. - function forceDeployNativeTokenVault( - uint256 _l1ChainId, - address _aliasedOwner, - bytes32 _l2TokenProxyBytecodeHash, - address _legacySharedBridge, - address _l2TokenBeacon, - bool _contractsDeployedAlready - ) internal { - // to ensure that the bytecode is known - bytes32 ethAssetId = DataEncoding.encodeNTVAssetId(_l1ChainId, ETH_TOKEN_ADDRESS); - { - new L2NativeTokenVault({ - _l1ChainId: _l1ChainId, - _aliasedOwner: _aliasedOwner, - _l2TokenProxyBytecodeHash: _l2TokenProxyBytecodeHash, - _legacySharedBridge: _legacySharedBridge, - _bridgedTokenBeacon: _l2TokenBeacon, - _contractsDeployedAlready: _contractsDeployedAlready, - _wethToken: address(0), - _baseTokenAssetId: ethAssetId - }); - } - - bytes memory bytecode = readEraBytecode("L2NativeTokenVault"); - - bytes32 bytecodehash = L2ContractHelper.hashL2Bytecode(bytecode); - - IContractDeployer.ForceDeployment[] memory deployments = new IContractDeployer.ForceDeployment[](1); - deployments[0] = IContractDeployer.ForceDeployment({ - bytecodeHash: bytecodehash, - newAddress: L2_NATIVE_TOKEN_VAULT_ADDR, - callConstructor: true, - value: 0, - // solhint-disable-next-line func-named-parameters - input: abi.encode( - _l1ChainId, - _aliasedOwner, - _l2TokenProxyBytecodeHash, - _legacySharedBridge, - _l2TokenBeacon, - _contractsDeployedAlready, - address(0), - ethAssetId - ) - }); - - vm.prank(L2_FORCE_DEPLOYER_ADDR); - IContractDeployer(DEPLOYER_SYSTEM_CONTRACT).forceDeployOnAddresses(deployments); - } - - /// @notice Encodes the token data. - /// @param name The name of the token. - /// @param symbol The symbol of the token. - /// @param decimals The decimals of the token. - function encodeTokenData( - string memory name, - string memory symbol, - uint8 decimals - ) internal pure returns (bytes memory) { - bytes memory encodedName = abi.encode(name); - bytes memory encodedSymbol = abi.encode(symbol); - bytes memory encodedDecimals = abi.encode(decimals); - - return abi.encode(encodedName, encodedSymbol, encodedDecimals); - } -} diff --git a/l1-contracts/test/foundry/l2/unit/weth/WETH.t.sol b/l1-contracts/test/foundry/l2/unit/weth/WETH.t.sol deleted file mode 100644 index 6cbc44fa7..000000000 --- a/l1-contracts/test/foundry/l2/unit/weth/WETH.t.sol +++ /dev/null @@ -1,118 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.20; - -import {Test} from "forge-std/Test.sol"; - -import {L2WrappedBaseToken} from "contracts/bridge/L2WrappedBaseToken.sol"; -import {TransparentUpgradeableProxy} from "@openzeppelin/contracts-v4/proxy/transparent/TransparentUpgradeableProxy.sol"; - -import {Unauthorized, UnimplementedMessage, BridgeMintNotImplemented} from "contracts/common/L1ContractErrors.sol"; - -contract WethTest is Test { - L2WrappedBaseToken internal weth; - - // The owner of the proxy - address internal ownerWallet = address(2); - - address internal l2BridgeAddress = address(3); - address internal l1Address = address(4); - - function setUp() public { - ownerWallet = makeAddr("owner"); - L2WrappedBaseToken impl = new L2WrappedBaseToken(); - - TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(impl), ownerWallet, ""); - - weth = L2WrappedBaseToken(payable(proxy)); - - weth.initializeV2("Wrapped Ether", "WETH", l2BridgeAddress, l1Address); - } - - function test_shouldDepositWethByCallingDeposit() public { - uint256 amount = 100; - weth.deposit{value: amount}(); - assertEq(weth.balanceOf(address(this)), amount); - } - - function test_shouldDepositWethBySendingEth() public { - uint256 amount = 100; - address(weth).call{value: amount}(""); - assertEq(weth.balanceOf(address(this)), amount); - } - - function test_revertWhenDepositingWithRandomCalldata() public { - (bool success, ) = address(weth).call{value: 100}(hex"00000000"); - assertEq(success, false); - } - - function test_shouldWithdrawWethToL2Eth() public { - address sender = makeAddr("sender"); - uint256 amount = 100; - - vm.deal(sender, amount); - - vm.prank(sender); - weth.deposit{value: amount}(); - - vm.prank(sender); - weth.withdraw(amount); - - assertEq(weth.balanceOf(sender), 0); - assertEq(address(sender).balance, amount); - } - - function test_shouldDepositWethToAnotherAccount() public { - address sender = makeAddr("sender"); - address receiver = makeAddr("receiver"); - - uint256 amount = 100; - - vm.deal(sender, amount); - - vm.prank(sender); - weth.depositTo{value: amount}(receiver); - - assertEq(weth.balanceOf(receiver), amount); - assertEq(weth.balanceOf(sender), 0); - } - - function test_shouldWithdrawWethToAnotherAccount() public { - address sender = makeAddr("sender"); - address receiver = makeAddr("receiver"); - - uint256 amount = 100; - - vm.deal(sender, amount); - - vm.prank(sender); - weth.deposit{value: amount}(); - - vm.prank(sender); - weth.withdrawTo(receiver, amount); - - assertEq(receiver.balance, amount); - assertEq(sender.balance, 0); - } - - function test_revertWhenWithdrawingMoreThanBalance() public { - vm.expectRevert(); - weth.withdraw(1); - } - - function test_revertWhenCallingBridgeMint() public { - vm.expectRevert(abi.encodeWithSelector(BridgeMintNotImplemented.selector)); - vm.prank(l2BridgeAddress); - weth.bridgeMint(address(1), 1); - } - - function test_revertWhenCallingBridgeMintDirectly() public { - vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, address(this))); - weth.bridgeMint(address(1), 1); - } - - function test_revertWhenCallingBridgeBurnDirectly() public { - vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, address(this))); - weth.bridgeBurn(address(1), 1); - } -} diff --git a/system-contracts/contracts/PubdataChunkPublisher.sol b/system-contracts/contracts/PubdataChunkPublisher.sol index 449c2655f..7c2abf2e1 100644 --- a/system-contracts/contracts/PubdataChunkPublisher.sol +++ b/system-contracts/contracts/PubdataChunkPublisher.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.24; import {IPubdataChunkPublisher} from "./interfaces/IPubdataChunkPublisher.sol"; -import {SystemContractBase} from "./abstract/SystemContractBase.sol"; import {BLOB_SIZE_BYTES, MAX_NUMBER_OF_BLOBS} from "./Constants.sol"; import {TooMuchPubdata} from "./SystemContractErrors.sol";