Skip to content

Commit

Permalink
fix: set side effect hwm in child private calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Apr 10, 2024
1 parent 9535bd2 commit 7135942
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 4 additions & 2 deletions noir-projects/aztec-nr/authwit/src/account.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions noir-projects/aztec-nr/aztec/src/context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod public_context;
mod avm_context;
mod interface;
mod gas;
mod utils;

use interface::ContextInterface;
use private_context::PrivateContext;
Expand Down
15 changes: 1 addition & 14 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions noir-projects/aztec-nr/aztec/src/context/utils.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn max(a: u32, b: u32) -> u32 {
if a > b { a } else { b }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down

0 comments on commit 7135942

Please sign in to comment.