feat(actuator,consensus): harden exchange calculations (TIP-836)#6710
Open
halibobo1205 wants to merge 4 commits intotronprotocol:developfrom
Open
feat(actuator,consensus): harden exchange calculations (TIP-836)#6710halibobo1205 wants to merge 4 commits intotronprotocol:developfrom
halibobo1205 wants to merge 4 commits intotronprotocol:developfrom
Conversation
7ff8e9b to
6c92146
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).
6c92146 to
03ecf09
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:
SafeExchangeProcessorreplacesdoublearithmetic in the Bancor formula withBigDecimal, eliminating silentInfinity/NaNfrom division-by-zero.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, one-time activation.Reference
TIP-836: Harden Exchange Transaction Calculations