From 991fc4a8c139c584e37c061b25f60f31878e7ab7 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 9 Apr 2024 07:30:15 +0000 Subject: [PATCH 1/4] fix: use entrypoint instead of pay_init_fee --- .../aztec/src/context/private_context.nr | 31 +++++++++++++++++++ .../account_manager/deploy_account_method.ts | 5 ++- .../aztec.js/src/account_manager/index.ts | 2 +- .../src/client/client_execution_context.ts | 10 ++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 3c8398ffb61..bd0f6df948e 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -189,6 +189,12 @@ impl PrivateContext { chain_id: self.inputs.private_global_variables.chain_id, version: self.inputs.private_global_variables.version }; + + // crate::oracle::debug_log::debug_log_format( + // "Finished private context with {0} note hash read requests", + // [self.note_hash_read_requests.len() as Field] + // ); + priv_circuit_pub_inputs } @@ -203,6 +209,12 @@ impl PrivateContext { } pub fn push_note_hash_read_request(&mut self, note_hash: Field) { + // crate::oracle::debug_log::debug_log_format( + // "Pushing note hash read request for note_hash={0} counter={1} len={2}", + // [ + // note_hash, self.side_effect_counter as Field, (self.note_hash_read_requests.len() as Field) + 1 + // ] + // ); let side_effect = SideEffect { value: note_hash, counter: self.side_effect_counter }; self.note_hash_read_requests.push(side_effect); self.side_effect_counter = self.side_effect_counter + 1; @@ -347,6 +359,25 @@ impl PrivateContext { is_delegate_call ); + let mut note_hash_read_req_count = 0; + for i in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_CALL { + if !is_empty(item.public_inputs.note_hash_read_requests[i]) { + note_hash_read_req_count = note_hash_read_req_count + 1; + } + } + + // crate::oracle::debug_log::debug_log_format( + // "Called private function got back contract_address={0} function_data={1} public_inputs={2} note_hash_read_reqs={3}", + // [ + // item.contract_address.to_field(), item.function_data.hash(), item.public_inputs.hash(), note_hash_read_req_count + // ] + // ); + + // crate::oracle::debug_log::debug_log_array_with_prefix( + // "Called private function public inputs", + // item.public_inputs.serialize() + // ); + assert_eq(item.public_inputs.call_context.side_effect_counter, self.side_effect_counter); assert_eq(item.public_inputs.start_side_effect_counter, self.side_effect_counter); self.side_effect_counter = item.public_inputs.end_side_effect_counter + 1; diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 75a2c6bd0d1..0534790e935 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -51,18 +51,21 @@ export class DeployAccountMethod extends DeployMethod { if (options.fee && this.#feePaymentArtifact) { const { address } = this.getInstance(); + const emptyAppPayload = EntrypointPayload.fromAppExecution([]); const feePayload = await EntrypointPayload.fromFeeOptions(options?.fee); exec.calls.push({ to: address, - args: encodeArguments(this.#feePaymentArtifact, [feePayload]), + args: encodeArguments(this.#feePaymentArtifact, [emptyAppPayload, feePayload]), functionData: FunctionData.fromAbi(this.#feePaymentArtifact), }); exec.authWitnesses ??= []; exec.packedArguments ??= []; + exec.authWitnesses.push(await this.#authWitnessProvider.createAuthWit(emptyAppPayload.hash())); exec.authWitnesses.push(await this.#authWitnessProvider.createAuthWit(feePayload.hash())); + exec.packedArguments.push(...emptyAppPayload.packedArguments); exec.packedArguments.push(...feePayload.packedArguments); } diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index 43fb28a5b23..251e7d40bb3 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -148,7 +148,7 @@ export class AccountManager { this.accountContract.getContractArtifact(), args, 'constructor', - 'pay_init_fee', + 'entrypoint', ); } return this.deployMethod; diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 522966631ad..9c80b5134dd 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -413,6 +413,16 @@ export class ClientExecutionContext extends ViewDataOracle { this.nestedExecutions.push(childExecutionResult); + const ci = childExecutionResult.callStackItem; + this.log(`Called private function and got back call stack item with hashes: + Contract address=${ci.contractAddress.toString()} + Function data=${ci.functionData.hash().toString()} + Public inputs=${ci.publicInputs.hash().toString()} + Count of note hash read requests=${ci.publicInputs.noteHashReadRequests.filter(x => !x.isEmpty()).length} + `); + + // this.log(`Called private function public inputs: ${ci.publicInputs.toFields().map(f => f.toString())}`); + return childExecutionResult.callStackItem; } From 5b18189ebc069784784f5f8e1473319dea35598f Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 11 Apr 2024 18:40:06 -0300 Subject: [PATCH 2/4] Remove logs --- .../aztec/src/context/private_context.nr | 28 ++----------------- .../src/client/client_execution_context.ts | 10 ------- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index bd0f6df948e..257a204cf06 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -28,7 +28,8 @@ use dep::protocol_types::{ }, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, grumpkin_private_key::GrumpkinPrivateKey, header::Header, - messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, traits::{is_empty, Deserialize, Empty} + messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, + traits::{is_empty, Deserialize, Empty} }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) @@ -190,11 +191,6 @@ impl PrivateContext { version: self.inputs.private_global_variables.version }; - // crate::oracle::debug_log::debug_log_format( - // "Finished private context with {0} note hash read requests", - // [self.note_hash_read_requests.len() as Field] - // ); - priv_circuit_pub_inputs } @@ -209,12 +205,6 @@ impl PrivateContext { } pub fn push_note_hash_read_request(&mut self, note_hash: Field) { - // crate::oracle::debug_log::debug_log_format( - // "Pushing note hash read request for note_hash={0} counter={1} len={2}", - // [ - // note_hash, self.side_effect_counter as Field, (self.note_hash_read_requests.len() as Field) + 1 - // ] - // ); let side_effect = SideEffect { value: note_hash, counter: self.side_effect_counter }; self.note_hash_read_requests.push(side_effect); self.side_effect_counter = self.side_effect_counter + 1; @@ -366,18 +356,6 @@ impl PrivateContext { } } - // crate::oracle::debug_log::debug_log_format( - // "Called private function got back contract_address={0} function_data={1} public_inputs={2} note_hash_read_reqs={3}", - // [ - // item.contract_address.to_field(), item.function_data.hash(), item.public_inputs.hash(), note_hash_read_req_count - // ] - // ); - - // crate::oracle::debug_log::debug_log_array_with_prefix( - // "Called private function public inputs", - // item.public_inputs.serialize() - // ); - assert_eq(item.public_inputs.call_context.side_effect_counter, self.side_effect_counter); assert_eq(item.public_inputs.start_side_effect_counter, self.side_effect_counter); self.side_effect_counter = item.public_inputs.end_side_effect_counter + 1; @@ -418,8 +396,6 @@ impl PrivateContext { ); } - // crate::oracle::debug_log::debug_log_array_with_prefix("Private call stack item", item.serialize()); - self.private_call_stack_hashes.push(item.hash()); PackedReturns::new(item.public_inputs.returns_hash) diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 9c80b5134dd..522966631ad 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -413,16 +413,6 @@ export class ClientExecutionContext extends ViewDataOracle { this.nestedExecutions.push(childExecutionResult); - const ci = childExecutionResult.callStackItem; - this.log(`Called private function and got back call stack item with hashes: - Contract address=${ci.contractAddress.toString()} - Function data=${ci.functionData.hash().toString()} - Public inputs=${ci.publicInputs.hash().toString()} - Count of note hash read requests=${ci.publicInputs.noteHashReadRequests.filter(x => !x.isEmpty()).length} - `); - - // this.log(`Called private function public inputs: ${ci.publicInputs.toFields().map(f => f.toString())}`); - return childExecutionResult.callStackItem; } From 4c35bd8fb424ecb9d3ade3ca6e130e844c904c71 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 11 Apr 2024 18:41:17 -0300 Subject: [PATCH 3/4] Remove pay_init_fee method --- noir-projects/aztec-nr/authwit/src/account.nr | 10 ---------- .../contracts/ecdsa_account_contract/src/main.nr | 7 ------- .../contracts/schnorr_account_contract/src/main.nr | 11 ----------- .../schnorr_hardcoded_account_contract/src/main.nr | 6 ------ .../schnorr_single_key_account_contract/src/main.nr | 6 ------ 5 files changed, 40 deletions(-) diff --git a/noir-projects/aztec-nr/authwit/src/account.nr b/noir-projects/aztec-nr/authwit/src/account.nr index 0bc16963e25..2e33c4a0823 100644 --- a/noir-projects/aztec-nr/authwit/src/account.nr +++ b/noir-projects/aztec-nr/authwit/src/account.nr @@ -70,16 +70,6 @@ impl AccountActions { } // docs:end:entrypoint - pub fn pay_init_fee(self, fee_payload: FeePayload) { - let valid_fn = self.is_valid_impl; - let mut private_context = self.context.private.unwrap(); - - let fee_hash = fee_payload.hash(); - assert(valid_fn(private_context, fee_hash)); - fee_payload.execute_calls(private_context); - private_context.capture_min_revertible_side_effect_counter(); - } - // docs:start:spend_private_authwit pub fn spend_private_authwit(self, inner_hash: Field) -> Field { let context = self.context.private.unwrap(); 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 e0cd1cdaf90..30fb2737fc8 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 @@ -39,13 +39,6 @@ contract EcdsaAccount { actions.entrypoint(app_payload, fee_payload); } - #[aztec(private)] - #[aztec(noinitcheck)] - fn pay_init_fee(fee_payload: pub FeePayload) { - let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.pay_init_fee(fee_payload); - } - #[aztec(private)] #[aztec(noinitcheck)] fn spend_private_authwit(inner_hash: Field) -> Field { 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 f0b3f2c8ddd..1ec2152e7c3 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 @@ -48,17 +48,6 @@ contract SchnorrAccount { actions.entrypoint(app_payload, fee_payload); } - #[aztec(private)] - #[aztec(noinitcheck)] - fn pay_init_fee(fee_payload: pub FeePayload) { - let actions = AccountActions::private( - &mut context, - storage.approved_actions.storage_slot, - is_valid_impl - ); - actions.pay_init_fee(fee_payload); - } - #[aztec(private)] #[aztec(noinitcheck)] fn spend_private_authwit(inner_hash: Field) -> Field { diff --git a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr index 134a820b058..a660670a2a5 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr @@ -21,12 +21,6 @@ contract SchnorrHardcodedAccount { actions.entrypoint(app_payload, fee_payload); } - #[aztec(private)] - fn pay_init_fee(fee_payload: pub FeePayload) { - let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.pay_init_fee(fee_payload); - } - #[aztec(private)] fn spend_private_authwit(inner_hash: Field) -> Field { let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); diff --git a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr index 2a8678ce778..9803ed4f15e 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr @@ -17,12 +17,6 @@ contract SchnorrSingleKeyAccount { actions.entrypoint(app_payload, fee_payload); } - #[aztec(private)] - fn pay_init_fee(fee_payload: pub FeePayload) { - let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.pay_init_fee(fee_payload); - } - #[aztec(private)] fn spend_private_authwit(inner_hash: Field) -> Field { let actions = AccountActions::private(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); From f7741d9791e82ff9d34972c151c70bd8a7436974 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 12 Apr 2024 16:47:24 -0300 Subject: [PATCH 4/4] Remove variable used just for logging --- .../aztec-nr/aztec/src/context/private_context.nr | 7 ------- 1 file changed, 7 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 257a204cf06..48e4824521f 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -349,13 +349,6 @@ impl PrivateContext { is_delegate_call ); - let mut note_hash_read_req_count = 0; - for i in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_CALL { - if !is_empty(item.public_inputs.note_hash_read_requests[i]) { - note_hash_read_req_count = note_hash_read_req_count + 1; - } - } - assert_eq(item.public_inputs.call_context.side_effect_counter, self.side_effect_counter); assert_eq(item.public_inputs.start_side_effect_counter, self.side_effect_counter); self.side_effect_counter = item.public_inputs.end_side_effect_counter + 1;