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 9, 2024
1 parent 18350f2 commit 31d58d1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 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
22 changes: 16 additions & 6 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ impl PrivateContext {

pub fn capture_min_revertible_side_effect_counter(&mut self) {
self.min_revertible_side_effect_counter = self.side_effect_counter;
crate::oracle::debug_log::debug_log_format(
"Captured min revertible counter {0}",
[self.min_revertible_side_effect_counter as Field]
);
}

// docs:start:max-block-number
Expand Down Expand Up @@ -347,18 +351,24 @@ 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;

let min_revertible_side_effect_counter = item.public_inputs.min_revertible_side_effect_counter;

// 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
// (min_revertible_side_effect_counter == 0 as u32)
// | (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;
// }
if min_revertible_side_effect_counter > self.min_revertible_side_effect_counter {
self.min_revertible_side_effect_counter = min_revertible_side_effect_counter;

crate::oracle::debug_log::debug_log_format(
"Updated min revertible counter to {0}",
[self.min_revertible_side_effect_counter as Field]
);
}

assert(contract_address.eq(item.contract_address));
assert(function_selector.eq(item.function_data.selector));
Expand Down
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,13 @@ export class SetupPhaseManager extends AbstractPhaseManager {
previousPublicKernelProof: Proof,
) {
this.log(`Processing tx ${tx.getTxHash()}`);
// fix for #5614
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 31d58d1

Please sign in to comment.