Reject self ContextExtension keys >= 0x80 (JVM context-construction parity)#906
Open
mwaddip wants to merge 1 commit into
Open
Reject self ContextExtension keys >= 0x80 (JVM context-construction parity)#906mwaddip wants to merge 1 commit into
mwaddip wants to merge 1 commit into
Conversation
ContextExtension keys are a signed Byte JVM-side. ErgoLikeContext .toSigmaContext builds the contextVars as new Array(maxKey+1) indexed by the signed key (ErgoLikeContext.scala:140-146), so a self-box extension carrying a key >= 0x80 (signed-negative) crashes context construction (NegativeArraySizeException / ArrayIndexOutOfBoundsException) BEFORE any bytecode runs — the spend never validates. The crash is on the key's PRESENCE, independent of whether the script reads it. sigma-rust stores extension keys as unsigned u8 and resolves them lazily at GetVar, so it would otherwise ACCEPT a >= 0x80 key where the JVM rejects — a consensus fork on the attacker-supplied spending extension (the node feeds the spending input's extension into ctx.extension before reduce_to_crypto). Reject any self-extension key outside 0..=127 at the reduction boundary, mirroring the construction-time crash as a clean rejection. This is the top-level self extension only; the per-input getVarFromInput path masks the id with & 0xff by design and is untouched, and a GetVar of a >= 0x80 id with the key absent still resolves to None. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
kushti
approved these changes
Jun 29, 2026
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.
ContextExtension keys are a signed
ByteJVM-side.ErgoLikeContext.toSigmaContextbuilds the context vars asnew Array(maxKey+1)indexed by the signed key (ErgoLikeContext.scala:140-146), so a self-box extension with a key>= 0x80crashes context construction (NegativeArraySize/ AIOOBE) before any bytecode — the spend never validates, on key PRESENCE.sigma-rust stores extension keys as unsigned
u8and resolves them lazily atGetVar, so it would otherwise ACCEPT a>= 0x80key where the JVM rejects — a consensus fork on the attacker-supplied spending extension. Reject any self-extension key outside0..=127at the reduction boundary. The per-inputgetVarFromInputpath (id masked& 0xff) is untouched, and aGetVarof an absent>= 0x80id still resolves toNone.