fix: reject ErgoTree v>0 header without the size bit (JVM Rule-1012) - #898
Open
mwaddip wants to merge 2 commits into
Open
fix: reject ErgoTree v>0 header without the size bit (JVM Rule-1012)#898mwaddip wants to merge 2 commits into
mwaddip wants to merge 2 commits into
Conversation
JVM CheckHeaderSizeBit (ValidationRules Rule-1012, applied in ErgoTreeSerializer right after the header byte is read) requires the size bit to be set for any ErgoTree version > 0. sigma-rust's header parser did not enforce it, so a malformed v3 header missing the size bit (byte 0x03) parsed and evaluated where the JVM rejects with a ValidationException. Enforce it in ErgoTreeHeader::new (the byte-parse chokepoint; the v0()/v1() struct builders are unaffected) via a new ErgoTreeHeaderError::InvalidSizeBit. Tests: the SANTA Rule1012 vector 03050101017300 and per-version header bytes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… for conformance tests Add a lenient parse mirroring sigma-state deserializeErgoTree(.., checkType = false), gated behind the `arbitrary` feature — the same test/conformance surface as test_util, NOT default-shipped API. The real header parse runs (so Rule-1012 CheckHeaderSizeBit still applies), but a non-SigmaProp root yields a Parsed tree instead of Unparsed. Internally sigma_parse_sized gains a check_root_tpe flag and the parse body is shared via parse_with (strict sigma_parse passes true; no behavior change on the production path). sigma_parse_bytes_lenient_from_unsized restores the size bit + size slot of the historic 'unsized' blessed-byte fixtures (size bit cleared, slot dropped) before parsing, so the interpreter's expression-rooted eval tests keep working once Rule-1012 lands. The SANTA runner can call the same helper (it builds with `arbitrary`), retiring its source build-patch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
JVM CheckHeaderSizeBit (ValidationRules Rule-1012, applied in ErgoTreeSerializer right after the header byte) requires the size bit for any ErgoTree version > 0. sigma-rust's header parser did not enforce it, so a malformed v3 header missing the size bit (0x03) parsed and evaluated where the JVM rejects — a consensus split on crafted trees.
Commit 1 enforces it in ErgoTreeHeader::new (the byte-parse chokepoint) via ErgoTreeHeaderError::InvalidSizeBit.
Commit 2 adds #[cfg(feature = "arbitrary")] ErgoTree::sigma_parse_bytes_lenient (+ _from_unsized), mirroring deserializeErgoTree(checkType=false): the real header parse runs (Rule-1012 still fires), only the SigmaProp-root check is skipped — serves the expression-rooted blessed-byte eval tests and conformance runners; not default API.