-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fetch addresses from registry #12000
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
l1-contracts/test/governance/scenario/RegisterNewRollupVersionPayload.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.27; | ||
|
||
import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; | ||
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; | ||
|
||
/** | ||
* @title RegisterNewRollupVersionPayload | ||
* @author Aztec Labs | ||
* @notice A payload that registers a new rollup version. | ||
*/ | ||
contract RegisterNewRollupVersionPayload is IPayload { | ||
IRegistry public immutable REGISTRY; | ||
address public immutable ROLLUP; | ||
|
||
constructor(IRegistry _registry, address _rollup) { | ||
REGISTRY = _registry; | ||
ROLLUP = _rollup; | ||
} | ||
|
||
function getActions() external view override(IPayload) returns (IPayload.Action[] memory) { | ||
IPayload.Action[] memory res = new IPayload.Action[](1); | ||
|
||
res[0] = Action({ | ||
target: address(REGISTRY), | ||
data: abi.encodeWithSelector(IRegistry.upgrade.selector, ROLLUP) | ||
}); | ||
|
||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
import { Fr } from '@aztec/foundation/fields'; | ||
import { type Logger, createLogger } from '@aztec/foundation/log'; | ||
import { TestERC20Abi as FeeJuiceAbi, GovernanceAbi } from '@aztec/l1-artifacts'; | ||
|
||
import type { Anvil } from '@viem/anvil'; | ||
import omit from 'lodash.omit'; | ||
import { getContract } from 'viem'; | ||
import { type PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts'; | ||
import { foundry } from 'viem/chains'; | ||
|
||
import { DefaultL1ContractsConfig } from '../config.js'; | ||
import { createL1Clients, deployL1Contracts, deployRollupAndPeriphery } from '../deploy_l1_contracts.js'; | ||
import { EthCheatCodes } from '../eth_cheat_codes.js'; | ||
import type { L1ContractAddresses } from '../l1_contract_addresses.js'; | ||
import { defaultL1TxUtilsConfig } from '../l1_tx_utils.js'; | ||
import { startAnvil } from '../test/start_anvil.js'; | ||
import type { L1Clients } from '../types.js'; | ||
import { RegistryContract } from './registry.js'; | ||
|
||
const originalVersionSalt = 42; | ||
|
||
describe('Registry', () => { | ||
let anvil: Anvil; | ||
let rpcUrl: string; | ||
let privateKey: PrivateKeyAccount; | ||
let logger: Logger; | ||
|
||
let vkTreeRoot: Fr; | ||
let protocolContractTreeRoot: Fr; | ||
let l2FeeJuiceAddress: Fr; | ||
let publicClient: L1Clients['publicClient']; | ||
let walletClient: L1Clients['walletClient']; | ||
let registry: RegistryContract; | ||
let deployedAddresses: L1ContractAddresses; | ||
|
||
beforeAll(async () => { | ||
logger = createLogger('ethereum:test:registry'); | ||
// this is the 6th address that gets funded by the junk mnemonic | ||
privateKey = privateKeyToAccount('0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba'); | ||
vkTreeRoot = Fr.random(); | ||
protocolContractTreeRoot = Fr.random(); | ||
l2FeeJuiceAddress = Fr.random(); | ||
|
||
({ anvil, rpcUrl } = await startAnvil()); | ||
|
||
({ publicClient, walletClient } = createL1Clients(rpcUrl, privateKey)); | ||
|
||
const deployed = await deployL1Contracts(rpcUrl, privateKey, foundry, logger, { | ||
...DefaultL1ContractsConfig, | ||
salt: originalVersionSalt, | ||
vkTreeRoot, | ||
protocolContractTreeRoot, | ||
l2FeeJuiceAddress, | ||
genesisArchiveRoot: Fr.random(), | ||
genesisBlockHash: Fr.random(), | ||
}); | ||
// Since the registry cannot "see" the slash factory, we omit it from the addresses for this test | ||
deployedAddresses = omit(deployed.l1ContractAddresses, 'slashFactoryAddress'); | ||
registry = new RegistryContract(publicClient, deployedAddresses.registryAddress); | ||
}); | ||
|
||
afterAll(async () => { | ||
await anvil.stop(); | ||
}); | ||
|
||
it('gets rollup versions', async () => { | ||
const rollupAddress = deployedAddresses.rollupAddress; | ||
{ | ||
const address = await registry.getCanonicalAddress(); | ||
expect(address).toEqual(rollupAddress); | ||
} | ||
{ | ||
const address = await registry.getRollupAddress('canonical'); | ||
expect(address).toEqual(rollupAddress); | ||
} | ||
{ | ||
const address = await registry.getRollupAddress(1); | ||
expect(address).toEqual(rollupAddress); | ||
} | ||
}); | ||
|
||
it('handles non-existent versions', async () => { | ||
const address = await registry.getRollupAddress(2); | ||
expect(address).toBeUndefined(); | ||
}); | ||
|
||
it('collects addresses', async () => { | ||
await expect( | ||
RegistryContract.collectAddresses(publicClient, deployedAddresses.registryAddress, 'canonical'), | ||
).resolves.toEqual(deployedAddresses); | ||
|
||
await expect( | ||
RegistryContract.collectAddresses(publicClient, deployedAddresses.registryAddress, 1), | ||
).resolves.toEqual(deployedAddresses); | ||
|
||
// Version 2 does not exist | ||
|
||
await expect(RegistryContract.collectAddresses(publicClient, deployedAddresses.registryAddress, 2)).rejects.toThrow( | ||
'Rollup address is undefined', | ||
); | ||
}); | ||
|
||
it('adds a version to the registry', async () => { | ||
const addresses = await RegistryContract.collectAddresses( | ||
publicClient, | ||
deployedAddresses.registryAddress, | ||
'canonical', | ||
); | ||
const newVersionSalt = originalVersionSalt + 1; | ||
|
||
const { rollup: newRollup, payloadAddress } = await deployRollupAndPeriphery( | ||
rpcUrl, | ||
foundry, | ||
privateKey, | ||
{ | ||
...DefaultL1ContractsConfig, | ||
salt: newVersionSalt, | ||
vkTreeRoot, | ||
protocolContractTreeRoot, | ||
l2FeeJuiceAddress, | ||
genesisArchiveRoot: Fr.random(), | ||
genesisBlockHash: Fr.random(), | ||
}, | ||
{ | ||
feeJuicePortalAddress: addresses.feeJuicePortalAddress, | ||
rewardDistributorAddress: addresses.rewardDistributorAddress, | ||
stakingAssetAddress: addresses.stakingAssetAddress, | ||
registryAddress: deployedAddresses.registryAddress, | ||
}, | ||
logger, | ||
defaultL1TxUtilsConfig, | ||
); | ||
|
||
const { governance, voteAmount } = await createGovernanceProposal( | ||
payloadAddress.toString(), | ||
addresses, | ||
privateKey, | ||
publicClient, | ||
logger, | ||
); | ||
|
||
await executeGovernanceProposal(0n, governance, voteAmount, privateKey, publicClient, walletClient, rpcUrl, logger); | ||
|
||
const newAddresses = await newRollup.getRollupAddresses(); | ||
|
||
const newCanonicalAddresses = await RegistryContract.collectAddresses( | ||
publicClient, | ||
deployedAddresses.registryAddress, | ||
'canonical', | ||
); | ||
|
||
expect(newCanonicalAddresses).toEqual({ | ||
...deployedAddresses, | ||
...newAddresses, | ||
}); | ||
|
||
await expect( | ||
RegistryContract.collectAddresses(publicClient, deployedAddresses.registryAddress, 2), | ||
).resolves.toEqual(newCanonicalAddresses); | ||
|
||
await expect( | ||
RegistryContract.collectAddresses(publicClient, deployedAddresses.registryAddress, 1), | ||
).resolves.toEqual(deployedAddresses); | ||
}); | ||
}); | ||
|
||
async function executeGovernanceProposal( | ||
proposalId: bigint, | ||
governance: any, | ||
voteAmount: bigint, | ||
privateKey: PrivateKeyAccount, | ||
publicClient: L1Clients['publicClient'], | ||
walletClient: L1Clients['walletClient'], | ||
rpcUrl: string, | ||
logger: Logger, | ||
) { | ||
const proposal = await governance.read.getProposal([proposalId]); | ||
|
||
const waitL1Block = async () => { | ||
await publicClient.waitForTransactionReceipt({ | ||
hash: await walletClient.sendTransaction({ | ||
to: privateKey.address, | ||
value: 1n, | ||
account: privateKey, | ||
}), | ||
}); | ||
}; | ||
|
||
const cheatCodes = new EthCheatCodes(rpcUrl, logger); | ||
|
||
const timeToActive = proposal.creation + proposal.config.votingDelay; | ||
logger.info(`Warping to ${timeToActive + 1n}`); | ||
await cheatCodes.warp(Number(timeToActive + 1n)); | ||
logger.info(`Warped to ${timeToActive + 1n}`); | ||
await waitL1Block(); | ||
|
||
logger.info(`Voting`); | ||
const voteTx = await governance.write.vote([proposalId, voteAmount, true], { account: privateKey }); | ||
await publicClient.waitForTransactionReceipt({ hash: voteTx }); | ||
logger.info(`Voted`); | ||
|
||
const timeToExecutable = timeToActive + proposal.config.votingDuration + proposal.config.executionDelay + 1n; | ||
logger.info(`Warping to ${timeToExecutable}`); | ||
await cheatCodes.warp(Number(timeToExecutable)); | ||
logger.info(`Warped to ${timeToExecutable}`); | ||
await waitL1Block(); | ||
|
||
const executeTx = await governance.write.execute([proposalId], { account: privateKey }); | ||
await publicClient.waitForTransactionReceipt({ hash: executeTx }); | ||
logger.info(`Executed proposal`); | ||
} | ||
|
||
async function createGovernanceProposal( | ||
payloadAddress: `0x${string}`, | ||
addresses: L1ContractAddresses, | ||
privateKey: PrivateKeyAccount, | ||
publicClient: L1Clients['publicClient'], | ||
logger: Logger, | ||
) { | ||
const token = getContract({ | ||
address: addresses.feeJuiceAddress.toString(), | ||
abi: FeeJuiceAbi, | ||
client: publicClient, | ||
}); | ||
|
||
const governance = getContract({ | ||
address: addresses.governanceAddress.toString(), | ||
abi: GovernanceAbi, | ||
client: publicClient, | ||
}); | ||
|
||
const lockAmount = 10000n * 10n ** 18n; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If configs are changed this would likely be breaking. Also, if they are the same value, we could reduce the number of magic numbers and not have them both be defined with a constant like this 🫡 |
||
const voteAmount = 10000n * 10n ** 18n; | ||
|
||
const mintTx = await token.write.mint([privateKey.address, lockAmount + voteAmount], { account: privateKey }); | ||
await publicClient.waitForTransactionReceipt({ hash: mintTx }); | ||
logger.info(`Minted tokens`); | ||
|
||
const approveTx = await token.write.approve([addresses.governanceAddress.toString(), lockAmount + voteAmount], { | ||
account: privateKey, | ||
}); | ||
await publicClient.waitForTransactionReceipt({ hash: approveTx }); | ||
logger.info(`Approved tokens`); | ||
|
||
const depositTx = await governance.write.deposit([privateKey.address, lockAmount + voteAmount], { | ||
account: privateKey, | ||
}); | ||
await publicClient.waitForTransactionReceipt({ hash: depositTx }); | ||
logger.info(`Deposited tokens`); | ||
|
||
await governance.write.proposeWithLock([payloadAddress, privateKey.address], { | ||
account: privateKey, | ||
}); | ||
|
||
return { governance, voteAmount }; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
periphery is vague,
its not clear to me that its deploying a governance payload and slash factory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasong that it is not just doing the "usual" deployment, and then deploying the extra components separate? Is it also to be used in the cli. Otherwise it seems like a bit of an overkill to ingrain it all the way in there.
Beyond that, package wise, should we be pulling in all the deployment stuff for using contracts as well? I mean things like deploying the contracts etc is not needed for the sequencer or any of the others nodes but won't they end up loading some of it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused on the first point- we do a usual deployment in the
beforeAll
? Or are you saying "usual" here just for deploying the rollup contract and then have separate functions for deploying the rollup's slash factory and upgrade proposal? If so, then yes this function is a convenience wrapper over some utilities that do just that.For the second one, I agree, but since the deploy stuff is already in @aztec/ethereum alongside these contract utility classes, the sequencer is already pulling all of it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But also, yes, this is used in the CLI as part of #12127