From 971867b5b806186466099e598740fffb78ceabe3 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 9 Apr 2024 08:13:09 +0000 Subject: [PATCH] fix: set side effect hwm in child private calls --- noir-projects/aztec-nr/authwit/src/account.nr | 6 ++++-- noir-projects/aztec-nr/aztec/src/context.nr | 1 + .../aztec-nr/aztec/src/context/private_context.nr | 15 +-------------- noir-projects/aztec-nr/aztec/src/context/utils.nr | 3 +++ .../src/sequencer/public_processor.ts | 5 +++++ .../src/sequencer/setup_phase_manager.ts | 2 ++ 6 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 noir-projects/aztec-nr/aztec/src/context/utils.nr diff --git a/noir-projects/aztec-nr/authwit/src/account.nr b/noir-projects/aztec-nr/authwit/src/account.nr index 0bc16963e252..a293dcd5f233 100644 --- a/noir-projects/aztec-nr/authwit/src/account.nr +++ b/noir-projects/aztec-nr/authwit/src/account.nr @@ -77,13 +77,15 @@ impl AccountActions { let fee_hash = fee_payload.hash(); assert(valid_fn(private_context, fee_hash)); fee_payload.execute_calls(private_context); + + dep::aztec::oracle::debug_log::debug_log("About to capture min revertible side effect counter"); 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(); - // The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can + // The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can // consume the message. // This ensures that contracts cannot consume messages that are not intended for them. let message_hash = compute_outer_authwit_hash( @@ -102,7 +104,7 @@ impl AccountActions { // docs:start:spend_public_authwit pub fn spend_public_authwit(self, inner_hash: Field) -> Field { let context = self.context.public.unwrap(); - // The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can + // The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can // consume the message. // This ensures that contracts cannot consume messages that are not intended for them. let message_hash = compute_outer_authwit_hash( diff --git a/noir-projects/aztec-nr/aztec/src/context.nr b/noir-projects/aztec-nr/aztec/src/context.nr index eb4e66512c5e..90185ea2fa69 100644 --- a/noir-projects/aztec-nr/aztec/src/context.nr +++ b/noir-projects/aztec-nr/aztec/src/context.nr @@ -6,6 +6,7 @@ mod public_context; mod avm_context; mod interface; mod gas; +mod utils; use interface::ContextInterface; use private_context::PrivateContext; 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 c3ec9a756044..fdf6bf224d32 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -347,18 +347,7 @@ impl PrivateContext { 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; - // TODO (fees) figure out why this crashes the prover and enable it - // we need this in order to pay fees inside child call contexts - // assert( - // (item.public_inputs.min_revertible_side_effect_counter == 0 as u32) - // | (item.public_inputs.min_revertible_side_effect_counter - // > self.min_revertible_side_effect_counter) - // ); - - // if item.public_inputs.min_revertible_side_effect_counter - // > self.min_revertible_side_effect_counter { - // self.min_revertible_side_effect_counter = item.public_inputs.min_revertible_side_effect_counter; - // } + self.min_revertible_side_effect_counter = crate::context::utils::max(item.public_inputs.min_revertible_side_effect_counter, self.min_revertible_side_effect_counter); assert(contract_address.eq(item.contract_address)); assert(function_selector.eq(item.function_data.selector)); @@ -383,8 +372,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()); item.public_inputs.return_values diff --git a/noir-projects/aztec-nr/aztec/src/context/utils.nr b/noir-projects/aztec-nr/aztec/src/context/utils.nr new file mode 100644 index 000000000000..8bc7b0b5524c --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/context/utils.nr @@ -0,0 +1,3 @@ +pub fn max(a: u32, b: u32) -> u32 { + if a > b { a } else { b } +} diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.ts index 132b69d476f0..0ac7efe749f8 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.ts @@ -151,6 +151,11 @@ export class PublicProcessor { private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, ProcessReturnValues | undefined]> { let returnValues: ProcessReturnValues = undefined; + this.log( + `tx=${tx.getTxHash().toString()} needs setup=${tx.data.forPublic?.needsSetup} needs app=${ + tx.data.forPublic?.needsAppLogic + } needs teardown=${tx.data.forPublic?.needsTeardown}`, + ); let phase: AbstractPhaseManager | undefined = PhaseManagerFactory.phaseFromTx( tx, this.db, diff --git a/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.ts b/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.ts index a043cfdd47b6..40e860103da8 100644 --- a/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.ts +++ b/yarn-project/sequencer-client/src/sequencer/setup_phase_manager.ts @@ -35,10 +35,12 @@ export class SetupPhaseManager extends AbstractPhaseManager { previousPublicKernelProof: Proof, ) { this.log.verbose(`Processing tx ${tx.getTxHash()}`); + await this.publicContractsDB.addNewContracts(tx); const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] = await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch( // the abstract phase manager throws if simulation gives error in a non-revertible phase async err => { + await this.publicContractsDB.removeNewContracts(tx); await this.publicStateDB.rollbackToCommit(); throw err; },