Skip to content

fix: coerce mismatched-numeric arithmetic operands to the wider type#869

Open
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/arith-numeric-coercion
Open

fix: coerce mismatched-numeric arithmetic operands to the wider type#869
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/arith-numeric-coercion

Conversation

@mwaddip
Copy link
Copy Markdown

@mwaddip mwaddip commented May 31, 2026

sigma-rust rejected a numeric BinOp with mismatched operand types (bin-op-kind-mismatch), but sigma-state ACCEPTS it: it coerces to the WIDER type (Byte<Short<Int<Long<BigInt) and computes there with checked (addExact) semantics. So Plus(Int, Long) is accepted by the reference but rejected here — a consensus accept/reject divergence. Confirmed vs sigma-state 6.0.3 (full ErgoLikeInterpreter.verify): SigmaProp(EQ(Plus(Int 1, Long 2), Long 3)) → ACCEPT.

Fix: coerce the narrower operand to the wider type (reusing Upcast), compute in the wider type, reject only on wider-type overflow (LongMax+Int→reject; IntMax+LongLong 2147483648). Same-type arith unchanged. Regression: 14 sweep vectors (order, overflow, 7 ops, Byte/Short/Int/Long/BigInt pairs).

sigma-rust rejected a numeric BinOp whose operands have different types
(bin-op-kind-mismatch), but sigma-state ACCEPTS it: it silently coerces to the
WIDER operand type (Byte<Short<Int<Long<BigInt) and computes there with checked
(addExact) semantics. So a spending script with e.g. Plus(Int, Long) is accepted
by the reference interpreter but rejected here — a consensus accept/reject
divergence. Confirmed vs sigma-state 6.0.3 (full ErgoLikeInterpreter.verify path):
SigmaProp(EQ(Plus(Int 1, Long 2), Long 3)) -> ACCEPT.

Fix: in the BinOp arith eval, coerce the narrower operand up to the wider type
(reusing the Upcast conversions), compute in the wider type, and reject only on
genuine wider-type overflow (LongMax+Int -> reject; IntMax+Long -> Long
2147483648, no Int wrap). Same-type arithmetic (incl. UnsignedBigInt) is unchanged.

Regression: 14 vectors from a sigma-state 6.0.3 sweep covering operand order,
overflow accept/reject, all 7 ops, and Byte/Short/Int/Long/BigInt pairs.

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