Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added _disableInitializers() in Bridge's constructor #254

Merged
merged 2 commits into from
Nov 7, 2024
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
15 changes: 9 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "apps/blockchain/contracts/ethereum/lib/forge-std"]
path = apps/blockchain/ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "apps/blockchain/contracts/ethereum/lib/openzeppelin-contracts"]
path = apps/blockchain/ethereum/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "apps/blockchain/contracts/ethereum/lib/forge-std"]
path = apps/blockchain/ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "apps/blockchain/contracts/ethereum/lib/openzeppelin-contracts"]
path = apps/blockchain/ethereum/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable"]
path = apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
16 changes: 14 additions & 2 deletions apps/blockchain/ethereum/src/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "./UUPSProxied.sol";
import "starknet/IStarknetMessaging.sol";

import "./IStarklaneEvent.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

error NotSupportedYetError();
error CollectionMappingError();
Expand All @@ -36,7 +37,8 @@ contract Starklane is
StarklaneState,
StarklaneEscrow,
StarklaneMessaging,
CollectionManager
CollectionManager,
Initializable
{
// Mapping (collectionAddress => bool)
mapping(address => bool) _whiteList;
Expand All @@ -47,19 +49,29 @@ contract Starklane is
// Using an arbitrary gas value here for L1-L2 messaging fees, adjustable as network conditions evolve.
// This value serves as a flexible baseline, allowing for real-time adjustments to reflect gas changes.
uint256 _minimumGasFee = 5e13;// 0.00005 ETH
/**
* @notice Starklane contract constructor.
*
* @dev Makes the contract initializable only once
*/

constructor() {
_disableInitializers();
}

/**
* @notice Initializes the implementation, only callable once.
*
* @param data Data to init the implementation.
*/
function initialize(bytes calldata data) public onlyInit {
function initialize(bytes calldata data) public initializer {
(
address owner,
IStarknetMessaging starknetCoreAddress,
uint256 starklaneL2Address,
uint256 starklaneL2Selector
) = abi.decode(data, (address, IStarknetMessaging, uint256, uint256));

_enabled = false;
_starknetCoreAddress = starknetCoreAddress;

Expand Down
19 changes: 19 additions & 0 deletions apps/blockchain/ethereum/test/Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.0;

import "openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

import "forge-std/Test.sol";
import "../src/IStarklane.sol";
Expand Down Expand Up @@ -55,6 +56,24 @@ contract BridgeTest is Test, IStarklaneEvent {
IStarklane(bridge).enableBridge(true);
}

//
function test_initializersDisabled() public {
// Deploy a new instance of Starklane
Starklane newStarklane = new Starklane();

// Try to initialize the contract directly
bytes memory initData = abi.encode(
address(this),
address(0), // Mock Starknet Core address
uint256(0), // Mock Starklane L2 address
uint256(0) // Mock Starklane L2 selector
);

// Expect the initialization to revert
vm.expectRevert(Initializable.InvalidInitialization.selector);
newStarklane.initialize(initData);
}

//
function testFail_invalidIds() public {
uint256[] memory ids = new uint256[](0);
Expand Down
Loading