Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions spartan/scripts/upgrade_rollup_with_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ set -exu
# ./upgrade_rollup_with_cli.sh \
# --aztec-docker-image aztecprotocol/aztec:c5e2b43044862882a68de47cac07b7116e74e51e \
# --registry 0x29f815e32efdef19883cf2b92a766b7aebadd326 \
# --address 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 \
# --deposit-amount 200000000000000000000000 \
# --mint \
# --test-accounts \
# --sponsored-fpc
#
# where:
# - aztec-docker-tag is the tag of the aztec docker image to use.
# - registry is the address of the registry contract.
# - address is the address that corresponds to whatever mnemonic/private key you are using.
# - deposit-amount is optional, and if provided, will deposit the specified amount of governance tokens to the address.
# - mint is optional, and if provided, will mint the governance tokens to the address before depositing.
# - test-accounts is optional, and if provided, will initialise the genesis state with funded test accounts.
# - sponsored-fpc is optional, and if provided, will initialise the genesis state with a funded FPC.
#
Expand All @@ -41,15 +35,10 @@ set -exu
# ./spartan/scripts/upgrade_rollup_with_cli.sh \
# --aztec-bin $AZTEC_BIN \
# --registry 0x29f815e32efdef19883cf2b92a766b7aebadd326 \
# --address 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 \
# --deposit-amount 10000000000000000 \
# --mint
# --test-accounts \
# --sponsored-fpc

# First set from environment variables if they exist
DEPOSIT_AMOUNT=""
MINT=""
SALT=$((RANDOM % 1000000))
# The default path to the aztec binary within the docker image
AZTEC_BIN="/usr/src/yarn-project/aztec/dest/bin/index.js"
Expand All @@ -68,10 +57,6 @@ while [[ $# -gt 0 ]]; do
AZTEC_BIN="$2"
shift 2
;;
--deposit-amount)
DEPOSIT_AMOUNT="$2"
shift 2
;;
--salt)
SALT="$2"
shift 2
Expand All @@ -80,14 +65,10 @@ while [[ $# -gt 0 ]]; do
REGISTRY="$2"
shift 2
;;
--address)
MY_ADDR="$2"
--l1-chain-id)
L1_CHAIN_ID="$2"
shift 2
;;
--mint)
MINT="--mint"
shift 1
;;
--test-accounts)
TEST_ACCOUNTS="--test-accounts"
shift 1
Expand All @@ -109,11 +90,6 @@ if [ -z "$REGISTRY" ]; then
exit 1
fi

if [ -z "$MY_ADDR" ]; then
echo "Error: --address argument is required"
exit 1
fi

# Only need this in the docker case
cleanup() {
# Add error handling and force removal
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec/src/cli/cmds/start_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export async function startNode(
nodeConfig.l1Contracts.registryAddress,
nodeConfig.l1RpcUrls,
nodeConfig.l1ChainId,
nodeConfig.rollupVersion,
);

// TODO(#12272): will clean this up.
Expand Down
8 changes: 7 additions & 1 deletion yarn-project/aztec/src/cli/cmds/start_prover_broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ export async function startProverBroker(
throw new Error('L1 registry address is required to start Aztec Node without --deploy-aztec-contracts option');
}

const { addresses } = await getL1Config(config.l1Contracts.registryAddress, config.l1RpcUrls, config.l1ChainId);
const { addresses, config: rollupConfig } = await getL1Config(
config.l1Contracts.registryAddress,
config.l1RpcUrls,
config.l1ChainId,
config.rollupVersion,
);

config.l1Contracts = addresses;
config.rollupVersion = rollupConfig.rollupVersion;

const client = initTelemetryClient(getTelemetryClientConfig());
const broker = await createAndStartProvingBroker(config, client);
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec/src/cli/cmds/start_prover_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function startProverNode(
proverConfig.l1Contracts.registryAddress,
proverConfig.l1RpcUrls,
proverConfig.l1ChainId,
proverConfig.rollupVersion,
);
proverConfig.l1Contracts = addresses;
proverConfig = { ...proverConfig, ...config };
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/aztec/src/cli/get_l1_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ export async function getL1Config(
registryAddress: EthAddress,
l1RpcUrls: string[],
l1ChainId: number,
rollupVersion: number | 'canonical' = 'canonical',
): Promise<{ addresses: L1ContractAddresses; config: Awaited<ReturnType<typeof getL1ContractsConfig>> }> {
const publicClient = getPublicClient({ l1RpcUrls, l1ChainId });
const addresses = await RegistryContract.collectAddresses(publicClient, registryAddress, 'canonical');
const addresses = await RegistryContract.collectAddresses(publicClient, registryAddress, rollupVersion);

const config = await getL1ContractsConfig(publicClient, addresses);

Expand Down
1 change: 1 addition & 0 deletions yarn-project/cli/src/cmds/l1/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export async function deployL1Contracts(
log(`Governance Address: ${l1ContractAddresses.governanceAddress.toString()}`);
log(`SlashFactory Address: ${l1ContractAddresses.slashFactoryAddress?.toString()}`);
log(`FeeAssetHandler Address: ${l1ContractAddresses.feeAssetHandlerAddress?.toString()}`);
log(`StakingAssetHandler Address: ${l1ContractAddresses.stakingAssetHandlerAddress?.toString()}`);
log(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
log(`Initial validators: ${initialValidators.map(a => a.toString()).join(', ')}`);
log(`Genesis block hash: ${genesisBlockHash.toString()}`);
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/cli/src/cmds/l1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type Command, Option } from 'commander';

import {
ETHEREUM_HOSTS,
MNEMONIC,
PRIVATE_KEY,
l1ChainIdOption,
makePxeOption,
Expand Down Expand Up @@ -74,7 +75,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger
.option(
'-m, --mnemonic <string>',
'The mnemonic to use in deployment',
'test test test test test test test test test test test junk',
MNEMONIC ?? 'test test test test test test test test test test test junk',
)
.option('-i, --mnemonic-index <number>', 'The index of the mnemonic to use in deployment', arg => parseInt(arg), 0)
.addOption(l1ChainIdOption)
Expand Down
16 changes: 14 additions & 2 deletions yarn-project/cli/src/utils/aztec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type { EthAddress, PXE } from '@aztec/aztec.js';
import { EthAddress, type PXE } from '@aztec/aztec.js';
import {
type ContractArtifact,
type FunctionAbi,
FunctionType,
getAllFunctionAbis,
loadContractArtifact,
} from '@aztec/aztec.js/abi';
import type { DeployL1ContractsReturnType, L1ContractsConfig, RollupContract } from '@aztec/ethereum';
import {
type DeployL1ContractsReturnType,
type L1ContractsConfig,
RegistryContract,
RollupContract,
} from '@aztec/ethereum';
import type { Fr } from '@aztec/foundation/fields';
import type { LogFn, Logger } from '@aztec/foundation/log';
import type { NoirPackageConfig } from '@aztec/foundation/noir';
Expand Down Expand Up @@ -107,6 +112,13 @@ export async function deployNewRollupContracts(
const chain = createEthereumChain(rpcUrls, chainId);
const clients = createL1Clients(rpcUrls, account, chain.chainInfo, mnemonicIndex);

if (!initialValidators || initialValidators.length === 0) {
const registry = new RegistryContract(clients.publicClient, registryAddress);
const rollup = new RollupContract(clients.publicClient, await registry.getCanonicalAddress());
initialValidators = (await rollup.getAttesters()).map(str => EthAddress.fromString(str));
logger.info('Initializing new rollup with old attesters', { initialValidators });
}

const { rollup, slashFactoryAddress } = await deployRollupForUpgrade(
clients,
{
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getLocalhost = () =>
.catch(() => 'localhost');

export const LOCALHOST = await getLocalhost();
export const { ETHEREUM_HOSTS = `http://${LOCALHOST}:8545`, PRIVATE_KEY, API_KEY, CLI_VERSION } = process.env;
export const { ETHEREUM_HOSTS = `http://${LOCALHOST}:8545`, PRIVATE_KEY, MNEMONIC, API_KEY, CLI_VERSION } = process.env;

export function addOptions(program: Command, options: Option[]) {
options.forEach(option => program.addOption(option));
Expand Down
29 changes: 3 additions & 26 deletions yarn-project/end-to-end/src/spartan/upgrade_via_cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type PXE, createCompatibleClient } from '@aztec/aztec.js';
import { GovernanceContract, RegistryContract, createEthereumChain, createL1Clients } from '@aztec/ethereum';
import { RegistryContract, createEthereumChain, createL1Clients } from '@aztec/ethereum';
import { createLogger } from '@aztec/foundation/log';

import type { ChildProcess } from 'child_process';
Expand Down Expand Up @@ -55,37 +55,14 @@ describe('upgrade via cli', () => {
const info = await pxe.getNodeInfo();

const chain = createEthereumChain([ETHEREUM_HOSTS], info.l1ChainId);
const { walletClient: l1WalletClient, publicClient: l1PublicClient } = createL1Clients(
[ETHEREUM_HOSTS],
MNEMONIC,
chain.chainInfo,
);

const governance = new GovernanceContract(
info.l1ContractAddresses.governanceAddress.toString(),
l1PublicClient,
l1WalletClient,
);
const { minimumVotes, proposeConfig } = await governance.getConfiguration();

const depositAmount = proposeConfig.lockAmount + minimumVotes;
const { publicClient: l1PublicClient } = createL1Clients([ETHEREUM_HOSTS], MNEMONIC, chain.chainInfo);

const registry = new RegistryContract(l1PublicClient, info.l1ContractAddresses.registryAddress.toString());
const oldNumberOfVersions = await registry.getNumberOfVersions();

const exitCode = await runProjectScript(
'spartan/scripts/upgrade_rollup_with_cli.sh',
[
'--aztec-bin',
getAztecBin(),
'--registry',
info.l1ContractAddresses.registryAddress.toString(),
'--address',
l1WalletClient.account.address,
'--deposit-amount',
depositAmount.toString(),
'--mint',
],
['--aztec-bin', getAztecBin(), '--registry', info.l1ContractAddresses.registryAddress.toString()],
debugLogger,
{
MNEMONIC,
Expand Down
7 changes: 6 additions & 1 deletion yarn-project/ethereum/src/contracts/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ describe('Registry', () => {
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', 'feeAssetHandlerAddress');
deployedAddresses = omit(
deployed.l1ContractAddresses,
'slashFactoryAddress',
'feeAssetHandlerAddress',
'stakingAssetHandlerAddress',
);
registry = new RegistryContract(publicClient, deployedAddresses.registryAddress);

const rollup = new RollupContract(publicClient, deployedAddresses.rollupAddress);
Expand Down
11 changes: 9 additions & 2 deletions yarn-project/ethereum/src/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,14 @@ export const deployL1Contracts = async (
txUtilsConfig,
);

const { feeAssetAddress, feeAssetHandlerAddress, stakingAssetAddress, registryAddress, rewardDistributorAddress } =
await deploySharedContracts(clients, deployer, args, logger);
const {
feeAssetAddress,
feeAssetHandlerAddress,
stakingAssetAddress,
stakingAssetHandlerAddress,
registryAddress,
rewardDistributorAddress,
} = await deploySharedContracts(clients, deployer, args, logger);
const { rollup, slashFactoryAddress } = await deployRollup(
clients,
deployer,
Expand Down Expand Up @@ -913,6 +919,7 @@ export const deployL1Contracts = async (
...l1Contracts,
slashFactoryAddress,
feeAssetHandlerAddress,
stakingAssetHandlerAddress,
},
};
};
Expand Down
11 changes: 10 additions & 1 deletion yarn-project/ethereum/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import type { ViemPublicClient } from './types.js';
export async function getL1ContractsConfig(
publicClient: ViemPublicClient,
addresses: { governanceAddress: EthAddress; rollupAddress?: EthAddress },
): Promise<Omit<L1ContractsConfig, 'ethereumSlotDuration'> & { l1StartBlock: bigint; l1GenesisTime: bigint }> {
): Promise<
Omit<L1ContractsConfig, 'ethereumSlotDuration'> & {
l1StartBlock: bigint;
l1GenesisTime: bigint;
rollupVersion: number;
}
> {
const governance = new GovernanceContract(addresses.governanceAddress.toString(), publicClient, undefined);
const governanceProposerAddress = await governance.getGovernanceProposerAddress();
const governanceProposer = new GovernanceProposerContract(publicClient, governanceProposerAddress.toString());
Expand All @@ -35,6 +41,7 @@ export async function getL1ContractsConfig(
slashingRoundSize,
manaTarget,
provingCostPerMana,
rollupVersion,
] = await Promise.all([
rollup.getL1StartBlock(),
rollup.getL1GenesisTime(),
Expand All @@ -49,6 +56,7 @@ export async function getL1ContractsConfig(
slasherProposer.getRoundSize(),
rollup.getManaTarget(),
rollup.getProvingCostPerMana(),
rollup.getVersion(),
] as const);

return {
Expand All @@ -65,6 +73,7 @@ export async function getL1ContractsConfig(
slashingRoundSize: Number(slashingRoundSize),
manaTarget: manaTarget,
provingCostPerMana: provingCostPerMana,
rollupVersion: Number(rollupVersion),
};
}

Expand Down
6 changes: 5 additions & 1 deletion yarn-project/prover-client/src/proving_broker/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
getDefaultConfig,
numberConfigHelper,
} from '@aztec/foundation/config';
import { pickConfigMappings } from '@aztec/foundation/config';
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
import { ProvingRequestType } from '@aztec/stdlib/proofs';

import { z } from 'zod';
Expand Down Expand Up @@ -33,7 +35,8 @@ export const ProverBrokerConfig = z.object({

export type ProverBrokerConfig = z.infer<typeof ProverBrokerConfig> &
Pick<DataStoreConfig, 'dataStoreMapSizeKB' | 'dataDirectory'> &
L1ReaderConfig;
L1ReaderConfig &
Pick<ChainConfig, 'rollupVersion'>;

export const proverBrokerConfigMappings: ConfigMappingsType<ProverBrokerConfig> = {
proverBrokerJobTimeoutMs: {
Expand Down Expand Up @@ -73,6 +76,7 @@ export const proverBrokerConfigMappings: ConfigMappingsType<ProverBrokerConfig>
},
...dataConfigMappings,
...l1ReaderConfigMappings,
...pickConfigMappings(chainConfigMappings, ['rollupVersion']),
};

export const defaultProverBrokerConfig: ProverBrokerConfig = getDefaultConfig(proverBrokerConfigMappings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('ProvingBrokerPersistedDatabase', () => {
l1RpcUrls: [],
l1ChainId: 42,
viemPollingIntervalMS: 100,
rollupVersion: 42,
};
db = await KVBrokerDatabase.new(config);
});
Expand Down Expand Up @@ -342,6 +343,7 @@ describe('ProvingBrokerPersistedDatabase', () => {
l1RpcUrls: [],
l1ChainId: 42,
viemPollingIntervalMS: 100,
rollupVersion: 42,
};
db = await KVBrokerDatabase.new(config);
commitSpy = jest.spyOn(db, 'commitWrites');
Expand Down