Skip to content

circuit_unpacker: dummy-leaf support for non-power-of-two N#359

Open
anatgstarkware wants to merge 1 commit into
anatg/unpacker_impl_test1from
anatg/unpacker_dummies
Open

circuit_unpacker: dummy-leaf support for non-power-of-two N#359
anatgstarkware wants to merge 1 commit into
anatg/unpacker_impl_test1from
anatg/unpacker_dummies

Conversation

@anatgstarkware
Copy link
Copy Markdown
Contributor

@anatgstarkware anatgstarkware commented Jun 2, 2026

Summary

Adds support for N that isn't a power of two by right-padding hints.leaf_outputs internally with dummy_leaf_output() up to next_power_of_2(N), and truncating the returned Vec<Vec<Var>> back to N entries.

Dummy slots are indistinguishable from real leaves to compute_subtree_hash: their constant output is guessed into the circuit and Blake-bound just like any other leaf, so the prover cannot substitute different values without falsifying the root hash. The crate-level "Dummy leaves" doc and the Cairo-unpacker comparison table are updated to reflect the padding approach.

Covered by unpacker_n3_one_dummy (N=3, N_total=4, slot 3 dummy).


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 recursive proof unpacking binds dummy tree slots (Blake constraints vs skipped/precomputed subtrees), which affects soundness of the circuits-DSL unpacker path; scope is limited to this crate and covered by new tests.

Overview
Enables non-power-of-two leaf counts in circuit_unpacker by right-padding hints.leaf_outputs with the constant dummy_leaf_output() up to N_total = next_power_of_2(N), running the existing perfect-tree Blake recursion on the padded slice, then truncating the returned Vec<Vec<Var>> to N real leaves.

The previous power-of-two-only path and documentation about precomputed dummy-subtree hashes (skipping recursion into dummy subtrees) are replaced: dummy slots are now ordinary leaves in compute_subtree_hash—guessed and Blake-bound like real leaves—so substitution would break the root hash binding.

Tests add unpacker_n3_one_dummy and extend expected_subtree_hash to pad off-circuit the same way as production code.

Reviewed by Cursor Bugbot for commit 3ddf623. 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.56%. Comparing base (a62182d) to head (3ddf623).

Additional details and impacted files
@@                      Coverage Diff                      @@
##           anatg/unpacker_impl_test1     #359      +/-   ##
=============================================================
+ Coverage                      59.43%   59.56%   +0.12%     
=============================================================
  Files                             36       36              
  Lines                           5367     5366       -1     
=============================================================
+ Hits                            3190     3196       +6     
+ Misses                          2177     2170       -7     
Files with missing lines Coverage Δ
crates/circuit_unpacker/src/lib.rs 90.47% <100.00%> (+10.78%) ⬆️
🚀 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 deleted the branch anatg/unpacker_impl_test1 June 2, 2026 12:59
@anatgstarkware anatgstarkware reopened this Jun 2, 2026
@anatgstarkware anatgstarkware changed the base branch from anatg/unpacker_test2 to anatg/unpacker_impl_test1 June 2, 2026 13:06
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_dummies branch 2 times, most recently from dc9e591 to df33de0 Compare June 2, 2026 13:53
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_impl_test1 branch from 4ce8cdc to 0aa5854 Compare June 2, 2026 13:53
run_unpacker right-pads hints.leaf_outputs with dummy_leaf_output() up
to next_power_of_2(N) before driving the recursion, then truncates the
returned Vec<Vec<Var>> back to N entries. Dummy slots are
indistinguishable from real leaves to compute_subtree_hash: their
constant output is guessed into the circuit and Blake-bound like any
other leaf, so the prover cannot substitute different values without
falsifying the root hash.

Updates the crate-level "Dummy leaves" doc and the Cairo-unpacker
comparison table to reflect the padding approach.

Covered by unpacker_n3_one_dummy (N=3, N_total=4, slot 3 dummy).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@anatgstarkware anatgstarkware force-pushed the anatg/unpacker_impl_test1 branch from 0aa5854 to a62182d 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