From f7a659e4eab2014fd16e6a64c94385324fd199bd Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 9 Apr 2024 07:30:15 +0000 Subject: [PATCH] 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 c3ec9a75604..c393581fc27 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -185,6 +185,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 } @@ -199,6 +205,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; @@ -343,6 +355,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 a8c96b6887f..e23b3ed1c54 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 3f626293121..f4ee5876f48 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -396,6 +396,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; }