-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clone of matter-labs/era-contracts-private#10, but targeted towards the gateway release candidate
- Loading branch information
1 parent
502ee80
commit 7d809dd
Showing
15 changed files
with
272 additions
and
105 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
l1-contracts/contracts/dev-contracts/L2SharedBridgeLegacyDev.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import {UpgradeableBeacon} from "@openzeppelin/contracts-v4/proxy/beacon/UpgradeableBeacon.sol"; | ||
|
||
import {BridgedStandardERC20} from "../bridge/BridgedStandardERC20.sol"; | ||
|
||
import {L2SharedBridgeLegacy} from "../bridge/L2SharedBridgeLegacy.sol"; | ||
import {InvalidCaller, ZeroAddress, EmptyBytes32, Unauthorized, AmountMustBeGreaterThanZero, DeployFailed} from "../common/L1ContractErrors.sol"; | ||
|
||
contract L2SharedBridgeLegacyDev is L2SharedBridgeLegacy { | ||
constructor() L2SharedBridgeLegacy() {} | ||
|
||
/// @notice Initializes the bridge contract for later use. Expected to be used in the proxy. | ||
/// @param _legacyBridge The address of the L1 Bridge contract. | ||
/// @param _l1SharedBridge The address of the L1 Bridge contract. | ||
/// @param _l2TokenProxyBytecodeHash The bytecode hash of the proxy for tokens deployed by the bridge. | ||
/// @param _aliasedOwner The address of the governor contract. | ||
function initializeDevBridge( | ||
address _legacyBridge, | ||
address _l1SharedBridge, | ||
bytes32 _l2TokenProxyBytecodeHash, | ||
address _aliasedOwner | ||
) external reinitializer(2) { | ||
if (_l1SharedBridge == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
|
||
if (_l2TokenProxyBytecodeHash == bytes32(0)) { | ||
revert EmptyBytes32(); | ||
} | ||
|
||
if (_aliasedOwner == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
|
||
l1SharedBridge = _l1SharedBridge; | ||
l1Bridge = _legacyBridge; | ||
|
||
// The following statement is true only in freshly deployed environments. However, | ||
// for those environments we do not need to deploy this contract at all. | ||
// This check is primarily for local testing purposes. | ||
if (l2TokenProxyBytecodeHash == bytes32(0) && address(l2TokenBeacon) == address(0)) { | ||
address l2StandardToken = address(new BridgedStandardERC20{salt: bytes32(0)}()); | ||
l2TokenBeacon = new UpgradeableBeacon{salt: bytes32(0)}(l2StandardToken); | ||
l2TokenProxyBytecodeHash = _l2TokenProxyBytecodeHash; | ||
l2TokenBeacon.transferOwnership(_aliasedOwner); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
l1-contracts/deploy-script-config-template/config-deploy-l1.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
l1-contracts/deploy-scripts/L2LegacySharedBridgeTestHelper.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {L2ContractsBytecodesLib} from "./L2ContractsBytecodesLib.sol"; | ||
import {L2ContractHelper} from "contracts/common/libraries/L2ContractHelper.sol"; | ||
import {Utils} from "./Utils.sol"; | ||
import {L2SharedBridgeLegacyDev} from "contracts/dev-contracts/L2SharedBridgeLegacyDev.sol"; | ||
import {AddressAliasHelper} from "contracts/vendor/AddressAliasHelper.sol"; | ||
|
||
library L2LegacySharedBridgeTestHelper { | ||
function calculateL2LegacySharedBridgeProxyAddr( | ||
address l1Erc20BridgeProxy, | ||
address l1NullifierProxy, | ||
address ecosystemL1Governance | ||
) internal view returns (address) { | ||
// During local testing, we will deploy `L2SharedBridgeLegacyDev` to each chain | ||
// that supports the legacy bridge. | ||
|
||
bytes32 implHash = L2ContractHelper.hashL2Bytecode( | ||
L2ContractsBytecodesLib.readL2LegacySharedBridgeDevBytecode() | ||
); | ||
address implAddress = Utils.getL2AddressViaCreate2Factory(bytes32(0), implHash, hex""); | ||
|
||
bytes32 proxyHash = L2ContractHelper.hashL2Bytecode( | ||
L2ContractsBytecodesLib.readTransparentUpgradeableProxyBytecode() | ||
); | ||
|
||
return | ||
Utils.getL2AddressViaCreate2Factory( | ||
bytes32(0), | ||
proxyHash, | ||
getLegacySharedBridgeProxyConstructorParams( | ||
implAddress, | ||
l1Erc20BridgeProxy, | ||
l1NullifierProxy, | ||
ecosystemL1Governance | ||
) | ||
); | ||
} | ||
|
||
function getLegacySharedBridgeProxyConstructorParams( | ||
address _implAddress, | ||
address _l1Erc20BridgeProxy, | ||
address _l1NullifierProxy, | ||
address _ecosystemL1Governance | ||
) internal view returns (bytes memory) { | ||
bytes32 beaconProxyBytecodeHash = L2ContractHelper.hashL2Bytecode( | ||
L2ContractsBytecodesLib.readBeaconProxyBytecode() | ||
); | ||
|
||
bytes memory initializeData = abi.encodeCall( | ||
L2SharedBridgeLegacyDev.initializeDevBridge, | ||
( | ||
_l1Erc20BridgeProxy, | ||
// While the variable is named `sharedBridge`, in reality it will have the same | ||
// address as the nullifier | ||
_l1NullifierProxy, | ||
beaconProxyBytecodeHash, | ||
AddressAliasHelper.applyL1ToL2Alias(_ecosystemL1Governance) | ||
) | ||
); | ||
|
||
return abi.encode(_implAddress, AddressAliasHelper.applyL1ToL2Alias(_ecosystemL1Governance), initializeData); | ||
} | ||
|
||
function calculateTestL2TokenBeaconAddress( | ||
address l1Erc20BridgeProxy, | ||
address l1NullifierProxy, | ||
address ecosystemL1Governance | ||
) internal view returns (address tokenBeaconAddress, bytes32 tokenBeaconBytecodeHash) { | ||
address l2SharedBridgeAddress = calculateL2LegacySharedBridgeProxyAddr( | ||
l1Erc20BridgeProxy, | ||
l1NullifierProxy, | ||
ecosystemL1Governance | ||
); | ||
|
||
bytes32 bridgedL2ERC20Hash = L2ContractHelper.hashL2Bytecode( | ||
L2ContractsBytecodesLib.readStandardERC20Bytecode() | ||
); | ||
address bridgeL2ERC20ImplAddress = L2ContractHelper.computeCreate2Address( | ||
l2SharedBridgeAddress, | ||
bytes32(0), | ||
bridgedL2ERC20Hash, | ||
keccak256(hex"") | ||
); | ||
|
||
tokenBeaconBytecodeHash = L2ContractHelper.hashL2Bytecode( | ||
L2ContractsBytecodesLib.readUpgradeableBeaconBytecode() | ||
); | ||
tokenBeaconAddress = L2ContractHelper.computeCreate2Address( | ||
l2SharedBridgeAddress, | ||
bytes32(0), | ||
tokenBeaconBytecodeHash, | ||
keccak256(abi.encode(bridgeL2ERC20ImplAddress)) | ||
); | ||
} | ||
} |
Oops, something went wrong.