Skip to content

Commit

Permalink
chore: move governance out of core
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 26, 2024
1 parent bccfe26 commit 52bfd34
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 65 deletions.
5 changes: 3 additions & 2 deletions l1-contracts/src/core/FeeJuicePortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ pragma solidity >=0.8.18;
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {IFeeJuicePortal} from "@aztec/core/interfaces/IFeeJuicePortal.sol";
import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {IRegistry} from "@aztec/core/interfaces/messagebridge/IRegistry.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {IRollup} from "@aztec/core/interfaces/IRollup.sol";

import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
Expand Down Expand Up @@ -74,7 +75,7 @@ contract FeeJuicePortal is IFeeJuicePortal, Ownable {
returns (bytes32)
{
// Preamble
IInbox inbox = registry.getRollup().INBOX();
IInbox inbox = IRollup(registry.getRollup()).INBOX();
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1);

// Hash the message content to be reconstructed in the receiving contract
Expand Down
4 changes: 0 additions & 4 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {IProofCommitmentEscrow} from "@aztec/core/interfaces/IProofCommitmentEsc
import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";
import {IFeeJuicePortal} from "@aztec/core/interfaces/IFeeJuicePortal.sol";
import {IRegistry} from "@aztec/core/interfaces/messagebridge/IRegistry.sol";
import {IRollup, ITestRollup} from "@aztec/core/interfaces/IRollup.sol";
import {IVerifier} from "@aztec/core/interfaces/IVerifier.sol";

Expand Down Expand Up @@ -51,7 +50,6 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
uint256 public constant PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST = 1000;

uint256 public immutable L1_BLOCK_AT_GENESIS;
IRegistry public immutable REGISTRY;
IInbox public immutable INBOX;
IOutbox public immutable OUTBOX;
IProofCommitmentEscrow public immutable PROOF_COMMITMENT_ESCROW;
Expand All @@ -76,14 +74,12 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
uint256 private assumeProvenThroughBlockNumber;

constructor(
IRegistry _registry,
IFeeJuicePortal _fpcJuicePortal,
bytes32 _vkTreeRoot,
address _ares,
address[] memory _validators
) Leonidas(_ares) {
verifier = new MockVerifier();
REGISTRY = _registry;
FEE_JUICE_PORTAL = _fpcJuicePortal;
PROOF_COMMITMENT_ESCROW = new MockProofCommitmentEscrow();
INBOX = IInbox(address(new Inbox(address(this), Constants.L1_TO_L2_MSG_SUBTREE_HEIGHT)));
Expand Down
12 changes: 0 additions & 12 deletions l1-contracts/src/core/libraries/DataStructures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ library DataStructures {
}
// docs:end:l2_to_l1_msg

// docs:start:registry_snapshot
/**
* @notice Struct for storing address of cross communication components and the block number when it was updated
* @param rollup - The address of the rollup contract
* @param blockNumber - The block number of the snapshot
*/
struct RegistrySnapshot {
address rollup;
uint256 blockNumber;
}
// docs:end:registry_snapshot

/**
* @notice Struct for storing flags for block header validation
* @param ignoreDA - True will ignore DA check, otherwise checks
Expand Down
4 changes: 0 additions & 4 deletions l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ library Errors {
error Rollup__TryingToProveNonExistingBlock(); // 0x34ef4954
error Rollup__UnavailableTxs(bytes32 txsHash); // 0x414906c3

// Registry
error Registry__RollupNotRegistered(address rollup); // 0xa1fee4cf
error Registry__RollupAlreadyRegistered(address rollup); // 0x3c34eabf

//TxsDecoder
error TxsDecoder__InvalidLogsLength(uint256 expected, uint256 actual); // 0x829ca981
error TxsDecoder__TxsTooLarge(uint256 expected, uint256 actual); // 0xc7d44a62
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// Copyright 2023 Aztec Labs.
pragma solidity >=0.8.18;

import {IRegistry} from "@aztec/core/interfaces/messagebridge/IRegistry.sol";
import {IRollup} from "@aztec/core/interfaces/IRollup.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";

import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol";
import {Errors} from "@aztec/governance/libraries/Errors.sol";

import {Ownable} from "@oz/access/Ownable.sol";

Expand All @@ -32,8 +31,8 @@ contract Registry is IRegistry, Ownable {
* @notice Returns the rollup contract
* @return The rollup contract (of type IRollup)
*/
function getRollup() external view override(IRegistry) returns (IRollup) {
return IRollup(currentSnapshot.rollup);
function getRollup() external view override(IRegistry) returns (address) {
return currentSnapshot.rollup;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.18;

import {DataStructures} from "../../libraries/DataStructures.sol";
import {IRollup} from "../IRollup.sol";
import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol";

interface IRegistry {
// docs:start:registry_upgrade
function upgrade(address _rollup) external returns (uint256);
// docs:end:registry_upgrade

// docs:start:registry_get_rollup
function getRollup() external view returns (IRollup);
function getRollup() external view returns (address);
// docs:end:registry_get_rollup

// docs:start:registry_get_version_for
Expand Down
22 changes: 22 additions & 0 deletions l1-contracts/src/governance/libraries/DataStructures.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Aztec Labs.
pragma solidity >=0.8.18;

/**
* @title Data Structures Library
* @author Aztec Labs
* @notice Library that contains data structures used throughout the Aztec protocol
*/
library DataStructures {
// docs:start:registry_snapshot
/**
* @notice Struct for storing address of cross communication components and the block number when it was updated
* @param rollup - The address of the rollup contract
* @param blockNumber - The block number of the snapshot
*/
struct RegistrySnapshot {
address rollup;
uint256 blockNumber;
}
// docs:end:registry_snapshot
}
16 changes: 16 additions & 0 deletions l1-contracts/src/governance/libraries/Errors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Aztec Labs.
pragma solidity >=0.8.18;

/**
* @title Errors Library
* @author Aztec Labs
* @notice Library that contains errors used throughout the Aztec governance
* Errors are prefixed with the contract name to make it easy to identify where the error originated
* when there are multiple contracts that could have thrown the error.
*/
library Errors {
// Registry
error Registry__RollupNotRegistered(address rollup); // 0xa1fee4cf
error Registry__RollupAlreadyRegistered(address rollup); // 0x3c34eabf
}
11 changes: 2 additions & 9 deletions l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol";

import {Registry} from "@aztec/core/messagebridge/Registry.sol";
import {Registry} from "@aztec/governance/Registry.sol";
import {Inbox} from "@aztec/core/messagebridge/Inbox.sol";
import {Outbox} from "@aztec/core/messagebridge/Outbox.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Rollup} from "@aztec/core/Rollup.sol";
import {IFeeJuicePortal} from "@aztec/core/interfaces/IFeeJuicePortal.sol";
import {IRollup} from "@aztec/core/interfaces/IRollup.sol";
import {FeeJuicePortal} from "@aztec/core/FeeJuicePortal.sol";
import {Leonidas} from "@aztec/core/Leonidas.sol";
Expand Down Expand Up @@ -64,13 +63,7 @@ contract RollupTest is DecoderBase {
feeJuicePortal.initialize(
address(registry), address(portalERC20), bytes32(Constants.FEE_JUICE_ADDRESS)
);
rollup = new Rollup(
registry,
IFeeJuicePortal(address(feeJuicePortal)),
bytes32(0),
address(this),
new address[](0)
);
rollup = new Rollup(feeJuicePortal, bytes32(0), address(this), new address[](0));
inbox = Inbox(address(rollup.INBOX()));
outbox = Outbox(address(rollup.OUTBOX()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity >=0.8.18;

import {Test} from "forge-std/Test.sol";
import {Ownable} from "@oz/access/Ownable.sol";
import {Registry} from "@aztec/core/messagebridge/Registry.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Registry} from "@aztec/governance/Registry.sol";
import {Errors} from "@aztec/governance/libraries/Errors.sol";
import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol";

contract RegistryTest is Test {
address internal constant DEAD = address(0xdead);
Expand Down
9 changes: 5 additions & 4 deletions l1-contracts/test/portals/TokenPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";

// Messaging
import {IRegistry} from "@aztec/core/interfaces/messagebridge/IRegistry.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";
import {IRollup} from "@aztec/core/interfaces/IRollup.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
// docs:start:content_hash_sol_import
import {Hash} from "@aztec/core/libraries/crypto/Hash.sol";
Expand Down Expand Up @@ -40,7 +41,7 @@ contract TokenPortal {
returns (bytes32)
{
// Preamble
IInbox inbox = registry.getRollup().INBOX();
IInbox inbox = IRollup(registry.getRollup()).INBOX();
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1);

// Hash the message content to be reconstructed in the receiving contract
Expand Down Expand Up @@ -69,7 +70,7 @@ contract TokenPortal {
bytes32 _secretHashForL2MessageConsumption
) external returns (bytes32) {
// Preamble
IInbox inbox = registry.getRollup().INBOX();
IInbox inbox = IRollup(registry.getRollup()).INBOX();
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1);

// Hash the message content to be reconstructed in the receiving contract
Expand Down Expand Up @@ -120,7 +121,7 @@ contract TokenPortal {
)
});

IOutbox outbox = registry.getRollup().OUTBOX();
IOutbox outbox = IRollup(registry.getRollup()).OUTBOX();

outbox.consume(message, _l2BlockNumber, _leafIndex, _path);

Expand Down
5 changes: 2 additions & 3 deletions l1-contracts/test/portals/TokenPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";
// Rollup Processor
import {Rollup} from "@aztec/core/Rollup.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {Registry} from "@aztec/core/messagebridge/Registry.sol";
import {Registry} from "@aztec/governance/Registry.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Hash} from "@aztec/core/libraries/crypto/Hash.sol";
Expand Down Expand Up @@ -60,8 +60,7 @@ contract TokenPortalTest is Test {
function setUp() public {
registry = new Registry(address(this));
portalERC20 = new PortalERC20();
rollup =
new Rollup(registry, IFeeJuicePortal(address(0)), bytes32(0), address(this), new address[](0));
rollup = new Rollup(IFeeJuicePortal(address(0)), bytes32(0), address(this), new address[](0));
inbox = rollup.INBOX();
outbox = rollup.OUTBOX();

Expand Down
7 changes: 4 additions & 3 deletions l1-contracts/test/portals/UniswapPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ pragma solidity >=0.8.18;

import {IERC20} from "@oz/token/ERC20/IERC20.sol";

import {IRegistry} from "@aztec/core/interfaces/messagebridge/IRegistry.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";
import {IRollup} from "@aztec/core/interfaces/IRollup.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {DataStructures as PortalDataStructures} from "./DataStructures.sol";
import {Hash} from "@aztec/core/libraries/crypto/Hash.sol";
Expand Down Expand Up @@ -103,7 +104,7 @@ contract UniswapPortal {

// Consume the message from the outbox
{
IOutbox outbox = registry.getRollup().OUTBOX();
IOutbox outbox = IRollup(registry.getRollup()).OUTBOX();

outbox.consume(
DataStructures.L2ToL1Msg({
Expand Down Expand Up @@ -209,7 +210,7 @@ contract UniswapPortal {

// Consume the message from the outbox
{
IOutbox outbox = registry.getRollup().OUTBOX();
IOutbox outbox = IRollup(registry.getRollup()).OUTBOX();

outbox.consume(
DataStructures.L2ToL1Msg({
Expand Down
5 changes: 2 additions & 3 deletions l1-contracts/test/portals/UniswapPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "forge-std/Test.sol";

// Rollup Processor
import {Rollup} from "@aztec/core/Rollup.sol";
import {Registry} from "@aztec/core/messagebridge/Registry.sol";
import {Registry} from "@aztec/governance/Registry.sol";
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {DataStructures as PortalDataStructures} from "./DataStructures.sol";
import {Hash} from "@aztec/core/libraries/crypto/Hash.sol";
Expand Down Expand Up @@ -52,8 +52,7 @@ contract UniswapPortalTest is Test {
vm.selectFork(forkId);

registry = new Registry(address(this));
rollup =
new Rollup(registry, IFeeJuicePortal(address(0)), bytes32(0), address(this), new address[](0));
rollup = new Rollup(IFeeJuicePortal(address(0)), bytes32(0), address(this), new address[](0));
registry.upgrade(address(rollup));

daiTokenPortal = new TokenPortal();
Expand Down
9 changes: 1 addition & 8 deletions l1-contracts/test/sparta/Sparta.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {SignatureLib} from "@aztec/core/libraries/crypto/SignatureLib.sol";

import {Registry} from "@aztec/core/messagebridge/Registry.sol";
import {Inbox} from "@aztec/core/messagebridge/Inbox.sol";
import {Outbox} from "@aztec/core/messagebridge/Outbox.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
Expand Down Expand Up @@ -36,7 +35,6 @@ contract SpartaTest is DecoderBase {
bool shouldRevert;
}

Registry internal registry;
Inbox internal inbox;
Outbox internal outbox;
Rollup internal rollup;
Expand Down Expand Up @@ -71,16 +69,11 @@ contract SpartaTest is DecoderBase {
initialValidators[i - 1] = validator;
}

registry = new Registry(address(this));
portalERC20 = new PortalERC20();
rollup = new Rollup(
registry, IFeeJuicePortal(address(0)), bytes32(0), address(this), initialValidators
);
rollup = new Rollup(IFeeJuicePortal(address(0)), bytes32(0), address(this), initialValidators);
inbox = Inbox(address(rollup.INBOX()));
outbox = Outbox(address(rollup.OUTBOX()));

registry.upgrade(address(rollup));

merkleTestUtil = new MerkleTestUtil();
txsHelper = new TxsDecoderHelper();

Expand Down
1 change: 0 additions & 1 deletion yarn-project/ethereum/src/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export const deployL1Contracts = async (
logger.info(`Deployed Gas Portal at ${feeJuicePortalAddress}`);

const rollupAddress = await deployer.deploy(contractsToDeploy.rollup, [
getAddress(registryAddress.toString()),
getAddress(feeJuicePortalAddress.toString()),
args.vkTreeRoot.toString(),
account.address.toString(),
Expand Down

0 comments on commit 52bfd34

Please sign in to comment.