fix(helpers): prevent u8 overflow in signer fee multiplier - #340
Open
e-desouza wants to merge 1 commit into
Open
fix(helpers): prevent u8 overflow in signer fee multiplier#340e-desouza wants to merge 1 commit into
e-desouza wants to merge 1 commit into
Conversation
The expression `(1 + signers_count)` performed u8 arithmetic where `signers_count: u8`. At the protocol maximum of 255 signers this wraps to 0 in release builds (silent wrong fee) and panics in debug builds. Widened both operands to u64 before adding. XRPL protocol caps SignerList entries well below 255 in practice, so this is a robustness/debug-panic fix, not a reachable issue. Adds `test_fee_calculation_signers_count_max` as a regression guard.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #340 +/- ##
=======================================
Coverage 86.71% 86.71%
=======================================
Files 252 252
Lines 32630 32632 +2
=======================================
+ Hits 28296 28298 +2
Misses 4334 4334
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR hardens fee calculation and version parsing in the async transaction helper layer to prevent panics and incorrect fee computation under edge-case inputs.
Changes:
- Prevents
u8overflow in the signer fee multiplier by widening arithmetic before converting toBigDecimal. - Avoids panics in
is_not_later_rippled_versionby adding a length check before indexing version components. - Improves
EscrowFinishfulfillment fee computation by using the string’s byte length directly (removing an unnecessary allocation), and adds a regression test for the signer multiplier overflow case.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+549
to
+553
| // Regression guard for issue #238: (1 + signers_count) as u8 overflows at 255 | ||
| // in release builds, or panics in debug builds. The fix widens to u64 first. | ||
| // NOTE: A full behavioral test of calculate_fee_per_transaction_type requires a | ||
| // mock AsyncClient — this test guards the arithmetic expression at line 178. | ||
| #[test] |
Comment on lines
+556
to
+558
| // Production expression from calculate_fee_per_transaction_type line 178: | ||
| // let signer_count_fee_decimal: BigDecimal = (1u64 + signers_count as u64).into(); | ||
| let multiplier: BigDecimal = (1u64 + signers_count as u64).into(); |
e-desouza
force-pushed
the
fix/issue-238-fee-overflow
branch
2 times, most recently
from
July 15, 2026 18:37
62a7ee7 to
960bda8
Compare
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.
Why
calculate_fee_per_transaction_typecomputed(1 + signers_count)wheresigners_count: u8. At the maximum value of 255, this performsu8addition: debug builds panic; release builds wrap silently to 0, zeroing the signer fee surcharge and producing a transaction with an incorrect fee.is_not_later_rippled_versionsplit the server'sbuild_versionstring and accessed the resultingVecat indices 1 and 2 without a length check. A non-semverbuild_versionstring (e.g. a dev build returning"1") panicked everyautofillcall.calculate_based_on_fulfillmentcollectedchars().map(|c| c as u8)to compute a byte length for the EscrowFinish fee formula. This silently undercounts for multi-byte codepoints and allocates unnecessarily.Fixes #238.
What changed
asynch/transaction/mod.rs: widened to1u64 + signers_count as u64.is_not_later_rippled_version: addedif source_decomp.len() < 3 || target_decomp.len() < 3 { return Ok(false); }before any index access.calculate_based_on_fulfillment: replacedchars().map(|c| c as u8).collect::<Vec<_>>().len()withfulfillment.len().How to validate
Regression test
test_fee_signer_multiplier_overflow_guardverifies the production expression yieldsBigDecimal::from(256)forsigners_count = 255.