Skip to content

Commit

Permalink
plumbing
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Sep 3, 2024
1 parent dd2a9bc commit ab95620
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ library Constants {
2631409926445785927331173506476539962589925110142857699603561302478860342858;
uint256 internal constant FEE_JUICE_ADDRESS =
10248142274714515101077825679585135641434041564851038865006795089686437446849;
uint256 internal constant ROUTER_ADDRESS =
1063406426795385693869347374716646040831772088487068062386500675099194233623;
uint256 internal constant AZTEC_ADDRESS_LENGTH = 1;
uint256 internal constant GAS_FEES_LENGTH = 2;
uint256 internal constant GAS_LENGTH = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// The purpose of this contract is to perform a check in public without revealing what contract enqued the public
/// call. This is achieved by having a private function on this contract that enques the public call and hence
/// the `msg_sender` in the public call is the address of this contract.
contract RouterContract {
contract Router {
use dep::aztec::note::note_getter_options::Comparator;

#[aztec(private)]
fn check_timestamp(operation: u8, value: u64) {
RouterContract::at(context.this_address())._check_timestamp(operation, value).enqueue(&mut context);
Router::at(context.this_address())._check_timestamp(operation, value).enqueue(&mut context);
}

#[aztec(public)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ global CANONICAL_AUTH_REGISTRY_ADDRESS = AztecAddress::from_field(0x24877c50868f
global DEPLOYER_CONTRACT_ADDRESS = AztecAddress::from_field(0x2ab1a2bd6d07d8d61ea56d85861446349e52c6b7c0612b702cb1e6db6ad0b089);
global REGISTERER_CONTRACT_ADDRESS = AztecAddress::from_field(0x05d15342d76e46e5be07d3cda0d753158431cdc5e39d29ce4e8fe1f5c070564a);
global FEE_JUICE_ADDRESS = AztecAddress::from_field(0x16a83e3395bc921a2441db55dce24f0e0932636901a2e676fa68b9b2b9a644c1);
global ROUTER_ADDRESS = AztecAddress::from_field(0x0259dde096e975185dd026b0aade4fc9ff1478c361dbbe0b3922b8c206e31317);

// LENGTH OF STRUCTS SERIALIZED TO FIELDS
global AZTEC_ADDRESS_LENGTH = 1;
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const DEPLOYER_CONTRACT_ADDRESS = 193109947607833303683371634801986023939
export const REGISTERER_CONTRACT_ADDRESS =
2631409926445785927331173506476539962589925110142857699603561302478860342858n;
export const FEE_JUICE_ADDRESS = 10248142274714515101077825679585135641434041564851038865006795089686437446849n;
export const ROUTER_ADDRESS = 1063406426795385693869347374716646040831772088487068062386500675099194233623n;
export const AZTEC_ADDRESS_LENGTH = 1;
export const GAS_FEES_LENGTH = 2;
export const GAS_LENGTH = 2;
Expand Down Expand Up @@ -395,6 +396,7 @@ export enum GeneratorIndex {
SIDE_EFFECT = 29,
FEE_PAYLOAD = 30,
COMBINED_PAYLOAD = 31,
TX_NULLIFIER = 32,
TX_REQUEST = 33,
SIGNATURE_PAYLOAD = 34,
VK = 41,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/contract/artifact_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function computeArtifactMetadataHash(artifact: ContractArtifact) {
'FeeJuice',
'ContractInstanceDeployer',
'ContractClassRegisterer',
'Router',
];

// This is a temporary workaround for the canonical contracts to have deterministic deployments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('UnconstrainedFunctionBroadcastedEvent', () => {
expect(event).toMatchSnapshot();
});

it('filters out zero-elements at the end of the artifcat tree sibling path', () => {
it('filters out zero-elements at the end of the artifact tree sibling path', () => {
const siblingPath: Tuple<Fr, 5> = [Fr.ZERO, new Fr(1), Fr.ZERO, new Fr(2), Fr.ZERO];
const event = new UnconstrainedFunctionBroadcastedEvent(
Fr.random(),
Expand Down
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 @@ -9,6 +9,7 @@ contracts=(
key_registry_contract-KeyRegistry
auth_registry_contract-AuthRegistry
multi_call_entrypoint_contract-MultiCallEntrypoint
router_contract-Router
)


Expand Down
6 changes: 6 additions & 0 deletions yarn-project/protocol-contracts/src/router/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 RouterJson from '../../artifacts/Router.json' assert { type: 'json' };

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

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

describe('Router', () => {
it('returns canonical protocol contract', () => {
const contract = getCanonicalRouter();
expect(computeContractAddressFromInstance(contract.instance)).toEqual(contract.address);
expect(getContractClassFromArtifact(contract.artifact).id).toEqual(contract.contractClass.id);
expect(contract.address).toEqual(AztecAddress.fromBigInt(ROUTER_ADDRESS));
});
});
22 changes: 22 additions & 0 deletions yarn-project/protocol-contracts/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AztecAddress, ROUTER_ADDRESS } from '@aztec/circuits.js';

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

/** Returns the canonical deployment of the auth registry. */
export function getCanonicalRouter(): ProtocolContract {
const contract = getCanonicalProtocolContract(RouterArtifact, 1);

if (!contract.address.equals(RouterAddress)) {
throw new Error(
`Incorrect address for auth registry (got ${contract.address.toString()} but expected ${RouterAddress.toString()}). Check ROUTER_ADDRESS is set to the correct value in the constants files and run the protocol-contracts package tests.`,
);
}
return contract;
}

export function getCanonicalRouterAddress(): AztecAddress {
return getCanonicalRouter().address;
}

export const RouterAddress = AztecAddress.fromBigInt(ROUTER_ADDRESS);

0 comments on commit ab95620

Please sign in to comment.