Skip to content

Commit

Permalink
chore: Unhardcode canonical addresses of deployer and registerer cont…
Browse files Browse the repository at this point in the history
…racts (#4467)

Creates a new package `protocol-contracts` to store the artifacts and
canonical deployment addresses for well-known protocol contracts.
Contains deployer and registerer for now, should include address
registry and encryption precompiles in the future as well.

Builds on #4436.
  • Loading branch information
spalladino authored Feb 7, 2024
1 parent 4113cfd commit 2c82b62
Show file tree
Hide file tree
Showing 26 changed files with 1,284 additions and 15 deletions.
3 changes: 2 additions & 1 deletion yarn-project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ COPY . .
RUN yarn workspace @aztec/noir-compiler build
# Builds noir contracts (TODO: move this stage pre yarn-project). Generates typescript wrappers.
RUN yarn workspace @aztec/noir-contracts build:contracts
# We need to build accounts as it needs to copy in account contracts from noir-contracts.
# We need to copy noir contracts into other packages
RUN yarn workspace @aztec/accounts build:copy-contracts
RUN yarn workspace @aztec/protocol-contracts build:copy-contracts
RUN yarn workspace @aztec/noir-protocol-circuits build
RUN yarn tsc -b

Expand Down
1 change: 1 addition & 0 deletions yarn-project/archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@aztec/foundation": "workspace:^",
"@aztec/kv-store": "workspace:^",
"@aztec/l1-artifacts": "workspace:^",
"@aztec/protocol-contracts": "workspace:^",
"@aztec/types": "workspace:^",
"debug": "^4.3.4",
"lmdb": "^2.9.2",
Expand Down
16 changes: 4 additions & 12 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer';
import { InstanceDeployerAddress } from '@aztec/protocol-contracts/instance-deployer';
import {
ContractClass,
ContractClassPublic,
Expand Down Expand Up @@ -71,21 +73,11 @@ export class Archiver implements ArchiveSource {
*/
private lastLoggedL1BlockNumber = 0n;

// TODO(@spalladino): Calculate this on the fly somewhere else.
// Today this is printed in the logs for end-to-end test at
// end-to-end/src/e2e_deploy_contract.test.ts -t 'registering a new contract class'
// "Added contract ContractClassRegisterer ADDRESS"
// "Added contract ContractInstanceDeployer ADDRESS"

/** Address of the ClassRegisterer contract with a salt=1 */
private classRegistererAddress = AztecAddress.fromString(
'0x29c0cd0000951bba8af520ad5513cc53d9f0413c5a24a72a4ba8c17894c0bef9',
);
private classRegistererAddress = ClassRegistererAddress;

/** Address of the InstanceDeployer contract with a salt=1 */
private instanceDeployerAddress = AztecAddress.fromString(
'0x1799c61aa10430bf6fec46679c4cb76c3ed12cd8b6e73ed7389d5ae296ad1b97',
);
private instanceDeployerAddress = InstanceDeployerAddress;

/**
* Creates a new instance of the Archiver.
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/archiver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
{
"path": "../l1-artifacts"
},
{
"path": "../protocol-contracts"
},
{
"path": "../types"
}
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ yarn workspace @aztec/noir-compiler build
# Builds noir contracts (TODO: move this stage pre yarn-project). Generates typescript wrappers.
echo "Building contracts from noir-contracts..."
yarn workspace @aztec/noir-contracts build:contracts
# Bundle compiled account contracts into accounts package
# Bundle compiled contracts into other packages
echo "Copying account contracts..."
yarn workspace @aztec/accounts build:copy-contracts
echo "Copying protocol contracts..."
yarn workspace @aztec/protocol-contracts build:copy-contracts
# Build protocol circuits. TODO: move pre yarn-project.
echo "Building circuits from noir-protocol-circuits..."
yarn workspace @aztec/noir-protocol-circuits build
Expand Down
1 change: 1 addition & 0 deletions yarn-project/deploy_npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ deploy_package foundation
deploy_package types
deploy_package circuits.js
deploy_package circuit-types
deploy_package protocol-contracts
deploy_package aztec.js
deploy_package accounts
deploy_package l1-artifacts
Expand Down
1 change: 1 addition & 0 deletions yarn-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"noir-protocol-circuits",
"p2p",
"p2p-bootstrap",
"protocol-contracts",
"prover-client",
"rollup-provider",
"sequencer-client",
Expand Down
1 change: 1 addition & 0 deletions yarn-project/protocol-contracts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@aztec/foundation/eslint');
1 change: 1 addition & 0 deletions yarn-project/protocol-contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src/artifacts
7 changes: 7 additions & 0 deletions yarn-project/protocol-contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Protocol Contracts

Canonical Noir contracts used to power the Aztec Network protocol.

Includes:
- Contract class registerer
- Contract instance deployer
69 changes: 69 additions & 0 deletions yarn-project/protocol-contracts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@aztec/protocol-contracts",
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/protocol-contracts",
"description": "Canonical Noir contracts for the Aztec Network",
"version": "0.1.0",
"type": "module",
"exports": {
".": "./dest/index.js",
"./*": "./dest/*/index.js"
},
"typedocOptions": {
"entryPoints": [
"./src/index.ts",
"./src/class-registerer/index.ts",
"./src/instance-deployer/index.ts"
],
"name": "Protocol Contracts",
"tsconfig": "./tsconfig.json"
},
"scripts": {
"build": "yarn clean && yarn build:copy-contracts && tsc -b",
"build:copy-contracts": "./scripts/copy-contracts.sh",
"build:dev": "tsc -b --watch",
"build:ts": "tsc -b",
"clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
},
"inherits": [
"../package.common.json",
"./package.local.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
},
"dependencies": {
"@aztec/circuits.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/types": "workspace:^",
"lodash.omit": "^4.5.0",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/lodash.omit": "^4.5.9",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"files": [
"dest",
"src",
"!*.test.*"
],
"engines": {
"node": ">=18"
}
}
9 changes: 9 additions & 0 deletions yarn-project/protocol-contracts/package.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"build": "yarn clean && yarn build:copy-contracts && tsc -b",
"build:copy-contracts": "./scripts/copy-contracts.sh",
"build:dev": "tsc -b --watch",
"build:ts": "tsc -b",
"clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts"
}
}
11 changes: 11 additions & 0 deletions yarn-project/protocol-contracts/scripts/copy-contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/bash
set -euo pipefail
mkdir -p ./src/artifacts

contracts=(contract_class_registerer_contract-ContractClassRegisterer contract_instance_deployer_contract-ContractInstanceDeployer)

for contract in "${contracts[@]}"; do
cp "../noir-contracts/target/$contract.json" ./src/artifacts/${contract#*-}.json
done

yarn run -T prettier -w ./src/artifacts
Loading

0 comments on commit 2c82b62

Please sign in to comment.