feat(actuator,consensus): harden exchange calculations (TIP-836)#6710
Merged
lvs0075 merged 7 commits intotronprotocol:developfrom May 8, 2026
Merged
Conversation
7ff8e9b to
6c92146
Compare
6c92146 to
03ecf09
Compare
lxcmyf
approved these changes
May 6, 2026
a6aaa84 to
93f384b
Compare
…IP-836) Add SafeExchangeProcessor that replaces double arithmetic with BigDecimal in the Bancor-formula calculation: 1. BigDecimal divide throws ArithmeticException on zero divisor 2. ExchangeCapsule.transaction() rejects negative post-trade balances 3. longValueExact() guards against BigDecimal-to-long saturation Introduce AbstractExchangeActuator that overrides addExact/subtractExact to route through allowHardenExchangeCalculation() flag, applied to all four exchange actuators (Create, Inject, Transaction, Withdraw) for consistent overflow detection. ExchangeWithdrawActuator.validate() also gains a pure BigDecimal precision-loss check when the proposal is active (previously used double comparison). Pre-activation behavior is byte-for-byte identical to legacy code. Activation gated by ALLOW_HARDEN_EXCHANGE_CALCULATION (proposal 98).
16271b8 to
f52026e
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.
Summary
Implements TIP-836 to harden exchange transaction calculations:
SafeExchangeProcessorusesBigDecimalfor division, scaling, and rounding around the Bancor formula, while keepingStrictMath.powfor deterministic exponentiation. This avoids silentInfinity/NaNresults from invalid division paths.ExchangeCapsule.transaction()rejects negative post-trade pool balances viaStrictMathWrapper.addExact/subtractExact.AbstractExchangeActuatorfor unified overflow-checked arithmetic gated by the new proposal.ALLOW_HARDEN_EXCHANGE_CALCULATION(code 98), requires forkVERSION_4_8_2.Reference
TIP-836: Harden Exchange Transaction Calculations