Skip to content
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: add key registry to deployment (e2e & sandbox) #5875

Merged
merged 65 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3eb0d7b
initial
sklppy88 Apr 19, 2024
72ca505
yarn format
sklppy88 Apr 19, 2024
3da10c1
fixes
sklppy88 Apr 19, 2024
1f166da
Revert "fixes"
sklppy88 Apr 19, 2024
f09c76b
fix
sklppy88 Apr 19, 2024
dfde46d
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 19, 2024
7ead539
fix
sklppy88 Apr 19, 2024
9de1a5f
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 19, 2024
eb6e7ae
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 20, 2024
8a26311
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 22, 2024
67e71c9
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 22, 2024
3f4fe51
fix
sklppy88 Apr 22, 2024
1366fc9
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 22, 2024
4a8eca9
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 23, 2024
437514f
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 23, 2024
99a5b2b
Address comments
sklppy88 Apr 23, 2024
be3f86c
string
sklppy88 Apr 23, 2024
5708964
remake consts
sklppy88 Apr 23, 2024
ff5af43
fix
sklppy88 Apr 23, 2024
c6b1b7e
fix ?
sklppy88 Apr 23, 2024
2119e01
conts
sklppy88 Apr 23, 2024
d46db22
fix
sklppy88 Apr 23, 2024
c3bbd71
fix
sklppy88 Apr 23, 2024
b809aa2
fix
sklppy88 Apr 23, 2024
d210838
fix
sklppy88 Apr 23, 2024
4e2f5a4
hack
sklppy88 Apr 23, 2024
501e079
fix
sklppy88 Apr 23, 2024
426be8b
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 23, 2024
33d2e61
another salt ?
sklppy88 Apr 23, 2024
a2f858b
fix
sklppy88 Apr 23, 2024
de746ea
another constants
sklppy88 Apr 23, 2024
41e6ec5
fix
sklppy88 Apr 23, 2024
3e8d86b
asdf
sklppy88 Apr 23, 2024
4355e8f
asf
sklppy88 Apr 23, 2024
59e5cfa
asdf
sklppy88 Apr 23, 2024
bf2f5fa
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 24, 2024
a87bbf5
fix
sklppy88 Apr 24, 2024
7a69d69
test
sklppy88 Apr 24, 2024
3484dde
temp
sklppy88 Apr 24, 2024
06f7604
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 24, 2024
fecb707
fix ?
sklppy88 Apr 24, 2024
40fb063
remake consts
sklppy88 Apr 24, 2024
aa6bde4
fix
sklppy88 Apr 24, 2024
12ca58c
fix ?
sklppy88 Apr 24, 2024
3922eef
snaps
sklppy88 Apr 24, 2024
693137b
fix
sklppy88 Apr 24, 2024
f3f2fc4
fix
sklppy88 Apr 24, 2024
3b9db8e
fix
sklppy88 Apr 24, 2024
81c3496
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 24, 2024
2e75e61
why
sklppy88 Apr 24, 2024
a5e1b96
???
sklppy88 Apr 24, 2024
946a835
edits
sklppy88 Apr 24, 2024
2e8ed6c
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 24, 2024
8e97be0
fix ?
sklppy88 Apr 24, 2024
715cfed
test
sklppy88 Apr 24, 2024
8365d54
test
sklppy88 Apr 24, 2024
73853cf
format
sklppy88 Apr 24, 2024
abe64eb
fix
sklppy88 Apr 25, 2024
55f1006
fix
sklppy88 Apr 25, 2024
5cb8d5f
asdf
sklppy88 Apr 25, 2024
af07727
add comment
sklppy88 Apr 25, 2024
ea63152
fix
sklppy88 Apr 25, 2024
6e35053
Merge branch 'master' into ek/feat/add-key-registry-to-deployment
sklppy88 Apr 25, 2024
666921d
asdf
sklppy88 Apr 25, 2024
ecdcf29
address comments
sklppy88 Apr 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 100_000_000;
global DEFAULT_MAX_FEE_PER_GAS: Field = 10;
global DEFAULT_INCLUSION_FEE: Field = 0;

global CANONICAL_KEY_REGISTRY_ADDRESS = 0x0fde809aaeb2210ca367381dfa9a46fb4542d67bcb27538e8de72151ae6d545c;

// LENGTH OF STRUCTS SERIALIZED TO FIELDS
global AZTEC_ADDRESS_LENGTH = 1;
global GAS_FEES_LENGTH: u64 = 3;
Expand Down
25 changes: 25 additions & 0 deletions yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
RollupBytecode,
} from '@aztec/l1-artifacts';
import { getCanonicalGasToken } from '@aztec/protocol-contracts/gas-token';
import { getCanonicalKeyRegistry } from '@aztec/protocol-contracts/key-registry';
import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe';

import {
Expand Down Expand Up @@ -182,6 +183,26 @@ async function deployCanonicalL2GasToken(deployer: Wallet, l1ContractAddresses:
logger.info(`Deployed Gas Token on L2 at ${canonicalGasToken.address}`);
}

/**
* Deploys the key registry on L2.
*/
async function deployCanonicalKeyRegistry(deployer: Wallet) {
const canonicalKeyRegistry = getCanonicalKeyRegistry();

if (await deployer.isContractClassPubliclyRegistered(canonicalKeyRegistry.contractClass.id)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check only checks contract class so I think it could happen that someone could accidentally deploy it to a different address (for example by using a different salt) and then this would not deploy an instance even though it should.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 99a5b2b

return;
}

await new BatchCall(deployer, [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If rebasing you should see the deployment flow that we are normally using for the deployCanonicalL2GasToken I think it would be better to also use that here to not have different flows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 99a5b2b

(await registerContractClass(deployer, canonicalKeyRegistry.artifact)).request(),
deployInstance(deployer, canonicalKeyRegistry.instance).request(),
])
.send()
.wait();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please throw here an error if the address of the deployed contract does not match the constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 99a5b2b

logger.info(`Deployed Key Registry on L2 at ${canonicalKeyRegistry.address}`);
}

/** Sandbox settings. */
export type SandboxConfig = AztecNodeConfig & {
/** Mnemonic used to derive the L1 deployer private key.*/
Expand Down Expand Up @@ -210,6 +231,10 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
const node = await createAztecNode(aztecNodeConfig);
const pxe = await createAztecPXE(node);

await deployCanonicalKeyRegistry(
new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.chainId, aztecNodeConfig.version)),
);

if (config.enableGas) {
await deployCanonicalL2GasToken(
new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.chainId, aztecNodeConfig.version)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
const BLOCK_SIZE = BENCHMARK_HISTORY_BLOCK_SIZE;
const CHAIN_LENGTHS = BENCHMARK_HISTORY_CHAIN_LENGTHS;
const MAX_CHAIN_LENGTH = CHAIN_LENGTHS[CHAIN_LENGTHS.length - 1];
const SETUP_BLOCK_COUNT = 2; // deploy account + deploy contract
const SETUP_BLOCK_COUNT = 3; // deploy protocol contracts + deploy account + deploy contract

describe('benchmarks/process_history', () => {
let context: EndToEndContext;
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/e2e_key_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type AccountWallet, AztecAddress, Fr, type PXE } from '@aztec/aztec.js'
import { GeneratorIndex } from '@aztec/circuits.js';
import { poseidon2Hash } from '@aztec/foundation/crypto';
import { KeyRegistryContract, TestContract } from '@aztec/noir-contracts.js';
import { getCanonicalKeyRegistryAddress } from '@aztec/protocol-contracts/key-registry';

import { jest } from '@jest/globals';

Expand All @@ -22,7 +23,7 @@ describe('SharedMutablePrivateGetter', () => {
beforeAll(async () => {
({ teardown, pxe, wallets } = await setup(2));
testContract = await TestContract.deploy(wallets[0]).send().deployed();
keyRegistry = await KeyRegistryContract.deploy(wallets[0]).send().deployed();
keyRegistry = await KeyRegistryContract.at(getCanonicalKeyRegistryAddress(), wallets[0]);
LHerskind marked this conversation as resolved.
Show resolved Hide resolved

await publicDeployAccounts(wallets[0], wallets.slice(0, 2));
}, 120_000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('e2e_voting_contract', () => {
votingContract = await EasyPrivateVotingContract.deploy(wallet, owner).send().deployed();

logger.info(`Counter contract deployed at ${votingContract.address}`);
}, 25_000);
}, 45_000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added via Giphy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going in a good direction 🤣


afterAll(() => teardown());

Expand Down
34 changes: 31 additions & 3 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
RollupBytecode,
} from '@aztec/l1-artifacts';
import { getCanonicalGasToken, getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token';
import { getCanonicalKeyRegistry } from '@aztec/protocol-contracts/key-registry';
import { PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe';
import { type SequencerClient } from '@aztec/sequencer-client';

Expand Down Expand Up @@ -260,10 +261,14 @@ async function setupWithRemoteEnvironment(
const cheatCodes = CheatCodes.create(config.rpcUrl, pxeClient!);
const teardown = () => Promise.resolve();

const { chainId, protocolVersion } = await pxeClient.getNodeInfo();
// this contract might already have been deployed
// the following deployin functions are idempotent
await deployCanonicalKeyRegistry(
new SignerlessWallet(pxeClient, new DefaultMultiCallEntrypoint(chainId, protocolVersion)),
);

if (enableGas) {
const { chainId, protocolVersion } = await pxeClient.getNodeInfo();
// this contract might already have been deployed
// the following function is idempotent
await deployCanonicalGasToken(
new SignerlessWallet(pxeClient, new DefaultMultiCallEntrypoint(chainId, protocolVersion)),
);
Expand Down Expand Up @@ -397,6 +402,11 @@ export async function setup(
logger.verbose('Creating a pxe...');
const { pxe, wallets } = await setupPXEService(numberOfAccounts, aztecNode!, pxeOpts, logger);

logger.verbose('Deploying key registry...');
await deployCanonicalKeyRegistry(
new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(config.chainId, config.version)),
);

if (enableGas) {
logger.verbose('Deploying gas token...');
await deployCanonicalGasToken(
Expand Down Expand Up @@ -587,3 +597,21 @@ export async function deployCanonicalGasToken(deployer: Wallet) {
await expect(deployer.isContractClassPubliclyRegistered(canonicalGasToken.contractClass.id)).resolves.toBe(true);
await expect(deployer.getContractInstance(canonicalGasToken.instance.address)).resolves.toBeDefined();
}

export async function deployCanonicalKeyRegistry(deployer: Wallet) {
const canonicalKeyRegistry = getCanonicalKeyRegistry();

if (await deployer.isContractClassPubliclyRegistered(canonicalKeyRegistry.contractClass.id)) {
return;
}

await new BatchCall(deployer, [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 99a5b2b

(await registerContractClass(deployer, canonicalKeyRegistry.artifact)).request(),
deployInstance(deployer, canonicalKeyRegistry.instance).request(),
])
.send()
.wait();

await expect(deployer.isContractClassPubliclyRegistered(canonicalKeyRegistry.contractClass.id)).resolves.toBe(true);
await expect(deployer.getContractInstance(canonicalKeyRegistry.instance.address)).resolves.toBeDefined();
}
1 change: 1 addition & 0 deletions yarn-project/protocol-contracts/scripts/copy-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ contracts=(
contract_class_registerer_contract-ContractClassRegisterer
contract_instance_deployer_contract-ContractInstanceDeployer
gas_token_contract-GasToken
key_registry_contract-KeyRegistry
multi_call_entrypoint_contract-MultiCallEntrypoint
)

Expand Down
6 changes: 6 additions & 0 deletions yarn-project/protocol-contracts/src/key-registry/artifact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { loadContractArtifact } from '@aztec/types/abi';
import { type NoirCompiledContract } from '@aztec/types/noir';

import KeyRegistryJson from '../artifacts/KeyRegistry.json' assert { type: 'json' };

export const KeyRegistryArtifact = loadContractArtifact(KeyRegistryJson as NoirCompiledContract);
11 changes: 11 additions & 0 deletions yarn-project/protocol-contracts/src/key-registry/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/circuits.js';

import { getCanonicalKeyRegistry } from './index.js';

describe('KeyRegistry', () => {
it('returns canonical protocol contract', () => {
const contract = getCanonicalKeyRegistry();
expect(computeContractAddressFromInstance(contract.instance)).toEqual(contract.address);
expect(getContractClassFromArtifact(contract.artifact).id).toEqual(contract.contractClass.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test checking that it matches what we have in the constants as well. OTherwise could be massive pain to figure out 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to check it during deployment. It's harder to accidentally miss as it blows all the e2e tests as well. Added a comment above.

Copy link
Contributor Author

@sklppy88 sklppy88 Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've put it in both places for now.

});
});
13 changes: 13 additions & 0 deletions yarn-project/protocol-contracts/src/key-registry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type AztecAddress } from '@aztec/circuits.js';
LHerskind marked this conversation as resolved.
Show resolved Hide resolved

import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js';
import { KeyRegistryArtifact } from './artifact.js';

/** Returns the canonical deployment of the gas token. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here is wrong 👀 wrong contract name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good look, thanks !

Addressed in ecdcf2

export function getCanonicalKeyRegistry(): ProtocolContract {
return getCanonicalProtocolContract(KeyRegistryArtifact, 1337);
}

export function getCanonicalKeyRegistryAddress(): AztecAddress {
return getCanonicalKeyRegistry().address;
}
2 changes: 2 additions & 0 deletions yarn-project/pxe/src/pxe_service/create_pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { initStoreForRollup } from '@aztec/kv-store/utils';
import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer';
import { getCanonicalGasToken } from '@aztec/protocol-contracts/gas-token';
import { getCanonicalInstanceDeployer } from '@aztec/protocol-contracts/instance-deployer';
import { getCanonicalKeyRegistry } from '@aztec/protocol-contracts/key-registry';
import { getCanonicalMultiCallEntrypointContract } from '@aztec/protocol-contracts/multi-call-entrypoint';

import { join } from 'path';
Expand Down Expand Up @@ -47,6 +48,7 @@ export async function createPXEService(
getCanonicalInstanceDeployer(),
getCanonicalMultiCallEntrypointContract(),
getCanonicalGasToken(l1Contracts.gasPortalAddress),
getCanonicalKeyRegistry(),
]) {
await server.registerContract(contract);
}
Expand Down
Loading