From 417b27d03d36d3769a8e688db51abd0ef1dfd3e9 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Fri, 11 Oct 2024 13:11:54 +0000 Subject: [PATCH] chore: simplify deployment flow --- l1-contracts/src/governance/Gerousia.sol | 10 ++++++---- l1-contracts/src/governance/Registry.sol | 8 ++++++++ .../src/governance/interfaces/IGerousia.sol | 3 ++- .../src/governance/interfaces/IRegistry.sol | 2 ++ l1-contracts/test/governance/apella/base.t.sol | 12 ++++-------- l1-contracts/test/governance/gerousia/Base.t.sol | 13 ++++++------- .../test/governance/gerousia/constructor.t.sol | 9 +++------ .../test/governance/gerousia/pushProposal.t.sol | 2 ++ l1-contracts/test/governance/gerousia/vote.t.sol | 2 ++ 9 files changed, 35 insertions(+), 26 deletions(-) diff --git a/l1-contracts/src/governance/Gerousia.sol b/l1-contracts/src/governance/Gerousia.sol index d6a12a10160..58bfe80ab6d 100644 --- a/l1-contracts/src/governance/Gerousia.sol +++ b/l1-contracts/src/governance/Gerousia.sol @@ -29,15 +29,13 @@ contract Gerousia is IGerousia { uint256 public constant LIFETIME_IN_ROUNDS = 5; - IApella public immutable APELLA; IRegistry public immutable REGISTRY; uint256 public immutable N; uint256 public immutable M; mapping(address instance => mapping(uint256 roundNumber => RoundAccounting)) public rounds; - constructor(IApella _apella, IRegistry _registry, uint256 _n, uint256 _m) { - APELLA = _apella; + constructor(IRegistry _registry, uint256 _n, uint256 _m) { REGISTRY = _registry; N = _n; M = _m; @@ -120,7 +118,7 @@ contract Gerousia is IGerousia { emit ProposalPushed(round.leader, _roundNumber); - require(APELLA.propose(round.leader), Errors.Gerousia__FailedToPropose(round.leader)); + require(getApella().propose(round.leader), Errors.Gerousia__FailedToPropose(round.leader)); return true; } @@ -152,4 +150,8 @@ contract Gerousia is IGerousia { function computeRound(Slot _slot) public view override(IGerousia) returns (uint256) { return _slot.unwrap() / M; } + + function getApella() public view override(IGerousia) returns (IApella) { + return IApella(REGISTRY.getApella()); + } } diff --git a/l1-contracts/src/governance/Registry.sol b/l1-contracts/src/governance/Registry.sol index bab4b52ee80..8595e664f9c 100644 --- a/l1-contracts/src/governance/Registry.sol +++ b/l1-contracts/src/governance/Registry.sol @@ -84,6 +84,14 @@ contract Registry is IRegistry, Ownable { return currentSnapshot; } + /** + * @notice Returns the address of the apella + * @return The apella address + */ + function getApella() external view override(IRegistry) returns (address) { + return owner(); + } + /** * @notice Creates a new snapshot of the registry * diff --git a/l1-contracts/src/governance/interfaces/IGerousia.sol b/l1-contracts/src/governance/interfaces/IGerousia.sol index d1f8dbffc09..12a5afd600f 100644 --- a/l1-contracts/src/governance/interfaces/IGerousia.sol +++ b/l1-contracts/src/governance/interfaces/IGerousia.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.27; import {Slot} from "@aztec/core/libraries/TimeMath.sol"; - +import {IApella} from "@aztec/governance/interfaces/IApella.sol"; import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; interface IGerousia { @@ -16,4 +16,5 @@ interface IGerousia { view returns (uint256); function computeRound(Slot _slot) external view returns (uint256); + function getApella() external view returns (IApella); } diff --git a/l1-contracts/src/governance/interfaces/IRegistry.sol b/l1-contracts/src/governance/interfaces/IRegistry.sol index 6c9fd5d1a45..844c45bbddc 100644 --- a/l1-contracts/src/governance/interfaces/IRegistry.sol +++ b/l1-contracts/src/governance/interfaces/IRegistry.sol @@ -34,4 +34,6 @@ interface IRegistry { // docs:end:registry_number_of_versions function isRollupRegistered(address _rollup) external view returns (bool); + + function getApella() external view returns (address); } diff --git a/l1-contracts/test/governance/apella/base.t.sol b/l1-contracts/test/governance/apella/base.t.sol index fbb36773508..41f5ed392e5 100644 --- a/l1-contracts/test/governance/apella/base.t.sol +++ b/l1-contracts/test/governance/apella/base.t.sol @@ -37,15 +37,11 @@ contract ApellaBase is TestBase { function setUp() public virtual { token = IMintableERC20(address(new TestERC20())); - // @todo We should be using a bit of create2 magic to do this nicely - apella = new Apella(token, address(0)); - registry = new Registry(address(apella)); - gerousia = new Gerousia(apella, registry, 677, 1000); + registry = new Registry(address(this)); + gerousia = new Gerousia(registry, 677, 1000); - // cheeky breeky - vm.store(address(apella), 0, bytes32(uint256(uint160(address(gerousia))))); - - assertEq(apella.gerousia(), address(gerousia)); + apella = new Apella(token, address(gerousia)); + registry.transferOwnership(address(apella)); { CallAssetPayload payload = new CallAssetPayload(token, address(apella)); diff --git a/l1-contracts/test/governance/gerousia/Base.t.sol b/l1-contracts/test/governance/gerousia/Base.t.sol index 6252ffd7921..8b3db4eb546 100644 --- a/l1-contracts/test/governance/gerousia/Base.t.sol +++ b/l1-contracts/test/governance/gerousia/Base.t.sol @@ -7,15 +7,14 @@ import {Registry} from "@aztec/governance/Registry.sol"; import {Gerousia} from "@aztec/governance/Gerousia.sol"; import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; -import {IApella} from "@aztec/governance/interfaces/IApella.sol"; contract FakeApella { - address public gerousia; + address immutable GEROUSIA; mapping(IPayload => bool) public proposals; - function setGerousia(address _gerousia) external { - gerousia = _gerousia; + constructor(address _gerousia) { + GEROUSIA = _gerousia; } function propose(IPayload _proposal) external returns (bool) { @@ -31,10 +30,10 @@ contract GerousiaBase is Test { function setUp() public virtual { registry = new Registry(address(this)); - apella = new FakeApella(); - gerousia = new Gerousia(IApella(address(apella)), registry, 667, 1000); + gerousia = new Gerousia(registry, 667, 1000); + apella = new FakeApella(address(gerousia)); - apella.setGerousia(address(gerousia)); + registry.transferOwnership(address(apella)); } } diff --git a/l1-contracts/test/governance/gerousia/constructor.t.sol b/l1-contracts/test/governance/gerousia/constructor.t.sol index e3fb6c87b01..47746bde059 100644 --- a/l1-contracts/test/governance/gerousia/constructor.t.sol +++ b/l1-contracts/test/governance/gerousia/constructor.t.sol @@ -5,10 +5,8 @@ import {Test} from "forge-std/Test.sol"; import {Gerousia} from "@aztec/governance/Gerousia.sol"; import {Errors} from "@aztec/governance/libraries/Errors.sol"; import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; -import {IApella} from "@aztec/governance/interfaces/IApella.sol"; contract ConstructorTest is Test { - IApella internal constant APELLA = IApella(address(0x01)); IRegistry internal constant REGISTRY = IRegistry(address(0x02)); function test_WhenNIsLessThanOrEqualHalfOfM(uint256 _n, uint256 _m) external { @@ -17,7 +15,7 @@ contract ConstructorTest is Test { uint256 n = bound(_n, 0, _m / 2); vm.expectRevert(abi.encodeWithSelector(Errors.Gerousia__InvalidNAndMValues.selector, n, _m)); - new Gerousia(APELLA, REGISTRY, n, _m); + new Gerousia(REGISTRY, n, _m); } function test_WhenNLargerThanM(uint256 _n, uint256 _m) external { @@ -26,7 +24,7 @@ contract ConstructorTest is Test { uint256 n = bound(_n, m + 1, type(uint256).max); vm.expectRevert(abi.encodeWithSelector(Errors.Gerousia__NCannotBeLargerTHanM.selector, n, m)); - new Gerousia(APELLA, REGISTRY, n, m); + new Gerousia(REGISTRY, n, m); } function test_WhenNIsGreatherThanHalfOfM(uint256 _n, uint256 _m) external { @@ -35,9 +33,8 @@ contract ConstructorTest is Test { uint256 m = bound(_m, 1, type(uint256).max); uint256 n = bound(_n, m / 2 + 1, m); - Gerousia g = new Gerousia(APELLA, REGISTRY, n, m); + Gerousia g = new Gerousia(REGISTRY, n, m); - assertEq(address(g.APELLA()), address(APELLA)); assertEq(address(g.REGISTRY()), address(REGISTRY)); assertEq(g.N(), n); assertEq(g.M(), m); diff --git a/l1-contracts/test/governance/gerousia/pushProposal.t.sol b/l1-contracts/test/governance/gerousia/pushProposal.t.sol index 42b97d4cd4e..5936b688dc9 100644 --- a/l1-contracts/test/governance/gerousia/pushProposal.t.sol +++ b/l1-contracts/test/governance/gerousia/pushProposal.t.sol @@ -29,6 +29,7 @@ contract PushProposalTest is GerousiaBase { modifier givenCanonicalInstanceHoldCode() { leonidas = new Leonidas(address(this)); + vm.prank(registry.getApella()); registry.upgrade(address(leonidas)); // We jump into the future since slot 0, will behave as if already voted in @@ -196,6 +197,7 @@ contract PushProposalTest is GerousiaBase { // When using a new registry we change the gerousia's interpetation of time :O Leonidas freshInstance = new Leonidas(address(this)); + vm.prank(registry.getApella()); registry.upgrade(address(freshInstance)); // The old is still there, just not executable. diff --git a/l1-contracts/test/governance/gerousia/vote.t.sol b/l1-contracts/test/governance/gerousia/vote.t.sol index 41690685e7a..023d58e734c 100644 --- a/l1-contracts/test/governance/gerousia/vote.t.sol +++ b/l1-contracts/test/governance/gerousia/vote.t.sol @@ -36,6 +36,7 @@ contract VoteTest is GerousiaBase { modifier givenCanonicalRollupHoldCode() { leonidas = new Leonidas(address(this)); + vm.prank(registry.getApella()); registry.upgrade(address(leonidas)); // We jump into the future since slot 0, will behave as if already voted in @@ -129,6 +130,7 @@ contract VoteTest is GerousiaBase { uint256 yeaBefore = gerousia.yeaCount(address(leonidas), leonidasRound, proposal); Leonidas freshInstance = new Leonidas(address(this)); + vm.prank(registry.getApella()); registry.upgrade(address(freshInstance)); vm.warp(Timestamp.unwrap(freshInstance.getTimestampForSlot(Slot.wrap(1))));