Set tree_version from the evaluated tree in reduce_to_crypto#875
Open
mwaddip wants to merge 1 commit into
Open
Set tree_version from the evaluated tree in reduce_to_crypto#875mwaddip wants to merge 1 commit into
mwaddip wants to merge 1 commit into
Conversation
reduce_to_crypto never propagated the evaluated ErgoTree's version into the eval Context, so ctx.tree_version stayed at its V0 default unless a caller set it. The JVM interpreter wraps reduction in VersionContext.withVersions(activatedVersion, ergoTree.version), setting the tree version from the tree being evaluated. Without this, version-gated ops evaluate as V0. BigInt -> Long downcast is gated on tree_version >= V3 (matching the JVM's SLong.downcast / isV3OrLaterErgoTreeVersion), so a V3 tree doing that downcast was rejected by sigma-rust while the JVM accepts it -- a consensus divergence. It surfaced as a node failing to sync testnet at the first V3 BigInt.toLong transaction; mainnet has no V3 trees, so it never triggered there. Set ctx.tree_version from tree.header().version() at the top of reduce_to_crypto. Adds a regression test reducing a V3 tree's BigInt(67500000000).toLong through reduce_to_crypto with a default-V0 context (reproduces the exact "cannot downcast" error without the fix). Co-Authored-By: Claude Opus 4.8 (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.
reduce_to_cryptonever propagated the evaluated ErgoTree's version into the evalContext—ctx.tree_versionstayed at itsV0default unless a caller set it. The JVM wraps reduction inVersionContext.withVersions(activatedVersion, ergoTree.version).Effect: version-gated ops evaluate as V0.
BigInt -> Longdowncast is gated ontree_version >= V3(matching the JVMSLong.downcast), so a V3 tree doing it was rejected by sigma-rust while the JVM accepts it — a consensus divergence (a node failed to sync testnet at the first V3BigInt.toLongtx; mainnet has no V3 trees so it never triggered).Fix: set
ctx.tree_versionfromtree.header().version()inreduce_to_crypto. Adds a regression test viareduce_to_cryptoon a default-V0 context.