From 9aaf3900d493d5c1637e15875935c9378df524de Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 28 Feb 2024 10:25:33 -0300 Subject: [PATCH 01/10] feat: Check initializer by default in private functions --- .../app_subscription_contract/src/main.nr | 1 + .../contracts/counter_contract/src/main.nr | 1 + .../easy_private_token_contract/src/main.nr | 1 + .../easy_private_voting_contract/src/main.nr | 3 ++- .../contracts/ecdsa_account_contract/src/main.nr | 1 + .../contracts/escrow_contract/src/main.nr | 1 + .../contracts/fpc_contract/src/main.nr | 1 + .../contracts/import_test_contract/src/main.nr | 1 + .../inclusion_proofs_contract/src/main.nr | 1 + .../contracts/lending_contract/src/main.nr | 1 + .../schnorr_account_contract/src/main.nr | 1 + .../contracts/stateful_test_contract/src/main.nr | 3 ++- .../contracts/test_contract/src/main.nr | 2 ++ .../token_blacklist_contract/src/main.nr | 1 + .../contracts/token_bridge_contract/src/main.nr | 1 + .../contracts/token_contract/src/main.nr | 1 + noir/noir-repo/aztec_macros/src/lib.rs | 16 ++++++++++------ 17 files changed, 29 insertions(+), 8 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index fb2eaf7c4fd..740dab33bc5 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -35,6 +35,7 @@ contract AppSubscription { // Constructs the contract #[aztec(private)] + #[aztec(initializer)] fn constructor( target_address: AztecAddress, subscription_recipient_address: AztecAddress, diff --git a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr index a7ad7b4888e..7782c5c3bf8 100644 --- a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr @@ -17,6 +17,7 @@ contract Counter { // docs:start:constructor #[aztec(private)] + #[aztec(initializer)] fn constructor(headstart: u64, owner: AztecAddress) { let counters = storage.counters; counters.at(owner).add(headstart, owner); diff --git a/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr index 513026f3360..0acb8c4e028 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_token_contract/src/main.nr @@ -13,6 +13,7 @@ contract EasyPrivateToken { * initialize the contract's initial state variables. */ #[aztec(private)] + #[aztec(initializer)] fn constructor(initial_supply: u64, owner: AztecAddress) { let balances = storage.balances; diff --git a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr index a6a388e6459..5a25136195d 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr @@ -14,7 +14,8 @@ contract EasyPrivateVoting { // docs:end:storage_struct // docs:start:constructor - #[aztec(private)] // annotation to mark function as private and expose private context + #[aztec(private)] + #[aztec(initializer)] // annotation to mark function as private and expose private context fn constructor(admin: AztecAddress) { // called when contract is deployed context.call_public_function( // we cannot update public state directly from private function but we can call public function (which queues it) diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr index e741663b5df..3ab9a2edfcd 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr @@ -26,6 +26,7 @@ contract EcdsaAccount { // Creates a new account out of an ECDSA public key to use for signature verification #[aztec(private)] + #[aztec(initializer)] fn constructor(signing_pub_key_x: pub [u8; 32], signing_pub_key_y: pub [u8; 32]) { let this = context.this_address(); let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this); diff --git a/noir-projects/noir-contracts/contracts/escrow_contract/src/main.nr b/noir-projects/noir-contracts/contracts/escrow_contract/src/main.nr index f1fde13f770..db9c51eab85 100644 --- a/noir-projects/noir-contracts/contracts/escrow_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/escrow_contract/src/main.nr @@ -19,6 +19,7 @@ contract Escrow { // Creates a new instance // docs:start:constructor #[aztec(private)] + #[aztec(initializer)] fn constructor(owner: pub AztecAddress) { let this = context.this_address(); diff --git a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr index 51b0ba3850a..5bc8535adc4 100644 --- a/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr @@ -12,6 +12,7 @@ contract FPC { } #[aztec(private)] + #[aztec(initializer)] fn constructor(other_asset: AztecAddress, fee_asset: AztecAddress) { let selector = FunctionSelector::from_signature("_initialize((Field),(Field))"); context.call_public_function( diff --git a/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr index c7ff4fa3a4a..180522176a1 100644 --- a/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr @@ -11,6 +11,7 @@ contract ImportTest { }; #[aztec(private)] + #[aztec(initializer)] fn constructor( ) {} diff --git a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr index 95385adc294..9e244aecdca 100644 --- a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr @@ -34,6 +34,7 @@ contract InclusionProofs { } #[aztec(private)] + #[aztec(initializer)] fn constructor(public_value: Field) { let selector = FunctionSelector::from_signature("_initialize(Field)"); context.call_public_function(context.this_address(), selector, [public_value]); diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr index bc039a499be..7a6e6d1376c 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/main.nr @@ -36,6 +36,7 @@ contract Lending { // Constructs the contract. #[aztec(private)] + #[aztec(initializer)] fn constructor( ) {} diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr index e7e4ebdafa0..5717762a7c1 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr @@ -29,6 +29,7 @@ contract SchnorrAccount { // Constructs the contract #[aztec(private)] + #[aztec(initializer)] fn constructor(signing_pub_key_x: pub Field, signing_pub_key_y: pub Field) { let this = context.this_address(); // docs:start:initialize diff --git a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr index d0738221169..ed0b66ee923 100644 --- a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr @@ -25,7 +25,6 @@ contract StatefulTest { } #[aztec(private)] - #[aztec(initcheck)] fn create_note(owner: AztecAddress, value: Field) { if (value != 0) { let loc = storage.notes.at(owner); @@ -34,6 +33,7 @@ contract StatefulTest { } #[aztec(private)] + #[aztec(noinitcheck)] fn create_note_no_init_check(owner: AztecAddress, value: Field) { if (value != 0) { let loc = storage.notes.at(owner); @@ -54,6 +54,7 @@ contract StatefulTest { } #[aztec(private)] + #[aztec(noinitcheck)] fn destroy_and_create_no_init_check(recipient: AztecAddress, amount: Field) { let sender = context.msg_sender(); diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 1436bc95a6e..efa7f436a35 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -36,6 +36,7 @@ contract Test { } #[aztec(private)] + #[aztec(initializer)] // docs:start:empty-constructor fn constructor() {} // docs:end:empty-constructor @@ -227,6 +228,7 @@ contract Test { // Forcefully emits a nullifier (for testing purposes) #[aztec(private)] + #[aztec(noinitcheck)] fn emit_nullifier(nullifier: Field) { context.push_new_nullifier(nullifier, 0); } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index 665de878c4c..34928ebc3d9 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -42,6 +42,7 @@ contract TokenBlacklist { // docs:start:constructor #[aztec(private)] + #[aztec(initializer)] fn constructor(admin: AztecAddress, slow_updates_contract: AztecAddress) { // docs:end:constructor let selector = FunctionSelector::from_signature("_initialize((Field),(Field))"); diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr index ef0322c8ba2..352d86e1980 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr @@ -24,6 +24,7 @@ contract TokenBridge { // Constructs the contract. #[aztec(private)] + #[aztec(initializer)] fn constructor(token: AztecAddress) { let selector = FunctionSelector::from_signature("_initialize((Field))"); context.call_public_function(context.this_address(), selector, [token.to_field()]); diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index 7a20030245a..b1a37a66a77 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -54,6 +54,7 @@ contract Token { // docs:start:constructor #[aztec(private)] + #[aztec(initializer)] fn constructor(admin: AztecAddress, name: str<31>, symbol: str<31>, decimals: u8) { let selector = FunctionSelector::from_signature("_initialize((Field),(Field),(Field),u8)"); let name_s = FieldCompressedString::from_string(name); diff --git a/noir/noir-repo/aztec_macros/src/lib.rs b/noir/noir-repo/aztec_macros/src/lib.rs index 2516b380ff6..a2b0fecdcb2 100644 --- a/noir/noir-repo/aztec_macros/src/lib.rs +++ b/noir/noir-repo/aztec_macros/src/lib.rs @@ -435,22 +435,26 @@ fn transform_module( } } + let has_initializer = module.functions.iter().any(|func| func.def.attributes.secondary.iter().any(|attr| is_custom_attribute(&attr, "aztec(initializer)"))); + for func in module.functions.iter_mut() { let mut is_private = false; let mut is_public = false; let mut is_public_vm = false; let mut is_initializer = false; - let mut skip_init_check = true; // Default to true once we're confident that the approach works + let mut insert_init_check = has_initializer; for secondary_attribute in func.def.attributes.secondary.clone() { if is_custom_attribute(&secondary_attribute, "aztec(private)") { is_private = true; } else if is_custom_attribute(&secondary_attribute, "aztec(initializer)") { is_initializer = true; - } else if is_custom_attribute(&secondary_attribute, "aztec(initcheck)") { - skip_init_check = false; + insert_init_check = false; + } else if is_custom_attribute(&secondary_attribute, "aztec(noinitcheck)") { + insert_init_check = false; } else if is_custom_attribute(&secondary_attribute, "aztec(public)") { is_public = true; + insert_init_check = false; } else if is_custom_attribute(&secondary_attribute, "aztec(public-vm)") { is_public_vm = true; } @@ -463,7 +467,7 @@ fn transform_module( func, storage_defined, is_initializer, - skip_init_check, + insert_init_check, ) .map_err(|err| (err, crate_graph.root_file_id))?; has_transformed_module = true; @@ -655,14 +659,14 @@ fn transform_function( func: &mut NoirFunction, storage_defined: bool, is_initializer: bool, - skip_init_check: bool, + insert_init_check: bool, ) -> Result<(), AztecMacroError> { let context_name = format!("{}Context", ty); let inputs_name = format!("{}ContextInputs", ty); let return_type_name = format!("{}CircuitPublicInputs", ty); // Add initialization check - if !skip_init_check { + if insert_init_check { if ty == "Public" { let error = AztecMacroError::UnsupportedAttributes { span: func.def.name.span(), From cfbe794de406d020bdfa8047fcf3b3ca28abf802 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 29 Feb 2024 15:13:24 -0300 Subject: [PATCH 02/10] Fix e2e_deploy test --- yarn-project/end-to-end/src/e2e_deploy_contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index beba774f639..cabdcacd7f9 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -365,8 +365,8 @@ describe('e2e_deploy_contract', () => { testDeployingAnInstance('from a contract', async instance => { // Register the instance to be deployed in the pxe await wallet.addContracts([{ artifact, instance }]); - // Set up the contract that calls the deployer (which happens to be the StatefulTestContract) and call it - const deployer = await registerContract(wallet, TestContract, [accounts[0].address, 48]); + // Set up the contract that calls the deployer (which happens to be the TestContract) and call it + const deployer = await TestContract.deploy(wallet).send().deployed(); await deployer.methods.deploy_contract(instance.address).send().wait(); }); }); From 44cc02db57d781d5fdb1fc68d0c7f5d42fd92890 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 29 Feb 2024 15:13:30 -0300 Subject: [PATCH 03/10] Better logging --- yarn-project/simulator/src/client/private_execution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/simulator/src/client/private_execution.ts b/yarn-project/simulator/src/client/private_execution.ts index df3fb12a848..1abdd7136f6 100644 --- a/yarn-project/simulator/src/client/private_execution.ts +++ b/yarn-project/simulator/src/client/private_execution.ts @@ -23,7 +23,7 @@ export async function executePrivateFunction( log = createDebugLogger('aztec:simulator:secret_execution'), ): Promise { const functionSelector = functionData.selector; - log(`Executing external function ${contractAddress}:${functionSelector}`); + log(`Executing external function ${contractAddress}:${functionSelector}(${artifact.name})`); const acir = Buffer.from(artifact.bytecode, 'base64'); const initialWitness = context.getInitialWitness(artifact); const acvmCallback = new Oracle(context); From a62055e1e2307fef01ac10a8426118e175f27dd5 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 29 Feb 2024 15:13:40 -0300 Subject: [PATCH 04/10] Fix missing serialization --- .../src/aztec_node/rpc/aztec_node_client.ts | 3 ++- .../src/interfaces/nullifier_tree.ts | 16 ++++++++++++++++ .../src/structs/rollup/nullifier_leaf/index.ts | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts index 4996f784d5a..9771db9a032 100644 --- a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts +++ b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts @@ -7,6 +7,7 @@ import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/cl import { ContractData, ExtendedContractData } from '../../contract_data.js'; import { AztecNode } from '../../interfaces/aztec-node.js'; +import { NullifierMembershipWitness } from '../../interfaces/nullifier_tree.js'; import { L1ToL2MessageAndIndex } from '../../l1_to_l2_message.js'; import { L2Block } from '../../l2_block.js'; import { ExtendedUnencryptedL2Log, L2BlockL2Logs, LogId } from '../../logs/index.js'; @@ -40,7 +41,7 @@ export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecN SiblingPath, L1ToL2MessageAndIndex, }, - { Tx, TxReceipt, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs, NullifierMembershipWitness }, false, 'node', fetch, diff --git a/yarn-project/circuit-types/src/interfaces/nullifier_tree.ts b/yarn-project/circuit-types/src/interfaces/nullifier_tree.ts index ee33fd07cba..a3a1bd1a8d1 100644 --- a/yarn-project/circuit-types/src/interfaces/nullifier_tree.ts +++ b/yarn-project/circuit-types/src/interfaces/nullifier_tree.ts @@ -31,4 +31,20 @@ export class NullifierMembershipWitness { public toFields(): Fr[] { return [new Fr(this.index), ...this.leafPreimage.toFields(), ...this.siblingPath.toFields()]; } + + public toJSON() { + return { + index: '0x' + this.index.toString(16), + leafPreimage: this.leafPreimage.toJSON(), + siblingPath: this.siblingPath.toString(), + }; + } + + static fromJSON(json: any): NullifierMembershipWitness { + return new NullifierMembershipWitness( + BigInt(json.index), + NullifierLeafPreimage.fromJSON(json.leafPreimage), + SiblingPath.fromString(json.siblingPath), + ); + } } diff --git a/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts b/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts index 14f7cf5e2b7..149ab6c0014 100644 --- a/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts +++ b/yarn-project/circuits.js/src/structs/rollup/nullifier_leaf/index.ts @@ -59,6 +59,14 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage { return new NullifierLeafPreimage(this.nullifier, this.nextNullifier, this.nextIndex); } + toJSON() { + return { + nullifier: this.nullifier.toString(), + nextNullifier: this.nextNullifier.toString(), + nextIndex: '0x' + this.nextIndex.toString(16), + }; + } + static empty(): NullifierLeafPreimage { return new NullifierLeafPreimage(Fr.ZERO, Fr.ZERO, 0n); } @@ -75,6 +83,14 @@ export class NullifierLeafPreimage implements IndexedTreeLeafPreimage { static clone(preimage: NullifierLeafPreimage): NullifierLeafPreimage { return new NullifierLeafPreimage(preimage.nullifier, preimage.nextNullifier, preimage.nextIndex); } + + static fromJSON(json: any): NullifierLeafPreimage { + return new NullifierLeafPreimage( + Fr.fromString(json.nullifier), + Fr.fromString(json.nextNullifier), + BigInt(json.nextIndex), + ); + } } /** From 7433a93d3e906a0103674f98699a1de382f1edf9 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 29 Feb 2024 17:37:19 -0300 Subject: [PATCH 05/10] Skip test --- yarn-project/simulator/src/client/private_execution.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index c97d08acb7c..d06e0bbda9a 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -762,7 +762,10 @@ describe('Private Execution test suite', () => { }); }); - it('Should be able to consume a dummy public to private message', async () => { + // TODO(@spalladino): Reenable this test by migrating the redeem_shield to the test contract and removing the init check. + // Doing so is currently triggering a noir compiler error that I need to dig further into, so I'm skipping the test for now. + // 'internal error: entered unreachable code: TypeVariable::bind, cannot bind bound var 3 to 1' + it.skip('Should be able to consume a dummy public to private message', async () => { const amount = 100n; const artifact = getFunctionArtifact(TokenContractArtifact, 'redeem_shield'); From 95be9f8e5746fb056f76a62d9334658d38c542fc Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 29 Feb 2024 17:54:25 -0300 Subject: [PATCH 06/10] Format --- noir/noir-repo/aztec_macros/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/noir/noir-repo/aztec_macros/src/lib.rs b/noir/noir-repo/aztec_macros/src/lib.rs index a2b0fecdcb2..6191108de86 100644 --- a/noir/noir-repo/aztec_macros/src/lib.rs +++ b/noir/noir-repo/aztec_macros/src/lib.rs @@ -435,7 +435,13 @@ fn transform_module( } } - let has_initializer = module.functions.iter().any(|func| func.def.attributes.secondary.iter().any(|attr| is_custom_attribute(&attr, "aztec(initializer)"))); + let has_initializer = module.functions.iter().any(|func| { + func.def + .attributes + .secondary + .iter() + .any(|attr| is_custom_attribute(&attr, "aztec(initializer)")) + }); for func in module.functions.iter_mut() { let mut is_private = false; From 07e8818f1101ab7a6fb1b3a8497c27fdb7fa7476 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 29 Feb 2024 17:57:12 -0300 Subject: [PATCH 07/10] Remove initializer attr for empty ctor --- .../noir-contracts/contracts/import_test_contract/src/main.nr | 2 +- .../noir-contracts/contracts/test_contract/src/main.nr | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr index 180522176a1..e575b117ae9 100644 --- a/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/import_test_contract/src/main.nr @@ -10,8 +10,8 @@ contract ImportTest { ManyNotesADeepStructTestCodeGenStruct }; + // TODO(@spalladino): Delete all empty constructors #[aztec(private)] - #[aztec(initializer)] fn constructor( ) {} diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index efa7f436a35..af2dd1bd27d 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -35,8 +35,8 @@ contract Test { example_constant: PrivateImmutable, } + // TODO(@spalladino): Delete all empty constructors #[aztec(private)] - #[aztec(initializer)] // docs:start:empty-constructor fn constructor() {} // docs:end:empty-constructor @@ -228,7 +228,6 @@ contract Test { // Forcefully emits a nullifier (for testing purposes) #[aztec(private)] - #[aztec(noinitcheck)] fn emit_nullifier(nullifier: Field) { context.push_new_nullifier(nullifier, 0); } From 4ebe2e6f4142aefcf54f5491e0f48e00996ba4ea Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 29 Feb 2024 17:59:36 -0300 Subject: [PATCH 08/10] Reenable test on simulator private-execution --- .../contracts/test_contract/src/main.nr | 17 +++++++++-- .../src/client/private_execution.test.ts | 28 ++++--------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index af2dd1bd27d..771a301cbe7 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -11,7 +11,8 @@ contract Test { // docs:end:unencrypted_import use dep::aztec::{ - context::{Context, inputs::private_context_inputs::PrivateContextInputs}, hash::pedersen_hash, + context::{Context, inputs::private_context_inputs::PrivateContextInputs}, + hash::{pedersen_hash, compute_secret_hash}, context::PrivateContext, note::{ note_header::NoteHeader, utils as note_utils, lifecycle::{create_note, destroy_note}, @@ -20,7 +21,7 @@ contract Test { }, deploy::{deploy_contract as aztec_deploy_contract}, oracle::{get_public_key::get_public_key as get_public_key_oracle, context::get_portal_address, rand::rand}, - state_vars::PrivateImmutable, log::emit_unencrypted_log_from_private + state_vars::{PrivateImmutable, PrivateSet}, log::emit_unencrypted_log_from_private }; use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash}; use dep::field_note::field_note::FieldNote; @@ -33,6 +34,7 @@ contract Test { struct Storage { example_constant: PrivateImmutable, + example_set: PrivateSet, } // TODO(@spalladino): Delete all empty constructors @@ -351,6 +353,17 @@ contract Test { aztec_deploy_contract(&mut context, target); } + #[aztec(private)] + // Adapted from TokenContract#redeem_shield but without an initcheck so it can be run in simulator/src/client/private_execution.test.ts + fn consume_note_from_secret(secret: Field) { + let notes_set = storage.example_set; + let secret_hash = compute_secret_hash(secret); + let options = NoteGetterOptions::new().select(0, secret_hash, Option::none()).set_limit(1); + let notes = notes_set.get_notes(options); + let note = notes[0].unwrap_unchecked(); + notes_set.remove(note); + } + unconstrained fn get_constant() -> pub Field { let constant = storage.example_constant.view_note(); constant.value diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index d06e0bbda9a..e41a9aac433 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -19,12 +19,7 @@ import { nonEmptySideEffects, sideEffectArrayToValueArray, } from '@aztec/circuits.js'; -import { - computeCommitmentNonce, - computeMessageSecretHash, - computeVarArgsHash, - siloNoteHash, -} from '@aztec/circuits.js/hash'; +import { computeCommitmentNonce, computeMessageSecretHash, computeVarArgsHash } from '@aztec/circuits.js/hash'; import { makeContractDeploymentData, makeHeader } from '@aztec/circuits.js/testing'; import { FunctionArtifact, @@ -50,7 +45,6 @@ import { PendingNoteHashesContractArtifact, StatefulTestContractArtifact, TestContractArtifact, - TokenContractArtifact, } from '@aztec/noir-contracts.js'; import { jest } from '@jest/globals'; @@ -762,20 +756,12 @@ describe('Private Execution test suite', () => { }); }); - // TODO(@spalladino): Reenable this test by migrating the redeem_shield to the test contract and removing the init check. - // Doing so is currently triggering a noir compiler error that I need to dig further into, so I'm skipping the test for now. - // 'internal error: entered unreachable code: TypeVariable::bind, cannot bind bound var 3 to 1' - it.skip('Should be able to consume a dummy public to private message', async () => { - const amount = 100n; - const artifact = getFunctionArtifact(TokenContractArtifact, 'redeem_shield'); - + it('Should be able to consume a dummy public to private message', async () => { + const artifact = getFunctionArtifact(TestContractArtifact, 'consume_note_from_secret'); const secret = new Fr(1n); const secretHash = computeMessageSecretHash(secret); - const note = new Note([new Fr(amount), secretHash]); - const noteHash = hashFields(note.items); + const note = new Note([secretHash]); const storageSlot = new Fr(5); - const innerNoteHash = hashFields([storageSlot, noteHash]); - const siloedNoteHash = siloNoteHash(contractAddress, innerNoteHash); oracle.getNotes.mockResolvedValue([ { contractAddress, @@ -788,10 +774,7 @@ describe('Private Execution test suite', () => { }, ]); - const result = await runSimulator({ - artifact, - args: [recipient, amount, secret], - }); + const result = await runSimulator({ artifact, args: [secret] }); // Check a nullifier has been inserted. const newNullifiers = sideEffectArrayToValueArray( @@ -806,7 +789,6 @@ describe('Private Execution test suite', () => { ); expect(readRequests).toHaveLength(1); - expect(readRequests[0]).toEqual(siloedNoteHash); }); }); From 1cf7989782b5ec528703906e4278c289fafbff4d Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 1 Mar 2024 14:36:40 -0300 Subject: [PATCH 09/10] Add missing serialization --- yarn-project/aztec.js/src/rpc_clients/pxe_client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts index ea873ab3ef0..60396d9c803 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -8,6 +8,7 @@ import { L2BlockL2Logs, LogId, Note, + NullifierMembershipWitness, PXE, Tx, TxEffect, @@ -55,7 +56,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false) TxExecutionRequest, TxHash, }, - { Tx, TxReceipt, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs, NullifierMembershipWitness }, false, 'pxe', fetch, From 2977dd26054e13a14260046f5eb9f7a45b9cecb3 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 1 Mar 2024 15:21:09 -0300 Subject: [PATCH 10/10] Fix serialization --- yarn-project/archiver/src/rpc/archiver_client.ts | 3 ++- yarn-project/archiver/src/rpc/archiver_server.ts | 3 ++- yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts | 3 ++- yarn-project/pxe/src/pxe_http/pxe_http_server.ts | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/yarn-project/archiver/src/rpc/archiver_client.ts b/yarn-project/archiver/src/rpc/archiver_client.ts index d6635fbdcad..cec9f21801f 100644 --- a/yarn-project/archiver/src/rpc/archiver_client.ts +++ b/yarn-project/archiver/src/rpc/archiver_client.ts @@ -6,6 +6,7 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, + NullifierMembershipWitness, TxReceipt, } from '@aztec/circuit-types'; import { EthAddress, Fr } from '@aztec/circuits.js'; @@ -27,7 +28,7 @@ export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], t L2Block, L2BlockL2Logs, }, - { TxReceipt }, + { TxReceipt, NullifierMembershipWitness }, false, 'archiver', fetch, diff --git a/yarn-project/archiver/src/rpc/archiver_server.ts b/yarn-project/archiver/src/rpc/archiver_server.ts index 48e7463cbc9..600a4316503 100644 --- a/yarn-project/archiver/src/rpc/archiver_server.ts +++ b/yarn-project/archiver/src/rpc/archiver_server.ts @@ -6,6 +6,7 @@ import { L1ToL2Message, L2Block, L2BlockL2Logs, + NullifierMembershipWitness, TxEffect, TxReceipt, } from '@aztec/circuit-types'; @@ -34,7 +35,7 @@ export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServe L2BlockL2Logs, TxEffect, }, - { TxReceipt }, + { TxReceipt, NullifierMembershipWitness }, ['start', 'stop'], ); } diff --git a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts index 213478e41d0..845d61b2916 100644 --- a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts @@ -7,6 +7,7 @@ import { L2Block, L2BlockL2Logs, LogId, + NullifierMembershipWitness, SiblingPath, Tx, TxEffect, @@ -43,7 +44,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { SiblingPath, L1ToL2MessageAndIndex, }, - { Tx, TxReceipt, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs, NullifierMembershipWitness }, // disable methods not part of the AztecNode interface ['start', 'stop'], ); diff --git a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts index 9e03421c649..8aa21824401 100644 --- a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts +++ b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts @@ -9,6 +9,7 @@ import { L2BlockL2Logs, LogId, Note, + NullifierMembershipWitness, PXE, Tx, TxEffect, @@ -51,7 +52,7 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer { TxEffect, LogId, }, - { Tx, TxReceipt, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs, NullifierMembershipWitness }, ['start', 'stop'], ); }