refactor: use immutable references for read-only public context methods#22420
Draft
refactor: use immutable references for read-only public context methods#22420
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts read-only methods on
PublicContext,UtilityContext,PublicCall, andPublicStaticCallfrom takingselfby 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
&selfinstead ofself:this_address,maybe_msg_sender,selector,transaction_feechain_id,version,block_number,timestampmin_fee_per_l2_gas,min_fee_per_da_gas,l2_gas_left,da_gas_leftis_static_call,note_hash_exists,l1_to_l2_msg_exists,nullifier_exists_unsaferaw_storage_read,storage_read,raw_storage_write,storage_writepush_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_functionUtilityContext (
utility_context.nr)All getter methods now take
&self:block_header,block_number,timestamp,this_address,version,chain_idraw_storage_read,storage_readPublicCall / PublicStaticCall (
calls.nr)call(&self, context: &PublicContext)andview(&self, context: &PublicContext)— both read-onlyenqueue,enqueue_incognito,enqueue_view,enqueue_view_incognito— read self fields onlyset_as_teardown,set_as_teardown_incognito— read self fields onlyCallers updated
contract_self_public.nr— passes&self.contextinstead ofself.contextexternal_functions_stubs.nr(macro) — same fix for generated call/view stubsClaudeBox log: https://claudebox.work/s/d72e1449fb744a16?run=25