Commit d9d3c738 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: erc721 bridge single impl

Update the ERC721 bridge so that a single implementation
can be used across many different chains.

Still need to double check the storage layout before this
is good, but the tests are passing.

Also need to update all the code that touches the go bindings.
parent 92855691
...@@ -435,14 +435,9 @@ contract Deploy is Deployer { ...@@ -435,14 +435,9 @@ contract Deploy is Deployer {
/// @notice Deploy the L1ERC721Bridge /// @notice Deploy the L1ERC721Bridge
function deployL1ERC721Bridge() broadcast() public returns (address) { function deployL1ERC721Bridge() broadcast() public returns (address) {
address l1CrossDomainMessengerProxy = mustGetAddress("L1CrossDomainMessengerProxy"); L1ERC721Bridge bridge = new L1ERC721Bridge();
L1ERC721Bridge bridge = new L1ERC721Bridge({
_messenger: l1CrossDomainMessengerProxy,
_otherBridge: Predeploys.L2_ERC721_BRIDGE
});
require(address(bridge.MESSENGER()) == l1CrossDomainMessengerProxy); require(address(bridge.MESSENGER()) == address(0));
require(bridge.OTHER_BRIDGE() == Predeploys.L2_ERC721_BRIDGE); require(bridge.OTHER_BRIDGE() == Predeploys.L2_ERC721_BRIDGE);
save("L1ERC721Bridge", address(bridge)); save("L1ERC721Bridge", address(bridge));
...@@ -574,9 +569,13 @@ contract Deploy is Deployer { ...@@ -574,9 +569,13 @@ contract Deploy is Deployer {
address l1ERC721Bridge = mustGetAddress("L1ERC721Bridge"); address l1ERC721Bridge = mustGetAddress("L1ERC721Bridge");
address l1CrossDomainMessengerProxy = mustGetAddress("L1CrossDomainMessengerProxy"); address l1CrossDomainMessengerProxy = mustGetAddress("L1CrossDomainMessengerProxy");
proxyAdmin.upgrade({ proxyAdmin.upgradeAndCall({
_proxy: payable(l1ERC721BridgeProxy), _proxy: payable(l1ERC721BridgeProxy),
_implementation: l1ERC721Bridge _implementation: l1ERC721Bridge,
_data: abi.encodeCall(
L1ERC721Bridge.initialize,
(CrossDomainMessenger(l1CrossDomainMessengerProxy))
)
}); });
L1ERC721Bridge bridge = L1ERC721Bridge(l1ERC721BridgeProxy); L1ERC721Bridge bridge = L1ERC721Bridge(l1ERC721BridgeProxy);
......
...@@ -6,6 +6,7 @@ import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; ...@@ -6,6 +6,7 @@ import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { L2ERC721Bridge } from "../L2/L2ERC721Bridge.sol"; import { L2ERC721Bridge } from "../L2/L2ERC721Bridge.sol";
import { Semver } from "../universal/Semver.sol"; import { Semver } from "../universal/Semver.sol";
import { Predeploys } from "../libraries/Predeploys.sol"; import { Predeploys } from "../libraries/Predeploys.sol";
import { CrossDomainMessenger } from "../universal/CrossDomainMessenger.sol";
/// @title L1ERC721Bridge /// @title L1ERC721Bridge
/// @notice The L1 ERC721 bridge is a contract which works together with the L2 ERC721 bridge to /// @notice The L1 ERC721 bridge is a contract which works together with the L2 ERC721 bridge to
...@@ -23,13 +24,13 @@ contract L1ERC721Bridge is ERC721Bridge, Semver { ...@@ -23,13 +24,13 @@ contract L1ERC721Bridge is ERC721Bridge, Semver {
ERC721Bridge(Predeploys.L2_ERC721_BRIDGE) ERC721Bridge(Predeploys.L2_ERC721_BRIDGE)
{ {
initialize({ initialize({
_messenger: address(0) _messenger: CrossDomainMessenger(address(0))
}); });
} }
/// @notice Initializes the contract. /// @notice Initializes the contract.
/// @param _messenger Address of the CrossDomainMessenger on this network. /// @param _messenger Address of the CrossDomainMessenger on this network.
function initialize(address _messenger) public reinitializer(1) { function initialize(CrossDomainMessenger _messenger) public reinitializer(1) {
__ERC721Bridge_init(_messenger); __ERC721Bridge_init(_messenger);
} }
......
...@@ -5,6 +5,7 @@ import { ERC721Bridge } from "../universal/ERC721Bridge.sol"; ...@@ -5,6 +5,7 @@ import { ERC721Bridge } from "../universal/ERC721Bridge.sol";
import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import { L1ERC721Bridge } from "../L1/L1ERC721Bridge.sol"; import { L1ERC721Bridge } from "../L1/L1ERC721Bridge.sol";
import { IOptimismMintableERC721 } from "../universal/IOptimismMintableERC721.sol"; import { IOptimismMintableERC721 } from "../universal/IOptimismMintableERC721.sol";
import { CrossDomainMessenger } from "../universal/CrossDomainMessenger.sol";
import { Semver } from "../universal/Semver.sol"; import { Semver } from "../universal/Semver.sol";
/// @title L2ERC721Bridge /// @title L2ERC721Bridge
...@@ -25,13 +26,13 @@ contract L2ERC721Bridge is ERC721Bridge, Semver { ...@@ -25,13 +26,13 @@ contract L2ERC721Bridge is ERC721Bridge, Semver {
ERC721Bridge(_otherBridge) ERC721Bridge(_otherBridge)
{ {
initialize({ initialize({
_messenger: address(0) _messenger: CrossDomainMessenger(address(0))
}); });
} }
/// @notice Initializes the contract. /// @notice Initializes the contract.
/// @param _messenger Address of the CrossDomainMessenger on this network. /// @param _messenger Address of the CrossDomainMessenger on this network.
function initialize(address _messenger) public reinitializer(1) { function initialize(CrossDomainMessenger _messenger) public reinitializer(1) {
__ERC721Bridge_init(_messenger); __ERC721Bridge_init(_messenger);
} }
......
...@@ -68,7 +68,6 @@ abstract contract ERC721Bridge is Initializable { ...@@ -68,7 +68,6 @@ abstract contract ERC721Bridge is Initializable {
// @notice Initializes the contract. // @notice Initializes the contract.
/// @param _messenger Address of the CrossDomainMessenger on this network. /// @param _messenger Address of the CrossDomainMessenger on this network.
function __ERC721Bridge_init(CrossDomainMessenger _messenger) internal onlyInitializing { function __ERC721Bridge_init(CrossDomainMessenger _messenger) internal onlyInitializing {
require(address(_messenger) != address(0), "ERC721Bridge: messenger cannot be address(0)");
MESSENGER = _messenger; MESSENGER = _messenger;
} }
......
...@@ -29,6 +29,7 @@ import { ResolvedDelegateProxy } from "../src/legacy/ResolvedDelegateProxy.sol"; ...@@ -29,6 +29,7 @@ import { ResolvedDelegateProxy } from "../src/legacy/ResolvedDelegateProxy.sol";
import { AddressManager } from "../src/legacy/AddressManager.sol"; import { AddressManager } from "../src/legacy/AddressManager.sol";
import { L1ChugSplashProxy } from "../src/legacy/L1ChugSplashProxy.sol"; import { L1ChugSplashProxy } from "../src/legacy/L1ChugSplashProxy.sol";
import { IL1ChugSplashDeployer } from "../src/legacy/L1ChugSplashProxy.sol"; import { IL1ChugSplashDeployer } from "../src/legacy/L1ChugSplashProxy.sol";
import { CrossDomainMessenger } from "../src/universal/CrossDomainMessenger.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { LegacyMintableERC20 } from "../src/legacy/LegacyMintableERC20.sol"; import { LegacyMintableERC20 } from "../src/legacy/LegacyMintableERC20.sol";
import { SystemConfig } from "../src/L1/SystemConfig.sol"; import { SystemConfig } from "../src/L1/SystemConfig.sol";
...@@ -507,7 +508,7 @@ contract ERC721Bridge_Initializer is Messenger_Initializer { ...@@ -507,7 +508,7 @@ contract ERC721Bridge_Initializer is Messenger_Initializer {
address(l1BridgeImpl), address(l1BridgeImpl),
abi.encodeCall( abi.encodeCall(
L1ERC721Bridge.initialize, L1ERC721Bridge.initialize,
address(L1Messenger) (CrossDomainMessenger(L1Messenger))
) )
); );
...@@ -516,14 +517,17 @@ contract ERC721Bridge_Initializer is Messenger_Initializer { ...@@ -516,14 +517,17 @@ contract ERC721Bridge_Initializer is Messenger_Initializer {
// Deploy the implementation for the L2ERC721Bridge and etch it into the predeploy address. // Deploy the implementation for the L2ERC721Bridge and etch it into the predeploy address.
L2ERC721Bridge l2BridgeImpl = new L2ERC721Bridge(address(L1Bridge)); L2ERC721Bridge l2BridgeImpl = new L2ERC721Bridge(address(L1Bridge));
Proxy l2BridgeProxy = new Proxy(multisig); Proxy l2BridgeProxy = new Proxy(multisig);
vm.etch(Predeploys.L2_ERC721_BRIDGE, l2BridgeProxy.code); vm.etch(Predeploys.L2_ERC721_BRIDGE, address(l2BridgeProxy).code);
// set the storage slot for admin and implementation
bytes32 IMPLEMENTATION_KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; // set the storage slot for admin
bytes32 OWNER_KEY = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; bytes32 OWNER_KEY = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
vm.store(Predeploys.L2_ERC721_BRIDGE, OWNER_KEY, bytes32(uint256(uint160(multisig))));
vm.store(Predeploys.L2_ERC721_BRIDGE, IMPLEMENTATION_KEY, address(l2BridgeProxy)); vm.prank(multisig);
vm.store(Predeploys.L2_ERC721_BRIDGE, OWNER_KEY, multisig); Proxy(payable(Predeploys.L2_ERC721_BRIDGE)).upgradeToAndCall(
address(l2BridgeImpl),
abi.encodeCall(L2ERC721Bridge.initialize, (L2Messenger))
);
// Set up a reference to the L2ERC721Bridge. // Set up a reference to the L2ERC721Bridge.
L2Bridge = L2ERC721Bridge(Predeploys.L2_ERC721_BRIDGE); L2Bridge = L2ERC721Bridge(Predeploys.L2_ERC721_BRIDGE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment