fix: pre-JIT ErgoScript leniency for v0/v1 ErgoTree scripts#859
Open
mwaddip wants to merge 2 commits into
Open
fix: pre-JIT ErgoScript leniency for v0/v1 ErgoTree scripts#859mwaddip wants to merge 2 commits into
mwaddip wants to merge 2 commits into
Conversation
Three pre-JIT compatibility paths in the interpreter were either missing or wrongly gated on the network's activated script version. The JVM sigmastate-interpreter applies these lenient v4.x semantics to ErgoTree scripts whose header version is < V2 (i.e. V0 or V1), regardless of the block they are spent in. A v0 tree spent in a v3+ block must still get the lenient path because the leniency is a property of how the old script was originally written and validated. The previous selfBoxIndex fix (now superseded) gated on `activated_script_version() < V2`, which only triggered the lenient path for v0/v1 *blocks*. This was incomplete: a buggy v0 script spent in a v3+ block (the common case post-mainnet-v5-activation) still needs the lenient -1 return value to match the JVM. Three behaviors fixed: 1. selfBoxIndex (CContext.scala equivalent): pre-V2 trees return -1 instead of the real input index. JVM bug ergoplatform#603 - historical scripts set output R4=-1 to match the buggy value. 2. BoolToSigmaProp (trees.scala): pre-V2 trees pass a SigmaProp input through unchanged instead of strict bool extraction. Mainnet has `sigmaProp(sigmaProp(...))` patterns at e.g. tx 5fe235558... block 680692 (address Fo6oijFP2JM87ac7w) which the JVM has a property test for. 3. xorOf (CSigmaDslBuilder.scala): pre-V2 trees compute `distinct.length == 2` (true iff coll contains BOTH true and false, count and order independent) instead of the proper left-fold XOR. The JVM source comment labels this "buggy version used in v4.x interpreter". All three gates use `ctx.tree_version() < ErgoTreeVersion::V2` so the script's header version determines the path, not the block's activated version. This matches how the JVM dispatches v4.x semantics through its `VersionContext` propagation. Tests added/updated: - selfBoxIndex: V0, V1, V2 cases - BoolToSigmaProp: V0 passthrough, V2 strict-error - xorOf: V0 distinct-length, V2 left-fold; concrete [true,true,false] cases proving the divergence Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rsion The JVM bug ergoplatform#603 (eq vs == in CostingDataContext.scala) was a global implementation bug fixed in v5.x for ALL scripts, not a per-script semantic difference. Using tree_version caused V0 scripts in v5+ blocks to incorrectly return -1, failing mainnet block 942664. Gate on activated_script_version (block level) so pre-v5 blocks reproduce the bug and v5+ blocks return the correct index regardless of script version. bool_to_sigma and xor_of gates are unchanged — those ARE per-script semantics. Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Three pre-JIT (v4.x) compatibility paths missing: BoolToSigmaProp passthrough for SigmaProp input, xorOf using distinct.length == 2 (both per-script, gated on tree_version()), and selfBoxIndex returning -1 in pre-v5 blocks (block-level, gated on activated_script_version() — JVM eq/== bug fixed globally in v5).
Verified: full mainnet validation from genesis through 966k+ blocks, no checkpoint, zero errors. (Per May 20: full validation from genesis to tip)