Skip to content

fix(ergotree-interpreter): implement numeric cast to UnsignedBigInt in eval#878

Open
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/cast-to-unsignedbigint
Open

fix(ergotree-interpreter): implement numeric cast to UnsignedBigInt in eval#878
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/cast-to-unsignedbigint

Conversation

@mwaddip

@mwaddip mwaddip commented Jun 4, 2026

Copy link
Copy Markdown

Upcast/Downcast to UnsignedBigInt had no eval arm, so evaluating one hit the _ catch-all and errored ("expected numeric value"). This adds the SUnsignedBigInt target arm to both, mirroring Scala SUnsignedBigInt.upcast/downcast: widen Byte/Short/Int/Long, pass an UnsignedBigInt through unchanged, and reject negatives (the JVM errors when widening a negative numeric to UnsignedBigInt). No signed-BigInt source arm — ErgoScript uses .toUnsigned.

Surfaced by a full node on testnet block 28,474 (Autolykos-2 verify): coll.map(x => Global.powHit(..)).exists((u: UnsignedBigInt) => ..), whose predicate runs Upcast(Int -> UnsignedBigInt). JVM 6.0.3 accepts it.

Tests cover each source type, the identity pass-through, and negative / signed-BigInt rejection.

…n eval

Upcast/Downcast to UnsignedBigInt had no eval arm, so the `_` catch-all
errored ("Upcast: expected numeric value" / "Downcast: ..."). Add the
SUnsignedBigInt target arm to both, mirroring Scala
SUnsignedBigInt.upcast/downcast: widen Byte/Short/Int/Long, pass an
UnsignedBigInt through unchanged, and reject negative values (the JVM
errors when widening a negative numeric to UnsignedBigInt). There is
deliberately no signed-BigInt source arm (ErgoScript uses .toUnsigned).

Surfaced by a full node on testnet block 28,474 (an Autolykos-2 verify),
which maps Global.powHit over a collection and runs
Upcast(Int -> UnsignedBigInt) in the exists predicate.

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