Repository navigation
Improve pruning process - #402
Closed
stringhandler wants to merge 5 commits into
Closed
stringhandler wants to merge 5 commits into
stringhandler wants to merge 5 commits into
Conversation
stringhandler
force-pushed
the
st-prune-merge-cases
branch
from
October 29, 2026 09:44
19d4291 to
ccd128b
Compare
Pruning built types for every node of the program, including the nodes in the branches that it then hid. A node which a hidden branch shares with the rest of the program kept that branch's type constraints, so the types of the pruned program were narrower than those a decoder infers from it. Witness values were pruned to those narrower types, so the encoded program failed to decode with trailing witness bytes, or decoded to a different IHR. First walk the program from the root, descending only into branches which were used, to find the nodes to keep. Then build the pruned program from those nodes alone, children first, so that nodes in hidden branches add no type constraints, and fix the program type to 1 -> 1 as a decoder does. This replaces the Pruner converter. The bug predates BlockstreamResearch#379, which made it much more likely by sharing nodes with equal IHRs: the same program with a pointer-shared node fails without BlockstreamResearch#379 too. The regression test covers both kinds of sharing, and also checks the pruned program against libsimplicity. Fixes BlockstreamResearch#391. Assisted-by: Claude
b841d93 upgraded the nightly in .github/workflows/fuzz.yml by hand, but not in the template in fuzz/generate-files.sh, so running the script, as is required when adding a fuzz target, downgraded it to nightly-2024-07-01. Assisted-by: Claude
The existing generator picks a combinator and then type checks it, so few of its programs are well-typed, and those are tiny. Add a generator which picks a type first, and then only combinators which can have that type, so every program is well-typed. It never generates fail, assertions, disconnect or jets which can fail, so every program also runs. It reuses nodes, so that pruning sees nodes shared between hidden and kept code. It uses Elements jets, because libsimplicity decodes Elements jet codes. Add the prune_generated target, which prunes each program and checks that: * the pruned program keeps the CMR and runs, * it decodes to the same IHR and encodes back to the same bytes, * libsimplicity accepts it and computes the same CMR, AMR and IHR, * libsimplicity rejects the unpruned program as anti-DOS exactly when pruning hid a branch. Without the previous fix, this target finds BlockstreamResearch#391 within two minutes. It also finds the bug that the next commit fixes. Also build ElementsEnv::dummy with the test-utils feature, so that the fuzz crate can run Elements jets. Assisted-by: Claude
The tracker records which branches each case node used by IHR. Two case nodes with different types have different IHRs, so pruning can hide a different branch in each. Pruning can then make their types equal, and the IHR of a case node does not show which branch it hides, if that branch holds no witness. An encoder then gives both case nodes the same node, which hides a branch that the other one uses, and the encoded program reaches a pruned branch. Prune in rounds: after rebuilding, merge the case nodes whose IHRs in the pruned program are equal, let them share the branches that any of them used, and rebuild. Every round that does not finish merges two groups of case nodes, so there are at most as many rounds as case nodes. Found by the prune_generated fuzz target. Assisted-by: Claude
Two case unit unit nodes with different types, one of which only takes its right branch and the other only its left. Without the previous commit, the encoded pruned program reaches a pruned branch, in Rust and in libsimplicity. The program is built with the constructor API, because human encoding merges nodes with equal CMRs and so cannot express it. Assisted-by: Claude
stringhandler
force-pushed
the
st-prune-merge-cases
branch
from
October 29, 2026 12:24
ccd128b to
cc71729
Compare
1 of 3 tasks
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.
No description provided.