Skip to content

fix: reject hard wire-structure errors in the size-flagged ErgoTree degrade gate#911

Open
mwaddip wants to merge 2 commits into
ergoplatform:developfrom
mwaddip:fix/softfork-non-serializable-typecode
Open

fix: reject hard wire-structure errors in the size-flagged ErgoTree degrade gate#911
mwaddip wants to merge 2 commits into
ergoplatform:developfrom
mwaddip:fix/softfork-non-serializable-typecode

Conversation

@mwaddip

@mwaddip mwaddip commented Jun 17, 2026

Copy link
Copy Markdown

Mirror sigma-state's deserializeErgoTree: a size-flagged body-parse failure degrades to UnparsedErgoTree only for a ValidationException; any hard exception escapes and rejects.

The gate previously degraded every error except one, so a crafted size-flagged tree whose constant hits a hard error was accepted (degraded + echoed) where the JVM rejects.

  • a9ba5bac — reject a non-soft-forkable constant type code (rule 1009: neither OptionTypeCode 36 nor > LastDataType 111 → hard SerializerException).
  • fa366f78 — generalize: escape all hard wire errors (bad EC point, EOF/truncation, VLQ overflow); only rule-1014 position-limit keeps degrading, typed distinct from a hard EOF.

Soft-forkable type/opcode/SOption/SFunc/position-limit cases still degrade — no regression.

mwaddip added 2 commits June 17, 2026 12:48
…rule 1009)

A size-flagged ErgoTree whose segregated constant has a non-serializable type code was degraded to an Unparsed tree (and re-serialized) on ANY body-parse error. sigma-state degrades only soft-forkable ValidationExceptions: ErgoTreeSerializer.deserializeErgoTree wraps the body parse in a catch that yields UnparsedErgoTree only for a ValidationException, and rule 1009 (CheckSerializableTypeCode) throws one only when the type code == OptionTypeCode (36) or > LastDataType (111).

For any other non-serializable data type code (SHeader=104, SPreHeader, SGlobal, SContext, SAny, STypeVar) a hard SerializerException escapes the fallback and the tree is rejected even with the size bit set. sigma-rust degraded these too, over-accepting trees the JVM rejects.

Add SigmaParsingError::NonSerializableTypeCode for the non-soft-forkable codes and propagate it out of the sized-parse degrade arm instead of wrapping Unparsed. SOption (36) and SFunc (112) stay soft-forkable and keep degrading. Matches sigma-state 6.0.3 (SANTA vectors ErgoTree.unparsed_soft_fork_{header,option}_constant).
…wire errors

The previous commit rejected only a non-soft-forkable constant type code
(rule 1009). sigma-state's ErgoTreeSerializer.deserializeErgoTree degrades a
size-flagged body-parse failure to UnparsedErgoTree ONLY for a
ValidationException; every other (hard) exception escapes and rejects the
tree -- an IllegalArgumentException from an invalid AutolykosSolution / group
element point, an IOException from a truncated constant body, or a VLQ
overflow. The gate degraded all of these, so a crafted size-flagged tree
carrying such a constant was accepted (degraded to Unparsed and echoed) where
the JVM rejects.

Generalize SigmaParsingError::escapes_sized_tree_degrade to escape all hard
wire-structure errors (NonSerializableTypeCode, ScorexParsingError, Io,
VlqEncode), keeping position-limit degrading -- rule 1014 CheckPositionLimit
is the one soft-forkable wire error (ReaderPositionLimitExceeded ->
ValidationException -> degrade). Position-limit gets a dedicated
PositionLimitExceeded variant (routed from the InvalidData io::Error at the
From boundary across VlqEncodingError / ScorexParsingError / SigmaParsingError,
with a recursive detector) so it is distinguished from a hard EOF. The
position-limit window itself (the MaxBoxSize span during box parse) is not on
this branch, so the carve-out is forward-compatible.
@mwaddip mwaddip changed the title fix: reject non-soft-forkable constant type codes in sized ErgoTree (rule 1009) fix: reject hard wire-structure errors in the size-flagged ErgoTree degrade gate Jun 17, 2026
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