Skip to content

Commit 71d202c

Browse files
authored
refactor!: contract logging plumbing cleanup (#20282)
The `debug_log` naming became problematic as different log levels are supported and hence the name collides with the debug log level even though it's a generic util. For this reason I've renamed `debug_log` simply as `log` and I've cleaned up what used to be `debug_log.nr` file (in this PR renamed to `logging.nr`). The cleanup consists of: - dropping the log_slice functions (use of slices is now discouraged), - introducing individual functions for different log levels, - un-exposing the log level constants (the specific functions should be used instead) This is a breaking change as the imports need to get updated. This PR is a followup of #19960
2 parents be53db8 + 3fcb658 commit 71d202c

File tree

29 files changed

+206
-182
lines changed

29 files changed

+206
-182
lines changed

avm-transpiler/src/transpile.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ fn handle_foreign_call(
563563
"avmOpcodeRevert" => handle_revert(avm_instrs, destinations, inputs),
564564
"avmOpcodeStorageRead" => handle_storage_read(avm_instrs, destinations, inputs),
565565
"avmOpcodeStorageWrite" => handle_storage_write(avm_instrs, destinations, inputs),
566-
"utilityDebugLog" => handle_debug_log(avm_instrs, destinations, inputs),
566+
"utilityLog" => handle_debug_log(avm_instrs, destinations, inputs),
567567
// Getters.
568568
_ if inputs.is_empty() && destinations.len() == 1 => {
569569
handle_getter_instruction(avm_instrs, function, destinations, inputs);
@@ -1348,8 +1348,8 @@ fn handle_debug_log(
13481348
) {
13491349
// We need to handle two flavors here:
13501350
//
1351-
// #[oracle(utilityDebugLog)]
1352-
// unconstrained fn debug_log_array_oracle<let M: u32, let N: u32>(
1351+
// #[oracle(utilityLog)]
1352+
// unconstrained fn log_oracle<let M: u32, let N: u32>(
13531353
// log_level: u8,
13541354
// msg: str<M>,
13551355
// length: u32,
@@ -1358,8 +1358,8 @@ fn handle_debug_log(
13581358
//
13591359
// and
13601360
//
1361-
//#[oracle(utilityDebugLog)]
1362-
// unconstrained fn debug_log_slice_oracle<let M: u32>(log_level: u8, msg: str<M>, args: [Field]) {}
1361+
//#[oracle(utilityLog)]
1362+
// unconstrained fn log_slice_oracle<let M: u32>(log_level: u8, msg: str<M>, args: [Field]) {}
13631363
//
13641364
// Luckily, these two flavors have both 4 arguments, since noir inserts a length field for slices before the slice.
13651365
// So we can handle both cases with mostly the same code.

docs/docs-developers/docs/resources/migration_notes.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ Aztec is in active development. Each version may introduce breaking changes that
99

1010
## TBD
1111

12+
### [Aztec.nr] `debug_log` module renamed to `logging`
13+
14+
The `debug_log` module has been renamed to `logging` to avoid naming collisions with per-level logging functions that were introduced in this PR (`warn_log`, `info_log`, `debug_log`... and the "format" versions `warn_log_format`, `debug_log_format`). Update all import paths accordingly:
15+
16+
```diff
17+
- use aztec::oracle::debug_log::debug_log;
18+
- use aztec::oracle::debug_log::debug_log_format;
19+
+ use aztec::oracle::logging::debug_log;
20+
+ use aztec::oracle::logging::debug_log_format;
21+
```
22+
23+
For inline paths:
24+
25+
```diff
26+
- aztec::oracle::debug_log::debug_log_format("msg: {}", [value]);
27+
+ aztec::oracle::logging::debug_log_format("msg: {}", [value]);
28+
```
29+
30+
The function names themselves (`debug_log`, `debug_log_format`, `debug_log_with_level`, `debug_log_format_with_level`) are unchanged.
31+
32+
Additionally, `debug_log_format_slice` has been removed. Use `debug_log_format` instead, which accepts a fixed-size array of fields:
33+
34+
```diff
35+
- debug_log_format_slice("values: {}", &[value1, value2]);
36+
+ debug_log_format("values: {}", [value1, value2]);
37+
```
38+
39+
This has been done as usage of Noir slices is discouraged and the function was unused in the aztec codebase.
40+
1241
### [aztec.js] `getDecodedPublicEvents` renamed to `getPublicEvents` with new signature
1342

1443
The `getDecodedPublicEvents` function has been renamed to `getPublicEvents` and now uses a filter object instead of positional parameters:

docs/examples/contracts/counter_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub contract Counter {
88
use aztec::{
99
macros::{functions::{external, initializer}, storage::storage},
1010
messages::message_delivery::MessageDelivery,
11-
oracle::debug_log::debug_log_format,
11+
oracle::logging::debug_log_format,
1212
protocol::{address::AztecAddress, traits::ToField},
1313
state_vars::Owned,
1414
};

docs/examples/contracts/recursive_verification_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub contract ValueNotEqual {
88
// docs:start:imports
99
use aztec::{
1010
macros::{functions::{external, initializer, only_self, view}, storage::storage},
11-
oracle::debug_log::debug_log_format,
11+
oracle::logging::debug_log_format,
1212
protocol::{address::AztecAddress, traits::ToField},
1313
state_vars::{Map, PublicImmutable, PublicMutable},
1414
};

docs/static/typescript-api/devnet/pxe.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ new Oracle(handler: IMiscOracle | IUtilityExecutionOracle | IPrivateExecutionOra
365365
- `utilityBulkRetrieveLogs(__namedParameters: string[], __namedParameters: string[], __namedParameters: string[]) => Promise<string[]>`
366366
- `utilityCheckNullifierExists(__namedParameters: string[]) => Promise<string[]>`
367367
- `utilityCopyCapsule(__namedParameters: string[], __namedParameters: string[], __namedParameters: string[], __namedParameters: string[]) => Promise<string[]>`
368-
- `utilityDebugLog(level: string[], message: string[], _ignoredFieldsSize: string[], fields: string[]) => Promise<string[]>`
368+
- `utilityLog(level: string[], message: string[], _ignoredFieldsSize: string[], fields: string[]) => Promise<string[]>`
369369
- `utilityDeleteCapsule(__namedParameters: string[], __namedParameters: string[]) => Promise<string[]>`
370370
- `utilityEmitOffchainEffect(data: string[]) => Promise<never[]>`
371371
- `utilityFetchTaggedLogs(__namedParameters: string[]) => Promise<string[]>`
@@ -542,7 +542,7 @@ new PrivateExecutionOracle(argsHash: Fr, txContext: TxContext, callContext: Call
542542
- `utilityBulkRetrieveLogs(contractAddress: AztecAddress, logRetrievalRequestsArrayBaseSlot: Fr, logRetrievalResponsesArrayBaseSlot: Fr) => Promise<void>`
543543
- `utilityCheckNullifierExists(innerNullifier: Fr) => Promise<boolean>` - Check if a nullifier exists in the nullifier tree.
544544
- `utilityCopyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number) => Promise<void>`
545-
- `utilityDebugLog(level: number, message: string, fields: Fr[]) => void`
545+
- `utilityLog(level: number, message: string, fields: Fr[]) => void`
546546
- `utilityDeleteCapsule(contractAddress: AztecAddress, slot: Fr) => Promise<void>`
547547
- `utilityEmitOffchainEffect(data: Fr[]) => Promise<void>`
548548
- `utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) => Promise<void>`
@@ -769,7 +769,7 @@ new UtilityExecutionOracle(contractAddress: AztecAddress, authWitnesses: AuthWit
769769
- `utilityBulkRetrieveLogs(contractAddress: AztecAddress, logRetrievalRequestsArrayBaseSlot: Fr, logRetrievalResponsesArrayBaseSlot: Fr) => Promise<void>`
770770
- `utilityCheckNullifierExists(innerNullifier: Fr) => Promise<boolean>` - Check if a nullifier exists in the nullifier tree.
771771
- `utilityCopyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number) => Promise<void>`
772-
- `utilityDebugLog(level: number, message: string, fields: Fr[]) => void`
772+
- `utilityLog(level: number, message: string, fields: Fr[]) => void`
773773
- `utilityDeleteCapsule(contractAddress: AztecAddress, slot: Fr) => Promise<void>`
774774
- `utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) => Promise<void>`
775775
- `utilityGetAuthWitness(messageHash: Fr) => Promise<Fr[]>` - Returns an auth witness for the given message hash. Checks on the list of transient witnesses for this transaction first, and falls back to the local database if not found.
@@ -838,7 +838,7 @@ Miscellaneous oracle methods, not very Aztec-specific and expected to be availab
838838

839839
**Methods**
840840
- `utilityAssertCompatibleOracleVersion(version: number) => void`
841-
- `utilityDebugLog(level: number, message: string, fields: Fr[]) => void`
841+
- `utilityLog(level: number, message: string, fields: Fr[]) => void`
842842
- `utilityGetRandomField() => Fr`
843843

844844
### IPrivateExecutionOracle

noir-projects/aztec-nr/aztec/src/context/private_context.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl PrivateContext {
529529
/// balance (>= the gas limits specified in the TxContext) by the time we reach the public setup phase of the tx.
530530
///
531531
pub fn set_as_fee_payer(&mut self) {
532-
crate::protocol::debug_log::debug_log_format("Setting {0} as fee payer", [self.this_address().to_field()]);
532+
crate::protocol::logging::debug_log_format("Setting {0} as fee payer", [self.this_address().to_field()]);
533533
self.is_fee_payer = true;
534534
}
535535

@@ -578,7 +578,7 @@ impl PrivateContext {
578578
// Incrementing the side effect counter when ending setup ensures non ambiguity for the counter where we change
579579
// phases.
580580
self.side_effect_counter += 1;
581-
// crate::protocol::debug_log::debug_log_format(
581+
// crate::protocol::logging::debug_log_format(
582582
// "Ending setup at counter {0}",
583583
// [self.side_effect_counter as Field]
584584
// );

noir-projects/aztec-nr/aztec/src/messages/discovery/mod.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::protocol::{address::AztecAddress, debug_log::{debug_log, debug_log_format}};
1+
use crate::protocol::{address::AztecAddress, logging::{debug_log, debug_log_format}};
22

33
pub mod nonce_discovery;
44
pub mod partial_notes;

noir-projects/aztec-nr/aztec/src/messages/discovery/nonce_discovery.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::messages::{discovery::ComputeNoteHashAndNullifier, logs::note::MAX_NO
33
use crate::protocol::{
44
address::AztecAddress,
55
constants::MAX_NOTE_HASHES_PER_TX,
6-
debug_log::debug_log_format,
76
hash::{compute_note_hash_nonce, compute_siloed_note_hash, compute_unique_note_hash},
7+
logging::debug_log_format,
88
traits::ToField,
99
};
1010

noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::{
1414

1515
use crate::protocol::{
1616
address::AztecAddress,
17-
debug_log::debug_log_format,
1817
hash::sha256_to_field,
18+
logging::debug_log_format,
1919
traits::{Deserialize, Serialize},
2020
};
2121

noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::messages::{
44
logs::note::{decode_private_note_message, MAX_NOTE_PACKED_LEN},
55
processing::enqueue_note_for_validation,
66
};
7-
use crate::protocol::{address::AztecAddress, constants::MAX_NOTE_HASHES_PER_TX, debug_log::debug_log_format};
7+
use crate::protocol::{address::AztecAddress, constants::MAX_NOTE_HASHES_PER_TX, logging::debug_log_format};
88

99
pub unconstrained fn process_private_note_msg<Env>(
1010
contract_address: AztecAddress,

0 commit comments

Comments
 (0)