Skip to content

refactor: use immutable references for read-only public context methods#22420

Draft
AztecBot wants to merge 10 commits intonextfrom
claudebox/d72e1449fb744a16-25
Draft

refactor: use immutable references for read-only public context methods#22420
AztecBot wants to merge 10 commits intonextfrom
claudebox/d72e1449fb744a16-25

Conversation

@AztecBot
Copy link
Copy Markdown
Collaborator

@AztecBot AztecBot commented Apr 8, 2026

Summary

Converts read-only methods on PublicContext, UtilityContext, PublicCall, and PublicStaticCall from taking self by value to &self (immutable reference). This helps the compiler optimize clone placement in Brillig (CoW semantics), reducing unnecessary array copies during public/unconstrained execution.

Changes

PublicContext (public_context.nr)

All AVM opcode getter methods now take &self instead of self:

  • this_address, maybe_msg_sender, selector, transaction_fee
  • chain_id, version, block_number, timestamp
  • min_fee_per_l2_gas, min_fee_per_da_gas, l2_gas_left, da_gas_left
  • is_static_call, note_hash_exists, l1_to_l2_msg_exists, nullifier_exists_unsafe
  • raw_storage_read, storage_read, raw_storage_write, storage_write
  • Side-effect methods (push_note_hash, push_nullifier, emit_public_log_unsafe, etc.) — these don't mutate the Noir struct (AVM handles state at VM level)
  • consume_l1_to_l2_message, message_portal, call_public_function, static_call_public_function

UtilityContext (utility_context.nr)

All getter methods now take &self:

  • block_header, block_number, timestamp, this_address, version, chain_id
  • raw_storage_read, storage_read

PublicCall / PublicStaticCall (calls.nr)

  • call(&self, context: &PublicContext) and view(&self, context: &PublicContext) — both read-only
  • enqueue, enqueue_incognito, enqueue_view, enqueue_view_incognito — read self fields only
  • set_as_teardown, set_as_teardown_incognito — read self fields only

Callers updated

  • contract_self_public.nr — passes &self.context instead of self.context
  • external_functions_stubs.nr (macro) — same fix for generated call/view stubs

ClaudeBox log: https://claudebox.work/s/d72e1449fb744a16?run=25

@AztecBot AztecBot added ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR. labels Apr 8, 2026
AztecBot added 9 commits April 8, 2026 15:39
Change call(self, call: PublicCall<M, N, T>) to call(self, call: &PublicCall<M, N, T>)
and view(self, call: PublicStaticCall<M, N, T>) to view(self, call: &PublicStaticCall<M, N, T>).

Callers now pass & explicitly: self.call(&Token::at(...).transfer(...)).
This avoids cloning the args: [Field; N] array in PublicCall/PublicStaticCall structs.
- Add & to self.call/self.view callers in aave_bridge and example_uniswap
  docs example contracts (public function contexts)
- Remove Prover.toml files accidentally generated by nargo check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant