Skip to content

fix: checked ERG summation in stateful transaction validation#891

Open
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/erg-sum-overflow
Open

fix: checked ERG summation in stateful transaction validation#891
mwaddip wants to merge 1 commit into
ergoplatform:developfrom
mwaddip:fix/erg-sum-overflow

Conversation

@mwaddip

@mwaddip mwaddip commented Jun 7, 2026

Copy link
Copy Markdown

TransactionContext::validate summed input and output ERG with plain u64 sums, so an overflowing aggregate panicked in debug builds and wrapped in release builds before BoxValue::new could reject it — the input check misfired and the output sum had no check at all.

The reference implementation sums with Math.addExact over longs (ErgoTransaction.validateStateful), trapping every addition. Sum with i64 try_fold/checked_add — the idiom validate_stateless already uses — returning InputSumOverflow/OutputSumOverflow. Also drops the spurious lower-bound check BoxValue::new applied to the aggregate (the reference bounds boxes, not sums).

Pinned by tests asserting the error (not a panic) in both build modes.

Closes #881.

TransactionContext::validate summed input and output box values with
plain u64 sums, so an overflowing aggregate panicked in debug builds
and wrapped in release builds before BoxValue::new could reject it —
the input check misfired and the output sum had no check at all. The
reference implementation sums with Math.addExact over longs
(ErgoTransaction.validateStateful), trapping every addition.

Sum with i64 try_fold/checked_add — the same idiom validate_stateless
already uses — returning InputSumOverflow/OutputSumOverflow. This also
drops the spurious lower-bound check the BoxValue::new construction
applied to the aggregate (the reference bounds boxes, not the sum).

Closes ergoplatform#881.

Co-Authored-By: Claude Opus 4.8 <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.

Unchecked ERG Sum Overflow in Validation

1 participant