Skip to content

circuit_unpacker: short-circuit fully-dummy subtrees#360

Open
anatgstarkware wants to merge 1 commit into
anatg/unpacker_dummiesfrom
anatg/unpacker_deeper_dummies
Open

circuit_unpacker: short-circuit fully-dummy subtrees#360
anatgstarkware wants to merge 1 commit into
anatg/unpacker_dummiesfrom
anatg/unpacker_deeper_dummies

Conversation

@anatgstarkware
Copy link
Copy Markdown
Contributor

@anatgstarkware anatgstarkware commented Jun 2, 2026

Summary

Replaces the "treat dummies as regular leaves" recursion with an off-circuit precompute of per-depth dummy-subtree hash constants, wired in-circuit as ctx.constants. When a subtree falls entirely in the dummy region (its leaf range starts at or after N), the recursion returns the cached constant directly — no Blake gate, no recursion, no guessed Vars on the dummy side. Mixed subtrees recurse only on the real side and combine with the cached dummy constant under one Blake gate.

API change

run_unpacker's preprocessed_root is now HashValue<QM31> (by value) instead of HashValue<Var>. The off-circuit precompute (precompute_dummy_hashes) needs the QM31 value; the unpacker wires it as ctx.constant internally, so callers no longer pre-wire pp_root. The existing tests are updated accordingly.

New test

unpacker_n5_dummies_short_circuit_at_two_depths — N=5, N_total=8: slot 5 is a single dummy leaf (depth-0 short-circuit) and slots 6,7 form an all-dummy depth-1 subtree (depth-1 short-circuit). Exercises both layers in one build.


This change is Reviewable

@anatgstarkware anatgstarkware self-assigned this Jun 2, 2026
@cursor
Copy link
Copy Markdown

cursor Bot commented Jun 2, 2026

PR Summary

Medium Risk
Changes how dummy padding is enforced in the Blake hash recursion for STWO proof unpacking; soundness relies on constants matching the root binding, but behavior is covered by new and updated tests.

Overview
Fully-dummy padding subtrees no longer recurse through dummy leaves with Blake gates and guessed outputs. The unpacker precomputes per-depth dummy-subtree hashes off-circuit (precompute_dummy_hashes), wires them as in-circuit constants, and compute_subtree_hash returns those constants when the subtree’s leaf range starts at or after N (no Blake, no dummy Vars). Mixed nodes still Blake-combine the real child with the cached dummy hash.

run_unpacker now takes preprocessed_root as HashValue<QM31> (by value); it internally constant-wires pp_root and the dummy-hash chain. Callers no longer pass pre-wired pp_root Vars. Output collection is sized for real leaves only.

Tests are updated for the API; unpacker_n5_dummies_short_circuit_at_two_depths covers depth-0 and depth-1 dummy short-circuits with N = 5, N_total = 8.

Reviewed by Cursor Bugbot for commit bc08899. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.99%. Comparing base (3ddf623) to head (bc08899).

Additional details and impacted files
@@                    Coverage Diff                     @@
##           anatg/unpacker_dummies     #360      +/-   ##
==========================================================
+ Coverage                   59.56%   59.99%   +0.43%     
==========================================================
  Files                          36       36              
  Lines                        5366     5417      +51     
==========================================================
+ Hits                         3196     3250      +54     
+ Misses                       2170     2167       -3     
Files with missing lines Coverage Δ
crates/circuit_unpacker/src/lib.rs 97.36% <100.00%> (+6.89%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_dummies branch from 72d9fee to 11cff94 Compare June 2, 2026 12:58
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_deeper_dummies branch from c300255 to 0fe7c2e Compare June 2, 2026 12:58
@anatgstarkware anatgstarkware changed the title circuit_unpacker: short-circuit fully-dummy subtrees via precomputed … circuit_unpacker: short-circuit fully-dummy subtrees Jun 2, 2026
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_dummies branch from 11cff94 to dc9e591 Compare June 2, 2026 13:16
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_deeper_dummies branch from 0fe7c2e to 311e9a2 Compare June 2, 2026 13:16
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_dummies branch from dc9e591 to df33de0 Compare June 2, 2026 13:53
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_deeper_dummies branch from 311e9a2 to 17063dd Compare June 2, 2026 13:53
…constants

Replaces the "treat dummies as regular leaves" recursion with an
off-circuit precompute of dummy_hash_at_depth(d) for every depth in
0..=tree_height, wired in-circuit as ctx.constants. The recursive
compute_subtree_hash now takes (leaf_offset, n_real, depth,
dummy_hash_vars) and returns the cached constant directly whenever a
subtree's leaf range falls entirely in the dummy region -- no
recursion or Blake gate on the dummy side. Mixed subtrees still recurse
on the real side and combine with the cached dummy constant under a
single Blake gate.

Requires a small API change: preprocessed_root is now HashValue<QM31>
(by value), since the off-circuit precompute needs the value, not just
Vars. The unpacker wires it as ctx.constant internally; callers no
longer have to pre-wire pp_root themselves. Existing tests adjusted.

Adds unpacker_n5_dummies_short_circuit_at_two_depths, an N=5 case where
both a depth-0 dummy (slot 5) and an all-dummy depth-1 subtree
(slots 6,7) exercise the short-circuit at two distinct depths in the
same circuit build.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_deeper_dummies branch from 17063dd to bc08899 Compare June 2, 2026 18:36
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_dummies branch from df33de0 to 3ddf623 Compare June 2, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant