From 379cc331e253a4db3370d342f426da0866aa7d31 Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Sun, 2 Aug 2026 22:13:31 +0300 Subject: [PATCH] make metadata historically dependant Signed-off-by: Uncle Fatso --- .env.template | 8 -------- src/Gatekeeper.sol | 23 +++++++++++----------- src/interfaces/IGatekeeper.sol | 1 + src/types/Metadata.sol | 25 ++++++++++++++---------- test/bonding/BondDepositorty.t.sol | 4 ++-- test/gatekeeper/Gatekeeper.t.sol | 11 +++++++---- test/gatekeeper/GatekeeperMetadata.t.sol | 13 +++++------- test/gatekeeper/GatekeeperWeaver.t.sol | 17 ++++------------ test/staking/Staking.t.sol | 2 +- 9 files changed, 47 insertions(+), 57 deletions(-) diff --git a/.env.template b/.env.template index 96e6968..799d8f0 100644 --- a/.env.template +++ b/.env.template @@ -105,18 +105,10 @@ GOVERNOR_PROPOSAL_THRESHOLD= GOVERNOR_QUORUM_FRACTION= ###################### Initial ghosted supply on gatekeeper ########################### -## ghostedSupply - supply that is currently locked inside the gatekeeper ## ## existential - minimum amount that could be reflected inside other chain ## -## ghostedIn - historical supply that was bridged in (max value is 2^104) ## -## ghostedOut - historical supply that was bridged out (max value is 2^104) ## -## deployedAt - time when gatekeepers was deployed, could be inherited if needed ## ## previousWeaver - previous weaver address if any to make linked list of weavers ## ####################################################################################### -INITIAL_GHOSTED_SUPPLY= INITIAL_EXISTENTIAL_DEPOSIT= -INITIAL_GHOSTED_IN= -INITIAL_GHOSTED_OUT= -GATEKEEPER_DEPLOYED_AT= PREVIOUS_WEAVER_ADDRESS= SEPOLIA_TEST_RPC_URL= diff --git a/src/Gatekeeper.sol b/src/Gatekeeper.sol index 9bf00ab..a0f3cb5 100644 --- a/src/Gatekeeper.sol +++ b/src/Gatekeeper.sol @@ -10,23 +10,24 @@ contract Gatekeeper is IGatekeeper, Metadata, Weaver { uint256 public override existentialDeposit; uint256 public override ghostedSupply; - address public immutable staking; // forge-lint: disable-line(screaming-snake-case-immutable) + address public override staking; uint256 private _aggregatedPublicKey; mapping(uint256 => mapping(uint256 => bool)) private _executedTransaction; constructor( address _staking, - uint256 _ghostedSupply, - uint256 _existential, - address _previousWeaver, - uint48 _deployedAt, - uint104 _amountIn, - uint104 _amountOut - ) Metadata(_deployedAt, _amountIn, _amountOut) Weaver(_previousWeaver) { - existentialDeposit = _existential; - ghostedSupply = _ghostedSupply; - staking = _staking; + uint256 _existentialDeposit, + address _previousGatekeeper + ) Metadata(_previousGatekeeper) Weaver(_previousGatekeeper) { + existentialDeposit = _existentialDeposit; + if (_previousGatekeeper != address(0)) { + IGatekeeper previousGatekeeper = IGatekeeper(_previousGatekeeper); + ghostedSupply = previousGatekeeper.ghostedSupply(); + staking = previousGatekeeper.staking(); + } else { + staking = _staking; + } } function ghost(bytes32 receiver, uint256 amount) external override returns (uint256) { diff --git a/src/interfaces/IGatekeeper.sol b/src/interfaces/IGatekeeper.sol index 65849ef..ae98ddd 100644 --- a/src/interfaces/IGatekeeper.sol +++ b/src/interfaces/IGatekeeper.sol @@ -13,6 +13,7 @@ interface IGatekeeper { function ghostedSupply() external view returns (uint256); function existentialDeposit() external view returns (uint256); + function staking() external view returns (address); function ghost(bytes32 receiver, uint256 amount) external returns (uint256); function materialize(address receiver, uint256 amount, uint256 rx, uint256 s) external; function rotate(uint256 aggregatedPublicKey, uint256 rx, uint256 s) external; diff --git a/src/types/Metadata.sol b/src/types/Metadata.sol index 6c51de7..a8e8769 100644 --- a/src/types/Metadata.sol +++ b/src/types/Metadata.sol @@ -6,16 +6,21 @@ import {IMetadata} from "../interfaces/IMetadata.sol"; abstract contract Metadata is IMetadata { GatekeeperMetadata internal _metadata; - constructor( - uint48 _deployedAt, - uint104 _amountIn, - uint104 _amountOut - ) { - _metadata = GatekeeperMetadata({ - deployedAt: _deployedAt, - amountIn: _amountIn, - amountOut: _amountOut - }); + constructor(address previosMetadata) { + if (previosMetadata == address(0)) { + _metadata = GatekeeperMetadata({ + deployedAt: uint48(block.number), + amountIn: 0, + amountOut: 0 + }); + } else { + IMetadata.GatekeeperMetadata memory previousMetadata = IMetadata(previosMetadata).metadata(); + _metadata = GatekeeperMetadata({ + deployedAt: previousMetadata.deployedAt, + amountIn: previousMetadata.amountIn, + amountOut: previousMetadata.amountOut + }); + } } function metadata() external view returns (GatekeeperMetadata memory) { diff --git a/test/bonding/BondDepositorty.t.sol b/test/bonding/BondDepositorty.t.sol index b38085d..cccc9f8 100644 --- a/test/bonding/BondDepositorty.t.sol +++ b/test/bonding/BondDepositorty.t.sol @@ -324,7 +324,7 @@ contract GhostBondDepositoryTest is Test { uint256 amount = 10_000 * 1e18; // 10,000 vm.startPrank(GOVERNOR); - Gatekeeper gatekeeper = new Gatekeeper(address(staking), 0, 0, address(0), 0, 0, 0); + Gatekeeper gatekeeper = new Gatekeeper(address(staking), 0, address(0)); staking.setGatekeeperAddress(address(gatekeeper)); staking.setWarmupPeriod(1); vm.stopPrank(); @@ -509,7 +509,7 @@ contract GhostBondDepositoryTest is Test { } vm.startPrank(GOVERNOR); - Gatekeeper gatekeeper = new Gatekeeper(address(staking), 0, 0, address(0), 0, 0, 0); + Gatekeeper gatekeeper = new Gatekeeper(address(staking), 0, address(0)); staking.setGatekeeperAddress(address(gatekeeper)); staking.setWarmupPeriod(10); vm.stopPrank(); diff --git a/test/gatekeeper/Gatekeeper.t.sol b/test/gatekeeper/Gatekeeper.t.sol index 9c561d6..414e96c 100644 --- a/test/gatekeeper/Gatekeeper.t.sol +++ b/test/gatekeeper/Gatekeeper.t.sol @@ -14,18 +14,21 @@ contract GatekeeperTest is Test { event Ghosted(bytes32 indexed receiver, uint256 indexed amount); function setUp() public { - gatekeeper = new Gatekeeper(ALICE, 0, EXISTENTIAL, address(0), 0, 0, 0); + gatekeeper = new Gatekeeper(ALICE, EXISTENTIAL, address(0)); } function test_correctInitialization() public { assertEq(gatekeeper.staking(), ALICE); assertEq(gatekeeper.ghostedSupply(), 0); - Gatekeeper anotherGatekeeper = new Gatekeeper(BOB, INIT_AMOUNT, EXISTENTIAL, address(0), 0, 0, 0); - assertEq(anotherGatekeeper.staking(), BOB); + bytes32 receiver = bytes32(abi.encodePacked(ALICE)); + vm.prank(ALICE); + gatekeeper.ghost(receiver, INIT_AMOUNT); + + Gatekeeper anotherGatekeeper = new Gatekeeper(BOB, EXISTENTIAL, address(gatekeeper)); + assertEq(anotherGatekeeper.staking(), ALICE); assertEq(anotherGatekeeper.ghostedSupply(), INIT_AMOUNT); assertEq(anotherGatekeeper.existentialDeposit(), EXISTENTIAL); - assertEq(anotherGatekeeper.ghostedSupply(), INIT_AMOUNT); } function test_ghostTokensWork(uint256 ghostAmount) public { diff --git a/test/gatekeeper/GatekeeperMetadata.t.sol b/test/gatekeeper/GatekeeperMetadata.t.sol index de69c18..2f7b9dd 100644 --- a/test/gatekeeper/GatekeeperMetadata.t.sol +++ b/test/gatekeeper/GatekeeperMetadata.t.sol @@ -9,22 +9,19 @@ contract GatekeeperMetadataTest is Test { uint256 constant INIT_AMOUNT = 69 * 1e18; uint256 constant INIT_GHOSTED = type(uint104).max / 2; uint256 constant EXISTENTIAL = 0; - uint48 constant DEPLOYED_AT = 1337; - uint104 constant AMOUNT_IN = 69; - uint104 constant AMOUNT_OUT = 420; Gatekeeper gatekeeper; function setUp() public { - gatekeeper = new Gatekeeper(ALICE, INIT_GHOSTED, EXISTENTIAL, address(0), DEPLOYED_AT, AMOUNT_IN, AMOUNT_OUT); + gatekeeper = new Gatekeeper(ALICE, EXISTENTIAL, address(0)); } function test_correctMetadataInitialization() public view { Gatekeeper.GatekeeperMetadata memory metadata = gatekeeper.metadata(); - assertEq(metadata.deployedAt, DEPLOYED_AT); - assertEq(metadata.amountIn, AMOUNT_IN); - assertEq(metadata.amountOut, AMOUNT_OUT); - assertEq(gatekeeper.ghostedSupply(), INIT_GHOSTED); + assertEq(metadata.deployedAt, block.number); + assertEq(metadata.amountIn, 0); + assertEq(metadata.amountOut, 0); + assertEq(gatekeeper.ghostedSupply(), 0); } function test_historicalAmountsOnlyIncrease(uint256 ghostAmount) public { diff --git a/test/gatekeeper/GatekeeperWeaver.t.sol b/test/gatekeeper/GatekeeperWeaver.t.sol index 0fd5943..5fbe927 100644 --- a/test/gatekeeper/GatekeeperWeaver.t.sol +++ b/test/gatekeeper/GatekeeperWeaver.t.sol @@ -12,20 +12,12 @@ contract GatekeeperVerification is Gatekeeper { constructor( address staking, - uint256 ghostedSupply, uint256 existential, - address previousWeaver, - uint48 deployedAt, - uint104 amountIn, - uint104 amountOut + address previousWeaver ) Gatekeeper( staking, - ghostedSupply, existential, - previousWeaver, - deployedAt, - amountIn, - amountOut + previousWeaver ) {} function filledEntries(uint256 session) public view returns (uint256) { @@ -104,7 +96,7 @@ contract GatekeeperWeaverTest is Test { GatekeeperVerification gatekeeper; function setUp() public { - gatekeeper = new GatekeeperVerification(ALICE, 0, EXISTENTIAL, address(0), 0, 0, 0); + gatekeeper = new GatekeeperVerification(ALICE, EXISTENTIAL, address(0)); } function test_insertationWorksAsExpected() public { @@ -142,7 +134,7 @@ contract GatekeeperWeaverTest is Test { assertFalse(_verifyProof(2047, currentSession, 100, amounts[2047], whos[2047])); vm.roll(block.number + 420); - gatekeeper = new GatekeeperVerification(ALICE, 0, EXISTENTIAL, address(gatekeeper), 0, 0, 0); + gatekeeper = new GatekeeperVerification(ALICE, EXISTENTIAL, address(gatekeeper)); uint256 finalSession = gatekeeper.currentSession(); for (uint256 i = 0; i < 69; i++) { @@ -166,7 +158,6 @@ contract GatekeeperWeaverTest is Test { assertFalse(_verifyProof(1337, currentSession, 100, amounts[1337], whos[1337])); assertFalse(_verifyProof(2047, currentSession, 100, amounts[2047], whos[2047])); - // TODO: this fails for some reason assertTrue(_verifyProof(0, finalSession, block.number, amounts[0], whos[0])); assertTrue(_verifyProof(34, finalSession, block.number, amounts[34], whos[34])); assertTrue(_verifyProof(35, finalSession, block.number, amounts[35], whos[35])); diff --git a/test/staking/Staking.t.sol b/test/staking/Staking.t.sol index 6c77139..37dd1f8 100644 --- a/test/staking/Staking.t.sol +++ b/test/staking/Staking.t.sol @@ -110,7 +110,7 @@ contract StakingTest is Test { treasury = new GhostTreasury(address(ftso), 69, address(authority)); stnk.initialize(address(staking), address(treasury), address(ghst)); ghst.initialize(address(staking)); - gatekeeper = new Gatekeeper(address(staking), 0, 0, address(0), 0, 0, 0); + gatekeeper = new Gatekeeper(address(staking), 0, address(0)); calculator = new GhostBondingCalculator(address(ftso), 1, 1); vm.stopPrank(); vm.roll(block.number + 1);