Skip to content

Commit

Permalink
Use initializers.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Nov 27, 2023
1 parent 643c47b commit 490c5bd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Use the contract addresses from the management contract deployment.
const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!!
const messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!!
console.log(`Management Contract address ${mgmtContractAddress}`);
console.log(`Message Bus address ${messageBusAddress}`);

// Setup the cross chain messenger and point it to the message bus from the management contract to be used for validation
Expand Down

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion contracts/src/bridge/L1/ObscuroBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "../ITokenFactory.sol";
import "../../messaging/messenger/CrossChainEnabledObscuro.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";


// This is the Ethereum side of the Obscuro Bridge.
// End-users can interact with it to transfer ERC20 tokens and native eth to the Layer 2 Obscuro.
Expand All @@ -30,7 +32,7 @@ contract ObscuroBridge is

address remoteBridgeAddress;

function initialize(address messenger) external {
function initialize(address messenger) public initializer() {
CrossChainEnabledObscuro.configure(messenger);
_grantRole(ADMIN_ROLE, msg.sender);
_grantRole(NATIVE_TOKEN_ROLE, address(0x0));
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/bridge/L2/EthereumBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";

import "../IBridge.sol";
import "../ITokenFactory.sol";
Expand Down Expand Up @@ -31,7 +32,7 @@ contract EthereumBridge is
function initialize(
address messenger,
address remoteBridge
) public {
) public initializer {
CrossChainEnabledObscuro.configure(messenger);
remoteBridgeAddress = remoteBridge;
}
Expand Down
10 changes: 8 additions & 2 deletions contracts/src/management/ManagementContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";


import "./Structs.sol";
import * as MessageBus from "../messaging/MessageBus.sol";

contract ManagementContract is Ownable {
contract ManagementContract is Ownable, Initializable {

constructor() {
// _disableInitializers(); //todo @siliev - figure out why the solidity compiler cant find this. Perhaps OZ needs a version upgrade?
}

event LogManagementContractCreated(address messageBusAddress);
// Event to log changes to important contract addresses
Expand Down Expand Up @@ -35,7 +41,7 @@ contract ManagementContract is Ownable {
Structs.RollupStorage private rollups;
//The messageBus where messages can be sent to Obscuro
MessageBus.IMessageBus public messageBus;
function initialize() external {
function initialize() public initializer {
lastBatchSeqNo = 0;
messageBus = new MessageBus.MessageBus();
emit LogManagementContractCreated(address(messageBus));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
pragma solidity >=0.7.0 <0.9.0;

import "./ICrossChainMessenger.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";


// TODO: We need to upgrade the open zeppelin version to the 4.x that adds cross chain enabled
abstract contract CrossChainEnabledObscuro {
abstract contract CrossChainEnabledObscuro is Initializable {
ICrossChainMessenger messenger;
IMessageBus messageBus;
uint32 nonce = 0;

// The messenger contract passed will be the authority that we trust to tell us
// who has sent the cross chain message and that the message is indeed cross chain.
function configure(address messengerAddress) public {
function configure(address messengerAddress) public onlyInitializing {
messenger = ICrossChainMessenger(messengerAddress);
messageBus = IMessageBus(messenger.messageBus());
}
Expand Down
6 changes: 4 additions & 2 deletions contracts/src/messaging/messenger/CrossChainMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
pragma solidity >=0.7.0 <0.9.0;

import "./ICrossChainMessenger.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";


// CrossChainMessenger is the contract that provides the context for contracts
// that inherit CrossChainEnabledObscuro. It allows to deliver messages using relayMessage.
Expand All @@ -14,7 +16,7 @@ import "./ICrossChainMessenger.sol";
// from whom the messages are coming from.
// Notice that this Messenger has no restrictions on who can relay messages, nor does it have any understanding of fees.
// You can opt in to deploy a customer messenger for your cross chain dApp with more specialized logic.
contract CrossChainMessenger is ICrossChainMessenger {
contract CrossChainMessenger is ICrossChainMessenger, Initializable {
error CallFailed(bytes error);

IMessageBus messageBusContract;
Expand All @@ -23,7 +25,7 @@ contract CrossChainMessenger is ICrossChainMessenger {


//todo - make only once
function initialize(address messageBusAddr) external {
function initialize(address messageBusAddr) external initializer {
messageBusContract = IMessageBus(messageBusAddr);
crossChainSender = address(0x0);
}
Expand Down
1 change: 1 addition & 0 deletions testnet/launcher/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (t *Testnet) Start() error {
l2cd.WithL2WSPort(81),
l2cd.WithL1PrivateKey("f52e5418e349dccdda29b6ac8b0abe6576bb7713886aa85abea6181ba731f9bb"),
l2cd.WithMessageBusContractAddress("0xDaBD89EEA0f08B602Ec509c3C608Cb8ED095249C"),
l2cd.WithManagementContractAddress("0x51D43a3Ca257584E770B6188232b199E76B022A2"),
l2cd.WithL2PrivateKey("8dfb8083da6275ae3e4f41e3e8a8c19d028d32c9247e24530933782f2a05035b"),
l2cd.WithHocPKString("6e384a07a01263518a09a5424c7b6bbfc3604ba7d93f47e3a455cbdd7f9f0682"),
l2cd.WithPocPKString("4bfe14725e685901c062ccd4e220c61cf9c189897b6c78bd18d7f51291b2b8f8"),
Expand Down

0 comments on commit 490c5bd

Please sign in to comment.