Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Debug log oracle calls return nothing #6209

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ contract Counter {
// docs:start:increment
#[aztec(private)]
fn increment(owner: AztecAddress) {
dep::aztec::oracle::debug_log::debug_log_format("Incrementing counter for owner {0}", [owner.to_field()]);
let counters = storage.counters;
counters.at(owner).add(1, owner);
}
Expand Down
20 changes: 10 additions & 10 deletions noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
// WARNING: sometimes when using debug logs the ACVM errors with: `thrown: "solver opcode resolution error: cannot solve opcode: expression has too many unknowns x155"`

#[oracle(debugLog)]
fn debug_log_oracle<T, N>(_msg: T, _num_args: Field) -> Field {}
fn debug_log_oracle<T, N>(_msg: T, _num_args: Field) {}
#[oracle(debugLog)]
fn debug_log_format_oracle<T, N>(_msg: T, _args: [Field; N], _num_args: Field) -> Field {}
fn debug_log_format_oracle<T, N>(_msg: T, _args: [Field; N], _num_args: Field) {}
#[oracle(debugLog)]
fn debug_log_field_oracle(_field: Field) -> Field {}
fn debug_log_field_oracle(_field: Field) {}
#[oracle(debugLog)]
fn debug_log_array_oracle<T, N>(_arbitrary_array: [T; N]) -> Field {}
fn debug_log_array_oracle<T, N>(_arbitrary_array: [T; N]) {}
#[oracle(debugLogWithPrefix)]
fn debug_log_array_with_prefix_oracle<S, T, N>(_prefix: S, _arbitrary_array: [T; N]) -> Field {}
fn debug_log_array_with_prefix_oracle<S, T, N>(_prefix: S, _arbitrary_array: [T; N]) {}

/// NOTE: call this with a str<N> msg of length > 1
/// Example:
/// `debug_log("blah blah this is a debug string");`
unconstrained pub fn debug_log<T>(msg: T) {
assert(debug_log_oracle(msg, 0) == 0);
debug_log_oracle(msg, 0);
}

/// NOTE: call this with a str<N> msg of form
Expand All @@ -26,23 +26,23 @@ unconstrained pub fn debug_log<T>(msg: T) {
/// Example:
/// debug_log_format("get_2(slot:{0}) =>\n\t0:{1}\n\t1:{2}", [storage_slot, note0_hash, note1_hash]);
unconstrained pub fn debug_log_format<T, N>(msg: T, args: [Field; N]) {
assert(debug_log_format_oracle(msg, args, args.len() as Field) == 0);
debug_log_format_oracle(msg, args, args.len() as Field);
}

/// Example:
/// `debug_log_field(my_field);`
unconstrained pub fn debug_log_field(field: Field) {
assert(debug_log_field_oracle(field) == 0);
debug_log_field_oracle(field);
}

/// Example:
/// `debug_log_array(my_array);`
unconstrained fn debug_log_array<T, N>(arbitrary_array: [T; N]) {
assert(debug_log_array_oracle(arbitrary_array) == 0);
debug_log_array_oracle(arbitrary_array);
}

/// Example:
/// `debug_log_array_with_prefix("Prefix", my_array);`
unconstrained pub fn debug_log_array_with_prefix<S, T, N>(prefix: S, arbitrary_array: [T; N]) {
assert(debug_log_array_with_prefix_oracle(prefix, arbitrary_array) == 0);
debug_log_array_with_prefix_oracle(prefix, arbitrary_array);
}
8 changes: 4 additions & 4 deletions yarn-project/noir-protocol-circuits-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
type BaseOrMergeRollupPublicInputs,
type BaseParityInputs,
type BaseRollupInputs,
Fr,
type KernelCircuitPublicInputs,
type MergeRollupInputs,
type ParityPublicInputs,
Expand All @@ -25,6 +24,7 @@ import { type NoirCompiledCircuit } from '@aztec/types/noir';

import {
type ForeignCallInput,
type ForeignCallOutput,
type WasmBlackBoxFunctionSolver,
createBlackBoxSolver,
executeCircuitWithBlackBoxSolver,
Expand Down Expand Up @@ -755,7 +755,7 @@ async function executePrivateKernelTailToPublicWithACVM(
return decodedInputs.return_value as PublicPublicPreviousReturnType;
}

export const foreignCallHandler = (name: string, args: ForeignCallInput[]) => {
export function foreignCallHandler(name: string, args: ForeignCallInput[]): Promise<ForeignCallOutput[]> {
const log = createDebugLogger('aztec:noir-protocol-circuits:oracle');

if (name === 'debugLog') {
Expand All @@ -766,5 +766,5 @@ export const foreignCallHandler = (name: string, args: ForeignCallInput[]) => {
throw Error(`unexpected oracle during execution: ${name}`);
}

return Promise.resolve([`0x${Buffer.alloc(Fr.SIZE_IN_BYTES).toString('hex')}`]);
};
return Promise.resolve([]);
}
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/acvm/acvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { type ORACLE_NAMES } from './oracle/index.js';
*/
type ACIRCallback = Record<
ORACLE_NAMES,
(...args: ForeignCallInput[]) => ForeignCallOutput | Promise<ForeignCallOutput>
(...args: ForeignCallInput[]) => void | ForeignCallOutput | Promise<ForeignCallOutput>
>;

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ export async function acvm(
}

const result = await oracleFunction.call(callback, ...args);
return [result];
return typeof result === 'undefined' ? [] : [result];
} catch (err) {
let typedError: Error;
if (err instanceof Error) {
Expand Down
6 changes: 2 additions & 4 deletions yarn-project/simulator/src/acvm/oracle/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,12 @@ export class Oracle {
return toACVMField(logHash);
}

debugLog(...args: ACVMField[][]): ACVMField {
debugLog(...args: ACVMField[][]): void {
this.log.verbose(oracleDebugCallToFormattedStr(args));
return toACVMField(0);
}

debugLogWithPrefix(arg0: ACVMField[], ...args: ACVMField[][]): ACVMField {
debugLogWithPrefix(arg0: ACVMField[], ...args: ACVMField[][]): void {
this.log.verbose(`${acvmFieldMessageToString(arg0)}: ${oracleDebugCallToFormattedStr(args)}`);
return toACVMField(0);
}

async callPrivateFunction(
Expand Down
Loading