From f95306f4284005de6b85df060c85f602ed10c1a6 Mon Sep 17 00:00:00 2001 From: SoarinSkySagar Date: Mon, 28 Oct 2024 21:01:12 +0530 Subject: [PATCH] did the needed constructor function change and added the corresponding test --- .gitmodules | 15 +++++++++------ .../lib/openzeppelin-contracts-upgradeable | 1 + apps/blockchain/ethereum/src/Bridge.sol | 11 +++++++++-- apps/blockchain/ethereum/test/Bridge.t.sol | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) create mode 160000 apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable diff --git a/.gitmodules b/.gitmodules index 32037572..a1a4ce5d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable b/apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable new file mode 160000 index 00000000..b9cf7c90 --- /dev/null +++ b/apps/blockchain/ethereum/lib/openzeppelin-contracts-upgradeable @@ -0,0 +1 @@ +Subproject commit b9cf7c901ef72b69c8d522d4f435f9dd3097a1e1 diff --git a/apps/blockchain/ethereum/src/Bridge.sol b/apps/blockchain/ethereum/src/Bridge.sol index 078ac40b..68552e14 100644 --- a/apps/blockchain/ethereum/src/Bridge.sol +++ b/apps/blockchain/ethereum/src/Bridge.sol @@ -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(); @@ -36,7 +37,8 @@ contract Starklane is StarklaneState, StarklaneEscrow, StarklaneMessaging, - CollectionManager + CollectionManager, + Initializable { // Mapping (collectionAddress => bool) mapping(address => bool) _whiteList; @@ -48,18 +50,23 @@ contract Starklane is // This value serves as a flexible baseline, allowing for real-time adjustments to reflect gas changes. uint256 _minimumGasFee = 5e13;// 0.00005 ETH + 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; diff --git a/apps/blockchain/ethereum/test/Bridge.t.sol b/apps/blockchain/ethereum/test/Bridge.t.sol index 0c28795e..150cef57 100644 --- a/apps/blockchain/ethereum/test/Bridge.t.sol +++ b/apps/blockchain/ethereum/test/Bridge.t.sol @@ -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"; @@ -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);