Skip to content

feat: add read-only view fn entry points (V15)#29419

Draft
mohammadfawaz wants to merge 1 commit into
masterfrom
mohammadfawaz/view_functions
Draft

feat: add read-only view fn entry points (V15)#29419
mohammadfawaz wants to merge 1 commit into
masterfrom
mohammadfawaz/view_functions

Conversation

@mohammadfawaz
Copy link
Copy Markdown
Collaborator

Summary

Adds Leo support for V15 view fn blocks (snarkVM #3238 + rename #3257) and lets a final {} body call those views (snarkVM #3253).

Supersedes #29411 (the original branch was force-pushed during the rename and the PR auto-closed).

  • Parser, AST (Variant::View), rowan→AST, type-check restrictions (read-only, plaintext-only, views are leaves; block.timestamp rejected, mapping writes / async / call rejected; reads of mappings, vectors, storage, block.height, network.id allowed).
  • Codegen emits Aleo view <name>: blocks. Disassembler round-trips them. ABI exposes views: Vec<Function>.
  • Formatter handles view fn (contextual keyword — preserves view as a regular identifier in pre-V15 source).
  • Deploy/upgrade reject pre-V15 deployments containing view blocks via Program::contains_v15_syntax.
  • Test framework: routes views through Process::evaluate_view_at_height (history feature) and adds optional seed_mapping to populate finalize-store entries before a case runs.
  • Finalize → view: type-check allows Variant::View callees from final {} blocks, final fn helpers, and hoisted-Variant::Finalize bodies; constructors still forbid call. is_cross_program_entry generalised to is_cross_program_call_target (covers views) so cross-program views survive the inliner and monomorphizer as direct calls. Tightened pre-existing gaps: transition body outside final {} calling a view, and final fn calling an entry point, now rejected at type-check with a clear message instead of failing late at snarkVM.

snarkVM pinned at cf6b381b (PR #3253 head); getrandom 0.4 enables the wasm_js backend on wasm32-unknown-unknown; satellite snarkVM pins promoted to workspace deps; CLI consensus-heights tests carry 15 values (V0–V14).

Tests

Compiler-level positive: basic_view, view_with_branching, view_uses_storage_and_vector, finalize_calls_view, finalize_calls_cross_program_view, final_fn_calls_view.
Compiler-level negative: final_view_fail, view_calls_other_view_fail, view_writes_mapping_fail, view_in_library_fail, entry_body_calls_view_fail, final_fn_calls_entry_point_fail.
Execution-level (Process::execute / evaluate_view_at_height): view_basic, view_storage_and_vector, view_aggregate, view_struct_output, finalize_calls_view.

@mohammadfawaz mohammadfawaz marked this pull request as draft May 13, 2026 15:09
@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/view_functions branch 2 times, most recently from 00ccc23 to b9cbdb0 Compare May 14, 2026 18:37
mohammadfawaz pushed a commit that referenced this pull request May 14, 2026
Implements V15 `view fn` block: a top-level program component that reads
finalize-store state off-consensus and returns plaintext to external callers.
Allowed reads cover mappings, vectors, storage, `block.height`, and
`network.id`; writes, `async`, `call`, and `block.timestamp` are rejected.
View fns are leaves (snarkVM rejects `call` inside a view body) but can be
called from `final {}` blocks, `final fn` helpers, and hoisted `Finalize`
bodies. Cross-program views go through `is_cross_program_call_target` to
survive the inliner and monomorphizer. Interface conformance enforces
View↔View and Fn↔(Fn|EntryPoint).

Bumps snarkVM to 088684ed (PR #3253 head): finalize-calls-view plus
`many0` view bodies, so empty views compile to valid Aleo bytecode with
no dummy filler.

closes #29419
@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/view_functions branch from b9cbdb0 to ffebd44 Compare May 14, 2026 19:57
@mohammadfawaz mohammadfawaz self-assigned this May 14, 2026
@mohammadfawaz mohammadfawaz added 🧱 Core Compiler Anything related to the core compiler including parsing, analysis, transforms, codegen, etc. 🚀 feature A new feature. labels May 14, 2026
Implements V15 `view fn` block: a top-level program component that reads
finalize-store state off-consensus and returns plaintext to external callers.
Allowed reads cover mappings, vectors, storage, `block.height`, and
`network.id`; writes, `async`, `call`, and `block.timestamp` are rejected.
View fns are leaves (snarkVM rejects `call` inside a view body) but can be
called from `final {}` blocks, `final fn` helpers, and hoisted `Finalize`
bodies. Cross-program views go through `is_cross_program_call_target` to
survive the inliner and monomorphizer. Interface conformance enforces
View↔View and Fn↔(Fn|EntryPoint).

Bumps snarkVM to 088684ed (PR #3253 head): finalize-calls-view plus
`many0` view bodies, so empty views compile to valid Aleo bytecode with
no dummy filler.

closes #29419
@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/view_functions branch from ffebd44 to 0491006 Compare May 14, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧱 Core Compiler Anything related to the core compiler including parsing, analysis, transforms, codegen, etc. 🚀 feature A new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant