diff --git a/noir-projects/aztec-nr/aztec/src/oracle.nr b/noir-projects/aztec-nr/aztec/src/oracle.nr index bd0c110e220d..b26afcf9cb01 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle.nr @@ -5,7 +5,6 @@ mod arguments; mod call_private_function; mod context; -mod debug_log; mod get_contract_instance; mod get_l1_to_l2_membership_witness; mod get_nullifier_membership_witness; @@ -21,3 +20,7 @@ mod public_call; mod notes; mod storage; mod logs; + +// debug_log oracle is used by both noir-protocol-circuits and this crate and for this reason we just re-export it +// here from protocol circuits. +use dep::protocol_types::debug_log; \ No newline at end of file diff --git a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr index 7e08267af34c..9803ed4f15e5 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr @@ -7,7 +7,6 @@ contract SchnorrSingleKeyAccount { use dep::authwit::{entrypoint::{app::AppPayload, fee::FeePayload}, account::AccountActions}; use crate::{util::recover_address, auth_oracle::get_auth_witness}; - use dep::aztec::oracle::debug_log::debug_log_format; global ACCOUNT_ACTIONS_STORAGE_SLOT = 1; diff --git a/noir-projects/aztec-nr/aztec/src/oracle/debug_log.nr b/noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr similarity index 100% rename from noir-projects/aztec-nr/aztec/src/oracle/debug_log.nr rename to noir-projects/noir-protocol-circuits/crates/types/src/debug_log.nr diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr index f9c986ba0de2..5e7a03c0f962 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/lib.nr @@ -1,5 +1,6 @@ mod utils; mod address; +mod debug_log; mod grumpkin_point; mod grumpkin_private_key; // This is intentionally spelled like this diff --git a/yarn-project/simulator/src/acvm/oracle/debug.ts b/yarn-project/circuits.js/src/debug_log.ts similarity index 97% rename from yarn-project/simulator/src/acvm/oracle/debug.ts rename to yarn-project/circuits.js/src/debug_log.ts index 655584512e98..36517cda5053 100644 --- a/yarn-project/simulator/src/acvm/oracle/debug.ts +++ b/yarn-project/circuits.js/src/debug_log.ts @@ -1,6 +1,7 @@ +// Placed here as it is used both by simulator and by noir-protocol-circuits-types import { type ForeignCallInput } from '@noir-lang/acvm_js'; -import { type ACVMField } from '../acvm_types.js'; +type ACVMField = string; /** * Convert an array of ACVMFields to a string. diff --git a/yarn-project/circuits.js/src/index.ts b/yarn-project/circuits.js/src/index.ts index 1fafc4e3bf56..f74c41c59323 100644 --- a/yarn-project/circuits.js/src/index.ts +++ b/yarn-project/circuits.js/src/index.ts @@ -1,5 +1,6 @@ export * from './constants.gen.js'; export * from './contract/index.js'; +export * from './debug_log.js'; export * from './hints/index.js'; export * from './keys/index.js'; export * from './structs/index.js'; diff --git a/yarn-project/noir-protocol-circuits-types/src/index.ts b/yarn-project/noir-protocol-circuits-types/src/index.ts index 8657f68680a4..853b59de4d6a 100644 --- a/yarn-project/noir-protocol-circuits-types/src/index.ts +++ b/yarn-project/noir-protocol-circuits-types/src/index.ts @@ -2,6 +2,7 @@ import { type BaseOrMergeRollupPublicInputs, type BaseParityInputs, type BaseRollupInputs, + Fr, type KernelCircuitPublicInputs, type MergeRollupInputs, type ParityPublicInputs, @@ -16,10 +17,14 @@ import { type RootParityInputs, type RootRollupInputs, type RootRollupPublicInputs, + acvmFieldMessageToString, + oracleDebugCallToFormattedStr, } from '@aztec/circuits.js'; +import { createDebugLogger } from '@aztec/foundation/log'; import { type NoirCompiledCircuit } from '@aztec/types/noir'; import { + type ForeignCallInput, type WasmBlackBoxFunctionSolver, createBlackBoxSolver, executeCircuitWithBlackBoxSolver, @@ -453,9 +458,7 @@ async function executePrivateKernelInitWithACVM(input: InitInputType): Promise { - throw Error('unexpected oracle during execution'); - }, + foreignCallHandler, ); // Decode the witness map into two fields, the return values and the inputs @@ -481,9 +484,7 @@ async function executePrivateKernelInnerWithACVM(input: InnerInputType): Promise await getSolver(), decodedBytecode, initialWitnessMap, - () => { - throw Error('unexpected oracle during execution'); - }, + foreignCallHandler, ); // Decode the witness map into two fields, the return values and the inputs @@ -509,9 +510,7 @@ async function executePrivateKernelTailWithACVM(input: TailInputType): Promise { - throw Error('unexpected oracle during execution'); - }, + foreignCallHandler, ); // Decode the witness map into two fields, the return values and the inputs @@ -536,9 +535,7 @@ async function executePrivateKernelTailToPublicWithACVM( await getSolver(), decodedBytecode, initialWitnessMap, - () => { - throw Error('unexpected oracle during execution'); - }, + foreignCallHandler, ); // Decode the witness map into two fields, the return values and the inputs @@ -547,3 +544,17 @@ async function executePrivateKernelTailToPublicWithACVM( // Cast the inputs as the return type return decodedInputs.return_value as PublicPublicPreviousReturnType; } + +const foreignCallHandler = (name: string, args: ForeignCallInput[]) => { + const log = createDebugLogger('aztec:noir-protocol-circuits:oracle'); + + if (name === 'debugLog') { + log(oracleDebugCallToFormattedStr(args)); + } else if (name === 'debugLogWithPrefix') { + log(`${acvmFieldMessageToString(args[0])}: ${oracleDebugCallToFormattedStr(args.slice(1))}`); + } else { + throw Error(`unexpected oracle during execution: ${name}`); + } + + return Promise.resolve([`0x${Buffer.alloc(Fr.SIZE_IN_BYTES).toString('hex')}`]); +}; diff --git a/yarn-project/simulator/src/acvm/oracle/index.ts b/yarn-project/simulator/src/acvm/oracle/index.ts index a89ffce2a1ba..d9b084ccb6cb 100644 --- a/yarn-project/simulator/src/acvm/oracle/index.ts +++ b/yarn-project/simulator/src/acvm/oracle/index.ts @@ -1,6 +1,5 @@ import { type Oracle } from './oracle.js'; -export * from './debug.js'; export * from './oracle.js'; export * from './typed_oracle.js'; diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index 9266daff20ed..81892640934c 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -1,5 +1,5 @@ import { MerkleTreeId, UnencryptedL2Log } from '@aztec/circuit-types'; -import { RETURN_VALUES_LENGTH } from '@aztec/circuits.js'; +import { RETURN_VALUES_LENGTH, acvmFieldMessageToString, oracleDebugCallToFormattedStr } from '@aztec/circuits.js'; import { EventSelector, FunctionSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { padArrayEnd } from '@aztec/foundation/collection'; @@ -9,7 +9,6 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { type ACVMField } from '../acvm_types.js'; import { frToBoolean, frToNumber, fromACVMField } from '../deserialize.js'; import { toACVMField, toAcvmEnqueuePublicFunctionResult } from '../serialize.js'; -import { acvmFieldMessageToString, oracleDebugCallToFormattedStr } from './debug.js'; import { type TypedOracle } from './typed_oracle.js'; /**