Skip to content

fix: reject ErgoTree v>0 header without the size bit (JVM Rule-1012) - #898

Open
mwaddip wants to merge 2 commits into
ergoplatform:developfrom
mwaddip:fix/header-size-bit-rule1012
Open

fix: reject ErgoTree v>0 header without the size bit (JVM Rule-1012)#898
mwaddip wants to merge 2 commits into
ergoplatform:developfrom
mwaddip:fix/header-size-bit-rule1012

Conversation

@mwaddip

@mwaddip mwaddip commented Jun 10, 2026

Copy link
Copy Markdown

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.

mwaddip and others added 2 commits June 8, 2026 17:43
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>
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