|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity >=0.8.27; |
| 3 | + |
| 4 | +import {GovernanceProposerBase} from "../Base.t.sol"; |
| 5 | + |
| 6 | +import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; |
| 7 | +import {Slot, Timestamp} from "@aztec/core/libraries/TimeLib.sol"; |
| 8 | +import {Fakerollup} from "../mocks/Fakerollup.sol"; |
| 9 | +import {IRollup} from "@aztec/core/interfaces/IRollup.sol"; |
| 10 | +import {Signature} from "@aztec/shared/libraries/SignatureLib.sol"; |
| 11 | +import {MessageHashUtils} from "@oz/utils/cryptography/MessageHashUtils.sol"; |
| 12 | +import {TestERC20} from "@aztec/mock/TestERC20.sol"; |
| 13 | +import {Registry} from "@aztec/governance/Registry.sol"; |
| 14 | +import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; |
| 15 | +import {IInstance} from "@aztec/core/interfaces/IInstance.sol"; |
| 16 | +import {GovernanceProposer} from "@aztec/governance/proposer/GovernanceProposer.sol"; |
| 17 | +import {FakeGovernance} from "../Base.t.sol"; |
| 18 | +import {TestBase} from "@test/base/Base.sol"; |
| 19 | +import {GSEPayload} from "@aztec/governance/GSEPayload.sol"; |
| 20 | +import {Governance} from "@aztec/governance/Governance.sol"; |
| 21 | +import {TestConstants} from "../../../harnesses/TestConstants.sol"; |
| 22 | +import {Proposal, ProposalState} from "@aztec/governance/interfaces/IGovernance.sol"; |
| 23 | +import {ProposalLib} from "@aztec/governance/libraries/ProposalLib.sol"; |
| 24 | +import {IGSE} from "@aztec/governance/GSE.sol"; |
| 25 | + |
| 26 | +contract MisconfiguredPayload is IPayload { |
| 27 | + IRegistry public immutable REGISTRY; |
| 28 | + IInstance public immutable ROLLUP; |
| 29 | + |
| 30 | + constructor(IRegistry _registry, IInstance _rollup) { |
| 31 | + REGISTRY = _registry; |
| 32 | + ROLLUP = _rollup; |
| 33 | + } |
| 34 | + |
| 35 | + function getActions() external view override(IPayload) returns (IPayload.Action[] memory) { |
| 36 | + IPayload.Action[] memory res = new IPayload.Action[](1); |
| 37 | + |
| 38 | + res[0] = |
| 39 | + Action({target: address(REGISTRY), data: abi.encodeWithSelector(IRegistry.addRollup.selector, address(ROLLUP))}); |
| 40 | + |
| 41 | + return res; |
| 42 | + } |
| 43 | + |
| 44 | + function getURI() external pure override(IPayload) returns (string memory) { |
| 45 | + return "MisconfiguredPayload"; |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +contract FakeGSE { |
| 50 | + address public latestRollup; |
| 51 | + uint256 public totalSupply; |
| 52 | + address public bonusInstance; |
| 53 | + mapping(address instance => uint256 supply) public supplyOf; |
| 54 | + |
| 55 | + function setLatestRollup(address _latestRollup) external { |
| 56 | + latestRollup = _latestRollup; |
| 57 | + } |
| 58 | + |
| 59 | + function setSupplyOf(address _instance, uint256 _supply) external { |
| 60 | + totalSupply -= supplyOf[_instance]; |
| 61 | + supplyOf[_instance] = _supply; |
| 62 | + totalSupply += _supply; |
| 63 | + } |
| 64 | + |
| 65 | + function setBonusInstanceAddress(address _bonusInstance) external { |
| 66 | + bonusInstance = _bonusInstance; |
| 67 | + } |
| 68 | + |
| 69 | + function getLatestRollup() external view returns (address) { |
| 70 | + return latestRollup; |
| 71 | + } |
| 72 | + |
| 73 | + function getTotalSupply() external view returns (uint256) { |
| 74 | + return totalSupply; |
| 75 | + } |
| 76 | + |
| 77 | + function getBonusInstanceAddress() external view returns (address) { |
| 78 | + return bonusInstance; |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +// https://linear.app/aztec-labs/issue/TMNT-143/spearbit-gov-finding-8-governance-deadlock |
| 83 | +contract TestTmnt143 is TestBase { |
| 84 | + using ProposalLib for Proposal; |
| 85 | + |
| 86 | + TestERC20 public asset; |
| 87 | + Registry public registry; |
| 88 | + FakeGSE public gse; |
| 89 | + GovernanceProposer public governanceProposer; |
| 90 | + Fakerollup public rollup; |
| 91 | + Governance internal governance; |
| 92 | + Proposal internal proposal; |
| 93 | + |
| 94 | + function setUp() external { |
| 95 | + asset = new TestERC20("test", "TEST", address(this)); |
| 96 | + registry = new Registry(address(this), new TestERC20("test", "TEST", address(this))); |
| 97 | + gse = new FakeGSE(); |
| 98 | + |
| 99 | + governanceProposer = new GovernanceProposer(registry, IGSE(address(gse)), 6, 10); |
| 100 | + |
| 101 | + rollup = new Fakerollup(); |
| 102 | + registry.addRollup(rollup); |
| 103 | + |
| 104 | + governance = |
| 105 | + new Governance(asset, address(governanceProposer), address(gse), TestConstants.getGovernanceConfiguration()); |
| 106 | + |
| 107 | + registry.transferOwnership(address(governance)); |
| 108 | + |
| 109 | + vm.warp(Timestamp.unwrap(rollup.getTimestampForSlot(rollup.getCurrentSlot() + Slot.wrap(10)))); |
| 110 | + } |
| 111 | + |
| 112 | + function test_livelock() external { |
| 113 | + // Make a proposal to move to a new GSE, but people leave early so less than 2/3 on the latest in the GSE. |
| 114 | + |
| 115 | + vm.prank(address(governance)); |
| 116 | + governance.openFloodgates(); |
| 117 | + |
| 118 | + vm.prank(asset.owner()); |
| 119 | + asset.mint(address(this), 10_000e18); |
| 120 | + asset.approve(address(governance), 10_000e18); |
| 121 | + governance.deposit(address(this), 10_000e18); |
| 122 | + |
| 123 | + // We setup the gse state where 70% percent is on the current instance (half directly, half from following) |
| 124 | + // The last 30% are then on older rollups. |
| 125 | + gse.setLatestRollup(address(rollup)); |
| 126 | + gse.setSupplyOf(address(rollup), 3500e18); |
| 127 | + address bonusInstance = address(0xbeef); |
| 128 | + gse.setBonusInstanceAddress(bonusInstance); |
| 129 | + gse.setSupplyOf(bonusInstance, 3500e18); |
| 130 | + |
| 131 | + address oldRandomRollup = address(0x1234); |
| 132 | + gse.setSupplyOf(oldRandomRollup, 3000e18); |
| 133 | + |
| 134 | + Fakerollup newRollup = new Fakerollup(); |
| 135 | + |
| 136 | + MisconfiguredPayload payload = new MisconfiguredPayload(registry, IInstance(address(newRollup))); |
| 137 | + |
| 138 | + for (uint256 i = 0; i < 10; i++) { |
| 139 | + address proposer = rollup.getCurrentProposer(); |
| 140 | + vm.prank(proposer); |
| 141 | + governanceProposer.signal(payload); |
| 142 | + vm.warp(Timestamp.unwrap(rollup.getTimestampForSlot(rollup.getCurrentSlot() + Slot.wrap(1)))); |
| 143 | + } |
| 144 | + |
| 145 | + governanceProposer.submitRoundWinner(1); |
| 146 | + proposal = governance.getProposal(0); |
| 147 | + |
| 148 | + // At this point, we expect the new rollup to be gaining traction, so people that follows (on bonus) |
| 149 | + // exit from the GSE, because they want to be on the one with reward. Those on the specific |
| 150 | + // are fine with staying, they like the tech/deployment. |
| 151 | + gse.setSupplyOf(bonusInstance, 0); |
| 152 | + |
| 153 | + vm.warp(Timestamp.unwrap(proposal.pendingThrough()) + 1); |
| 154 | + |
| 155 | + governance.vote(0, 10_000e18, true); |
| 156 | + |
| 157 | + vm.warp(Timestamp.unwrap(proposal.activeThrough()) + 1); |
| 158 | + assertTrue(governance.getProposalState(0) == ProposalState.Queued); |
| 159 | + |
| 160 | + vm.warp(Timestamp.unwrap(proposal.queuedThrough()) + 1); |
| 161 | + assertTrue(governance.getProposalState(0) == ProposalState.Executable); |
| 162 | + assertEq(governance.governanceProposer(), address(governanceProposer)); |
| 163 | + |
| 164 | + // Since the canonical != latest on the GSE. We expect there have been a misstep in the payload |
| 165 | + // e.g., forgot to add a new governance proposer not using the stale GSE. |
| 166 | + |
| 167 | + governance.execute(0); |
| 168 | + |
| 169 | + assertEq(address(registry.getCanonicalRollup()), address(newRollup)); |
| 170 | + } |
| 171 | +} |
0 commit comments