Skip to content

Set tree_version from the evaluated tree in reduce_to_crypto#875

Open
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/reduce-to-crypto-tree-version
Open

Set tree_version from the evaluated tree in reduce_to_crypto#875
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/reduce-to-crypto-tree-version

Conversation

@mwaddip

@mwaddip mwaddip commented Jun 3, 2026

Copy link
Copy Markdown

reduce_to_crypto never propagated the evaluated ErgoTree's version into the eval Contextctx.tree_version stayed at its V0 default unless a caller set it. The JVM wraps reduction in VersionContext.withVersions(activatedVersion, ergoTree.version).

Effect: version-gated ops evaluate as V0. BigInt -> Long downcast is gated on tree_version >= V3 (matching the JVM SLong.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 V3 BigInt.toLong tx; mainnet has no V3 trees so it never triggered).

Fix: set ctx.tree_version from tree.header().version() in reduce_to_crypto. Adds a regression test via reduce_to_crypto on a default-V0 context.

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>
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