Repository navigation
Conversation
…e bit The sigmastate-interpreter serializer runs CheckHeaderSizeBit (validation rule 1012) on the header byte during deserialization: for version > 0 the size bit must be set, otherwise the parse fails (without a size the tree body cannot be skipped, so the reference throws a SerializerException instead of producing a tree). sigma-rust accepted such headers and parsed the following bytes as an un-sized body, so a tree the reference rejects outright could parse successfully here under the wrong framing (e.g. header 0x01 followed by a plain SigmaProp constant root). ErgoTreeHeader::new now returns the new ErgoTreeHeaderError::MissingSizeBit variant for version > 0 headers without the size bit. Version 0 headers are unaffected either way, matching the reference rule, which only fires for version != 0.
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.
Fixes #974.
The gap
The sigmastate-interpreter serializer runs
CheckHeaderSizeBit(validation rule 1012) on the ErgoTree header byte during deserialization: for version > 0 the size bit must be set, otherwise aValidationExceptionis thrown — and because a tree without a size cannot be skipped, it escalates to aSerializerExceptionand the whole parse fails. sigma-rust'sErgoTreeHeader::newaccepted every version/flag combination, soErgoTree::sigma_parsetook the un-sized path for version 1/2/3 headers and interpreted the following bytes directly as constants + root. A trivial proof: take the canonical v0 serialization of aSigmaProp(true)tree and flip the header byte to0x01— it parsed as a valid v1 tree here, while the reference rejects it at the header byte.The fix
ErgoTreeHeader::newnow rejects version > 0 headers without the size bit with a newErgoTreeHeaderError::MissingSizeBit(header_byte)variant. Putting the check in the header constructor means it covers bothErgoTreeHeader::sigma_parseand the fullErgoTree::sigma_parsepath (which converts the error via the existing#[from]intoSigmaParsingError), and it matches where the reference performs the check — on the header, before the body is read.Behaviour matrix (all pinned by the new test):
0x11): rejected as wellTests
develop: the new testparse_header_version_without_size_bit_is_rejectedfailed at the first rejection assertion (header0x01accepted); the v0/v1-sized acceptance pins passed pre-fix, so in-range behaviour is pinned as unchanged, not just the new rejections.cargo test -p ergotree-ir --all-features: 265 passed (+2 doc/integration) — one new test over the 264 baseline.cargo test -p ergo-lib --all-features --lib121/121,cargo test -p ergotree-interpreter --all-features --lib339/339 (the interpreter's own header construction in tests uses0x0b— v3 with the size bit set — so it is unaffected).cargo clippy -p ergotree-ir --all-features --all-targets -- -D warningsclean;cargo fmt --checkclean.Deliberate non-changes
ErgoTreeHeader::v0(..)/v1(..)constructors are untouched: they build valid combinations by construction (v1always sets the size bit).Built by @Kshot9000 — donations (Ergo): 9fcM5RWnAjmP4vx5bnW6yohB6H9bLq8sJbaPLHtwZLtQPB32Pvy