fix: coerce mismatched-numeric arithmetic operands to the wider type#869
Open
mwaddip wants to merge 1 commit into
Open
fix: coerce mismatched-numeric arithmetic operands to the wider type#869mwaddip wants to merge 1 commit into
mwaddip wants to merge 1 commit into
Conversation
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>
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.
sigma-rust rejected a numeric
BinOpwith 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. SoPlus(Int, Long)is accepted by the reference but rejected here — a consensus accept/reject divergence. Confirmed vs sigma-state 6.0.3 (fullErgoLikeInterpreter.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+Long→Long 2147483648). Same-type arith unchanged. Regression: 14 sweep vectors (order, overflow, 7 ops, Byte/Short/Int/Long/BigInt pairs).