Skip to content
Draft
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
10 changes: 4 additions & 6 deletions barretenberg/cpp/pil/vm2/constants_gen.pil
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ namespace constants;
pol MAX_L2_TO_L1_MSGS_PER_TX = 8;
pol MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 3000;
pol MAX_PROTOCOL_CONTRACTS = 11;
pol CANONICAL_AUTH_REGISTRY_ADDRESS = 1;
pol CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = 2;
pol CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS = 3;
pol MULTI_CALL_ENTRYPOINT_ADDRESS = 4;
pol FEE_JUICE_ADDRESS = 5;
pol PUBLIC_CHECKS_ADDRESS = 6;
pol FEE_JUICE_ADDRESS = 1;
pol CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS = 2;
pol CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = 3;
pol CANONICAL_AUTH_REGISTRY_ADDRESS = 4;
pol FEE_JUICE_BALANCES_SLOT = 1;
pol UPDATED_CLASS_IDS_SLOT = 1;
pol FLAT_PUBLIC_LOGS_HEADER_LENGTH = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
#define GENESIS_ARCHIVE_ROOT "0x15684c8c3d2106918d3860f777e50555b7166adff47df13cc652e2e5a50bf5c7"
#define MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS 3000
#define MAX_PROTOCOL_CONTRACTS 11
#define CANONICAL_AUTH_REGISTRY_ADDRESS 1
#define CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS 2
#define CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS 3
#define MULTI_CALL_ENTRYPOINT_ADDRESS 4
#define FEE_JUICE_ADDRESS 5
#define PUBLIC_CHECKS_ADDRESS 6
#define FEE_JUICE_ADDRESS 1
#define CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS 2
#define CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS 3
#define CANONICAL_AUTH_REGISTRY_ADDRESS 4
#define FEE_JUICE_BALANCES_SLOT 1
#define UPDATED_CLASS_IDS_SLOT 1
#define FLAT_PUBLIC_LOGS_HEADER_LENGTH 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void contract_instance_retrievalImpl<FF_>::accumulate(ContainerOverSubrelations&
using C = ColumnAndShifts;

const auto constants_MAX_PROTOCOL_CONTRACTS = FF(11);
const auto constants_CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = FF(2);
const auto constants_CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = FF(3);
const auto constants_AVM_PUBLIC_INPUTS_PROTOCOL_CONTRACTS_ROW_IDX = FF(8);
const auto contract_instance_retrieval_NOT_EXISTS = (FF(1) - in.get(C::contract_instance_retrieval_exists));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void txImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
const auto constants_MAX_NOTE_HASHES_PER_TX = FF(64);
const auto constants_MAX_NULLIFIERS_PER_TX = FF(64);
const auto constants_MAX_L2_TO_L1_MSGS_PER_TX = FF(8);
const auto constants_FEE_JUICE_ADDRESS = FF(5);
const auto constants_FEE_JUICE_ADDRESS = FF(1);
const auto constants_FEE_JUICE_BALANCES_SLOT = FF(1);
const auto constants_AVM_TX_PHASE_VALUE_START = FF(0);
const auto constants_AVM_TX_PHASE_VALUE_LAST = FF(11);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void update_checkImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
{
using C = ColumnAndShifts;

const auto constants_CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = FF(2);
const auto constants_CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = FF(3);
const auto constants_UPDATED_CLASS_IDS_SLOT = FF(1);
const auto constants_AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_TIMESTAMP_ROW_IDX = FF(4);
const auto constants_TIMESTAMP_OF_CHANGE_BIT_SIZE = FF(32);
Expand Down
Binary file not shown.
8 changes: 7 additions & 1 deletion boxes/boxes/vanilla/app/embedded-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ const LocalStorageKey = 'aztec-account';
export class EmbeddedWallet extends BaseWallet {
connectedAccount: AztecAddress | null = null;
protected accounts: Map<string, Account> = new Map();
private multiCallEntrypointAddress?: AztecAddress;

protected async getAccountFromAddress(
address: AztecAddress
): Promise<Account> {
let account: Account | undefined;
if (address.equals(AztecAddress.ZERO)) {
account = new SignerlessAccount();
if (!this.multiCallEntrypointAddress) {
throw new Error(
'multiCallEntrypointAddress is required for signerless accounts'
);
}
account = new SignerlessAccount(this.multiCallEntrypointAddress);
} else {
account = this.accounts.get(address?.toString() ?? '');
}
Expand Down
8 changes: 4 additions & 4 deletions docs/docs-developers/docs/foundational-topics/call_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ It is also possible to create public functions that can _only_ be invoked by pri

A common pattern is to enqueue public calls to check some validity condition on public state, e.g. that a deadline has not expired or that some public value is set.

#include_code enqueueing /noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/utils.nr rust
#include_code enqueueing /noir-projects/noir-contracts/contracts/app/public_checks_contract/src/utils.nr rust

Note that this reveals what public function is being called on what contract, and perhaps more importantly which contract enqueued the call during private execution.
To prevent this you can enqueue a call to a public function using `self.enqueue_incognito` that behaves the same as `self.enqueue` but conceals the message sender.
Expand All @@ -145,19 +145,19 @@ An example of how a deadline can be checked using the `PublicChecks` contract fo

`privately_check_timestamp` and `privately_check_block_number` are helper functions around the call to the `PublicChecks` contract:

#include_code helper_public_checks_functions /noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/utils.nr rust
#include_code helper_public_checks_functions /noir-projects/noir-contracts/contracts/app/public_checks_contract/src/utils.nr rust

This is what the implementation of the check timestamp functionality looks like:

#include_code check_timestamp /noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/main.nr rust
#include_code check_timestamp /noir-projects/noir-contracts/contracts/app/public_checks_contract/src/main.nr rust

:::note
The `PublicChecks` contract is not part of the [aztec-nr repository](https://github.com/AztecProtocol/aztec-nr).
To add it as a dependency, point to the aztec-packages repository:

```toml
[dependencies]
public_checks = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "#include_aztec_version", directory = "noir-projects/noir-contracts/contracts/protocol/public_checks_contract" }
public_checks = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "#include_aztec_version", directory = "noir-projects/noir-contracts/contracts/app/public_checks_contract" }
```

:::
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ Not sure which network to use? Jump to our [Network Selection Guide](#network-se

| Contract Name | Ignition (Mainnet) | Testnet | Devnet |
|---------------|-------------------|---------|--------|
| **Instance Registry** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000002` | `0x0000000000000000000000000000000000000000000000000000000000000002` |
| **Class Registry** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000003` | `0x0000000000000000000000000000000000000000000000000000000000000003` |
| **MultiCall Entrypoint** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000004` | `0x0000000000000000000000000000000000000000000000000000000000000004` |
| **Fee Juice** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000005` | `0x0000000000000000000000000000000000000000000000000000000000000005` |
| **Fee Juice** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000001` | `0x0000000000000000000000000000000000000000000000000000000000000001` |
| **Class Registry** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000002` | `0x0000000000000000000000000000000000000000000000000000000000000002` |
| **Instance Registry** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000003` | `0x0000000000000000000000000000000000000000000000000000000000000003` |
| **Auth Registry** | N/A | `0x0000000000000000000000000000000000000000000000000000000000000004` | `0x0000000000000000000000000000000000000000000000000000000000000004` |
| **SponsoredFPC** | N/A | `0x1586f476995be97f07ebd415340a14be48dc28c6c661cc6bdddb80ae790caa4e` | `0x1586f476995be97f07ebd415340a14be48dc28c6c661cc6bdddb80ae790caa4e` |

## Governance Parameters
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ library Constants {
9_682_850_228_538_071_369_704_502_076_456_077_473_410_427_336_083_826_595_120_404_283_897_422_804_423;
uint256 internal constant EMPTY_EPOCH_OUT_HASH =
355_785_372_471_781_095_838_790_036_702_437_931_769_306_153_278_986_832_745_847_530_947_941_691_539;
uint256 internal constant FEE_JUICE_ADDRESS = 5;
uint256 internal constant FEE_JUICE_ADDRESS = 1;
uint256 internal constant BLS12_POINT_COMPRESSED_BYTES = 48;
uint256 internal constant ROOT_ROLLUP_PUBLIC_INPUTS_LENGTH = 111;
uint256 internal constant NUM_MSGS_PER_BASE_PARITY = 256;
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/noir-contracts/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ members = [
"contracts/protocol/contract_class_registry_contract",
"contracts/protocol/contract_instance_registry_contract",
"contracts/protocol/fee_juice_contract",
"contracts/protocol/multi_call_entrypoint_contract",
"contracts/protocol/public_checks_contract",
"contracts/app/multi_call_entrypoint_contract",
"contracts/app/public_checks_contract",
"contracts/protocol_interface/auth_registry_interface",
"contracts/protocol_interface/contract_instance_registry_interface",
"contracts/protocol_interface/fee_juice_interface",
Expand Down
9 changes: 9 additions & 0 deletions noir-projects/noir-contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Noir Contracts

A series of example aztec-nr smart contracts used in our end to end testing flow

### protocol_contracts.json

A list of protocol contract artifacts, formatted as `<crate_name>-<ContractName>`. This mirrors the Noir compiler's output naming convention for files in `target/`. Consumers split on `-` to get the contract name.

Consumed by:

- `yarn-project/protocol-contracts/src/scripts/generate_data.ts` — generates `protocol_contract_data.ts` (names, salts, addresses, derived addresses, protocol contracts list and hash)
- `yarn-project/aztec.js/src/scripts/generate_protocol_contract_types.ts` — generates TypeScript contract wrapper classes in `aztec.js/src/contract/protocol_contracts/`
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type = "contract"
[dependencies]
aztec = { path = "../../../../aztec-nr/aztec" }
token = { path = "../token_contract" }
public_checks = { path = "../../protocol/public_checks_contract" }
public_checks = { path = "../public_checks_contract" }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub struct Config {
pub subscription_recipient_address: AztecAddress,
pub subscription_price: u128,
pub fee_juice_limit_per_tx: Field,
pub public_checks_address: AztecAddress, // Address of the PublicChecks contract
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ pub contract AppSubscription {

// We check that the note is not expired. We do that via the public checks contract to conceal which contract
// is performing the check.
privately_check_block_number(Comparator.LT, *user_expiry_block_number, self.context);
privately_check_block_number(
Comparator.LT,
*user_expiry_block_number,
self.context,
config.public_checks_address,
);

payload.execute_calls(self.context, config.target_address);
}
Expand All @@ -120,6 +125,7 @@ pub contract AppSubscription {
subscription_token_address: AztecAddress,
subscription_price: u128,
fee_juice_limit_per_tx: Field,
public_checks_address: AztecAddress,
) {
self.storage.config.initialize(
Config {
Expand All @@ -128,6 +134,7 @@ pub contract AppSubscription {
subscription_token_address,
subscription_price,
fee_juice_limit_per_tx,
public_checks_address,
},
);
}
Expand Down Expand Up @@ -156,6 +163,7 @@ pub contract AppSubscription {
Comparator.GT,
expiry_block_number - SUBSCRIPTION_DURATION_IN_BLOCKS,
self.context,
config.public_checks_address,
);
// docs:start:owned_private_mutable_initialize
self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ type = "contract"
aztec = { path = "../../../../aztec-nr/aztec" }
uint_note = { path = "../../../../aztec-nr/uint-note" }
token = { path = "../token_contract" }
public_checks = { path = "../../protocol/public_checks_contract" }
public_checks = { path = "../public_checks_contract" }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pub struct Config {
pub donation_token: AztecAddress, // Token used for donations (e.g. DAI)
pub operator: AztecAddress, // Crowdfunding campaign operator
pub deadline: u64, // End of the crowdfunding campaign after which no more donations are accepted
pub public_checks_address: AztecAddress, // Address of the PublicChecks contract
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ pub contract Crowdfunding {
#[external("public")]
#[initializer]
// this-will-error:init-header-error
fn init(donation_token: AztecAddress, operator: AztecAddress, deadline: u64) {
self.storage.config.initialize(Config { donation_token, operator, deadline });
fn init(
donation_token: AztecAddress,
operator: AztecAddress,
deadline: u64,
public_checks_address: AztecAddress,
) {
self.storage.config.initialize(
Config { donation_token, operator, deadline, public_checks_address },
);
}

#[external("private")]
Expand All @@ -46,7 +53,12 @@ pub contract Crowdfunding {
// 1) Check that the deadline has not passed --> we do that via the public checks contract to conceal which contract
// is performing the check.
// docs:start:call-check-deadline
privately_check_timestamp(Comparator.LT, config.deadline, self.context);
privately_check_timestamp(
Comparator.LT,
config.deadline,
self.context,
config.public_checks_address,
);
// docs:end:call-check-deadline

// 2) Transfer the donation tokens from donor to this contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
//
// Pair this with SignerlessWallet to perform multiple actions before any account contracts are deployed (and without
// authentication).
//
// Note that this contract should not be grouped with protocol contracts as it is not part of the protocol. We keep
// it here for now as it allows us to use hardcoded address.
use aztec::macros::aztec;

#[aztec]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use aztec::macros::aztec;

/// The purpose of this contract is to perform a check in public without revealing what contract enqueued the public
/// call. This can be achieved by enqueueing an `incognito` public call.
///
/// Note that this contract should not be grouped with protocol contracts as it is not part of the protocol. We keep
/// it here for now as it allows us to use hardcoded address.
#[aztec]
pub contract PublicChecks {
use aztec::{macros::functions::{external, view}, utils::comparison::compare};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
use crate::PublicChecks;
use aztec::context::PrivateContext;
use aztec::protocol::constants::PUBLIC_CHECKS_ADDRESS;
use aztec::protocol::address::AztecAddress;

// docs:start:helper_public_checks_functions
/// Asserts that the current timestamp in the enqueued public call enqueued by `check_timestamp` satisfies
/// the `operation` with respect to the `value. Preserves privacy by performing the check via the public checks contract.
/// This conceals an address of the calling contract by setting `context.msg_sender` to the public checks contract address.
pub fn privately_check_timestamp(operation: u8, value: u64, context: &mut PrivateContext) {
PublicChecks::at(PUBLIC_CHECKS_ADDRESS)
pub fn privately_check_timestamp(
operation: u8,
value: u64,
context: &mut PrivateContext,
public_checks_address: AztecAddress,
) {
PublicChecks::at(public_checks_address)
.check_timestamp(operation, value)
.enqueue_view_incognito(context);
}

/// Asserts that the current block number in the enqueued public call enqueued by `check_block_number` satisfies
/// the `operation` with respect to the `value. Preserves privacy by performing the check via the public checks contract.
/// This conceals an address of the calling contract by setting `context.msg_sender` to the public checks contract address.
pub fn privately_check_block_number(operation: u8, value: u32, context: &mut PrivateContext) {
pub fn privately_check_block_number(
operation: u8,
value: u32,
context: &mut PrivateContext,
public_checks_address: AztecAddress,
) {
// docs:start:enqueueing
PublicChecks::at(PUBLIC_CHECKS_ADDRESS)
PublicChecks::at(public_checks_address)
.check_block_number(operation, value)
.enqueue_view_incognito(context);
// docs:end:enqueueing
Expand Down
8 changes: 3 additions & 5 deletions noir-projects/noir-contracts/protocol_contracts.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[
"auth_registry_contract-AuthRegistry",
"contract_instance_registry_contract-ContractInstanceRegistry",
"contract_class_registry_contract-ContractClassRegistry",
"multi_call_entrypoint_contract-MultiCallEntrypoint",
"fee_juice_contract-FeeJuice",
"public_checks_contract-PublicChecks"
"contract_class_registry_contract-ContractClassRegistry",
"contract_instance_registry_contract-ContractInstanceRegistry",
"auth_registry_contract-AuthRegistry"
]
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,10 @@ pub global CONTRACT_INSTANCE_UPDATED_MAGIC_VALUE: Field =
// Chosen to be a multiple of 3 (-1 to account for the separator), to optimize the poseidon2 hash.
pub global MAX_PROTOCOL_CONTRACTS: u32 = 11;
// Address 0 is not a protocol contract.
pub global CANONICAL_AUTH_REGISTRY_ADDRESS: AztecAddress = AztecAddress::from_field(1);
pub global CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS: AztecAddress = AztecAddress::from_field(2);
pub global CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS: AztecAddress = AztecAddress::from_field(3);
pub global MULTI_CALL_ENTRYPOINT_ADDRESS: AztecAddress = AztecAddress::from_field(4);
pub global FEE_JUICE_ADDRESS: AztecAddress = AztecAddress::from_field(5);
pub global PUBLIC_CHECKS_ADDRESS: AztecAddress = AztecAddress::from_field(6);
pub global FEE_JUICE_ADDRESS: AztecAddress = AztecAddress::from_field(1);
pub global CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS: AztecAddress = AztecAddress::from_field(2);
pub global CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS: AztecAddress = AztecAddress::from_field(3);
pub global CANONICAL_AUTH_REGISTRY_ADDRESS: AztecAddress = AztecAddress::from_field(4);

// `SIDE_EFFECT_MASKING_ADDRESS` is used by the protocol circuits to silo the padding side effects. It's not a protocol
// contract (hence its address is greater than `MAX_PROTOCOL_CONTRACTS`).
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,10 +1243,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {

public getProtocolContractAddresses(): Promise<ProtocolContractAddresses> {
return Promise.resolve({
classRegistry: ProtocolContractAddress.ContractClassRegistry,
feeJuice: ProtocolContractAddress.FeeJuice,
classRegistry: ProtocolContractAddress.ContractClassRegistry,
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint,
authRegistry: ProtocolContractAddress.AuthRegistry,
});
}

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/account/signerless_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
import type { Account } from './account.js';

/**
* Account implementation which creates a transaction using the multicall protocol contract as entrypoint.
* Account implementation which creates a transaction using a deployed MultiCallEntrypoint contract as entrypoint.
*/
export class SignerlessAccount implements Account {
private entrypoint: EntrypointInterface;

constructor() {
this.entrypoint = new DefaultMultiCallEntrypoint();
constructor(multiCallEntrypointAddress: AztecAddress) {
this.entrypoint = new DefaultMultiCallEntrypoint(multiCallEntrypointAddress);
}

createTxExecutionRequest(
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/aztec.js/src/api/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ export { AuthRegistryContract } from '../contract/protocol_contracts/auth-regist
export { ContractClassRegistryContract } from '../contract/protocol_contracts/contract-class-registry.js';
export { ContractInstanceRegistryContract } from '../contract/protocol_contracts/contract-instance-registry.js';
export { FeeJuiceContract } from '../contract/protocol_contracts/fee-juice.js';
export { MultiCallEntrypointContract } from '../contract/protocol_contracts/multi-call-entrypoint.js';
export { PublicChecksContract } from '../contract/protocol_contracts/public-checks.js';
Loading
Loading