From 3f4e6ff8f598817abbccf6088717c8b0cdf41d1a Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Thu, 24 Sep 2026 17:02:03 +0300 Subject: [PATCH] apply more strict rules for gatekeeper deployment Signed-off-by: Uncle Fatso --- .env.template | 8 +++++--- src/Gatekeeper.sol | 11 ++++------- src/Staking.sol | 2 +- test/gatekeeper/Gatekeeper.t.sol | 2 +- test/gatekeeper/GatekeeperHistory.t.sol | 4 ++-- test/gatekeeper/GatekeeperWeaver.t.sol | 6 +++--- test/staking/Staking.t.sol | 2 +- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.env.template b/.env.template index d136915..4d05383 100644 --- a/.env.template +++ b/.env.template @@ -101,10 +101,12 @@ GOVERNOR_VOTING_PERIOD= GOVERNOR_PROPOSAL_THRESHOLD= GOVERNOR_QUORUM_FRACTION= -###################### Initial ghosted supply on gatekeeper ########################### -## previousWeaver - previous weaver address if any to make linked list of weavers ## -####################################################################################### +############################# Gatekeeper Deployment ################################## +## previousWeaver - previous weaver address if any to make linked list of weavers ## +## previousStaking - previous staking address that will initialize the gatekeeper ## +###################################################################################### PREVIOUS_WEAVER_ADDRESS= +PREVIOUS_STAKING_ADDRESS= SEPOLIA_TEST_RPC_URL= SEPOLIA_TEST_API_KEY= diff --git a/src/Gatekeeper.sol b/src/Gatekeeper.sol index 049a54b..e4e7b29 100644 --- a/src/Gatekeeper.sol +++ b/src/Gatekeeper.sol @@ -39,34 +39,31 @@ contract Gatekeeper is IGatekeeper, Weaver, ReentrancyGuard { Checkpoints.Trace256 private _aggregatedPublicKeys; mapping(bytes32 => uint256) private _packedRotationStates; - constructor(address _storageHistory) { + constructor(address _storageHistory, address _staking) { storageHistory = _storageHistory; - staking = msg.sender; + staking = _staking; deployer = tx.origin; } receive() external payable {} function initialize(address _previousGatekeeperAddress) external override { + require(msg.sender == staking); + if (_previousGatekeeperAddress != address(0)) { require(_initialized == false); require(_previousGatekeeperAddress != address(this)); address previousStorage = IGatekeeper(_previousGatekeeperAddress).storageHistory(); - address previousStaking = IGatekeeper(_previousGatekeeperAddress).staking(); - require(previousStorage != address(0)); - require(previousStaking != address(0)); storageHistory = previousStorage; - staking = previousStaking; deployer = IGatekeeper(_previousGatekeeperAddress).deployer(); Weaver._initialize(_previousGatekeeperAddress); _previousAddress = _previousGatekeeperAddress; } - require(msg.sender == staking); _initialized = true; } diff --git a/src/Staking.sol b/src/Staking.sol index faff22e..bcca90b 100644 --- a/src/Staking.sol +++ b/src/Staking.sol @@ -62,7 +62,7 @@ contract GhostStaking is IStaking, GhostAccessControlled { GhostWarmup newWarmup = new GhostWarmup(_ghst); StorageHistory newHistory = new StorageHistory(); - Gatekeeper newGatekeeper = new Gatekeeper(address(newHistory)); + Gatekeeper newGatekeeper = new Gatekeeper(address(newHistory), address(this)); IStorageHistory(newHistory).setOwner(address(newGatekeeper)); IGatekeeper(newGatekeeper).initialize(address(0)); diff --git a/test/gatekeeper/Gatekeeper.t.sol b/test/gatekeeper/Gatekeeper.t.sol index bf79c6b..179fe1b 100644 --- a/test/gatekeeper/Gatekeeper.t.sol +++ b/test/gatekeeper/Gatekeeper.t.sol @@ -147,7 +147,7 @@ contract MockStaking is Test { constructor() { mockReserve = new WETH9(); StorageHistory history = new StorageHistory(); - gatekeeper = new Gatekeeper(address(history)); + gatekeeper = new Gatekeeper(address(history), address(this)); gatekeeper.initialize(address(0)); history.setOwner(address(gatekeeper)); } diff --git a/test/gatekeeper/GatekeeperHistory.t.sol b/test/gatekeeper/GatekeeperHistory.t.sol index fbc72af..0c1c8a4 100644 --- a/test/gatekeeper/GatekeeperHistory.t.sol +++ b/test/gatekeeper/GatekeeperHistory.t.sol @@ -19,13 +19,13 @@ contract MockStaking is Test { constructor() { mockReserve = new WETH9(); StorageHistory history = new StorageHistory(); - gatekeeper = new Gatekeeper(address(history)); + gatekeeper = new Gatekeeper(address(history), address(this)); gatekeeper.initialize(address(0)); history.setOwner(address(gatekeeper)); } function redoGatekeeper() external { - Gatekeeper newGatekeeper = new Gatekeeper(address(0)); + Gatekeeper newGatekeeper = new Gatekeeper(address(0), address(this)); newGatekeeper.initialize(address(gatekeeper)); address storageHistory = IGatekeeper(gatekeeper).storageHistory(); diff --git a/test/gatekeeper/GatekeeperWeaver.t.sol b/test/gatekeeper/GatekeeperWeaver.t.sol index 84fe864..282d0da 100644 --- a/test/gatekeeper/GatekeeperWeaver.t.sol +++ b/test/gatekeeper/GatekeeperWeaver.t.sol @@ -15,7 +15,7 @@ contract MockStaking { constructor() { StorageHistory history = new StorageHistory(); - gatekeeper = new GatekeeperWeaver(address(history)); + gatekeeper = new GatekeeperWeaver(address(history), address(this)); gatekeeper.initialize(address(0)); history.setOwner(address(gatekeeper)); governor = msg.sender; @@ -29,7 +29,7 @@ contract MockStaking { function createNewGatekeeper() external { require(msg.sender == governor); - GatekeeperWeaver newGatekeeper = new GatekeeperWeaver(address(0)); + GatekeeperWeaver newGatekeeper = new GatekeeperWeaver(address(0), address(this)); newGatekeeper.initialize(address(gatekeeper)); address storageHistory = IGatekeeper(gatekeeper).storageHistory(); @@ -43,7 +43,7 @@ contract GatekeeperWeaver is Gatekeeper { using Checkpoints for Checkpoints.Trace256; using Checkpoints for Checkpoints.Trace160; - constructor(address storageHistory) Gatekeeper(storageHistory) {} + constructor(address storageHistory, address staking) Gatekeeper(storageHistory, staking) {} function filledEntries(uint256 session) public view returns (uint256) { return _filledEntries[session]; diff --git a/test/staking/Staking.t.sol b/test/staking/Staking.t.sol index 43d569b..96eb086 100644 --- a/test/staking/Staking.t.sol +++ b/test/staking/Staking.t.sol @@ -594,7 +594,7 @@ contract StakingTest is Test { vm.prank(address(previousGatekeeper)); IStorageHistory(storageHistory).trySetTransactionExecuted(34); - Gatekeeper newGatekeeper = new Gatekeeper(address(0)); + Gatekeeper newGatekeeper = new Gatekeeper(address(0), address(staking)); vm.prank(GOVERNOR); staking.updateGatekeeperAddress(address(newGatekeeper));