fix: checked ERG summation in stateful transaction validation#891
Open
mwaddip wants to merge 1 commit into
Open
fix: checked ERG summation in stateful transaction validation#891mwaddip wants to merge 1 commit into
mwaddip wants to merge 1 commit into
Conversation
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>
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.
TransactionContext::validatesummed input and output ERG with plainu64sums, so an overflowing aggregate panicked in debug builds and wrapped in release builds beforeBoxValue::newcould reject it — the input check misfired and the output sum had no check at all.The reference implementation sums with
Math.addExactover longs (ErgoTransaction.validateStateful), trapping every addition. Sum with i64try_fold/checked_add— the idiomvalidate_statelessalready uses — returningInputSumOverflow/OutputSumOverflow. Also drops the spurious lower-bound checkBoxValue::newapplied to the aggregate (the reference bounds boxes, not sums).Pinned by tests asserting the error (not a panic) in both build modes.
Closes #881.