Repository navigation
Conversation
… fee box BabelFeeBoxStateBuilder.build() validates pricePerToken > 0, but the BabelFeeBoxState(TransactionBox) constructor - the path used for boxes loaded from the chain - read the price from register R5 with no check. A babel fee box can be created outside appkit with any register values, so a box with price 0 or a negative price parses into a state whose getMaxTokenAmountToBuy() and calcTokensToSellForErgAmount() then divide by that price: ArithmeticException (/ by zero) for 0, and nonsense token amounts for a negative price, surfacing far from the cause in BabelFeeOperations.addBabelFeeBoxes. Reject pricePerToken <= 0 at parse time with IllegalStateException (matching the token-id mismatch check in the same constructor), and enforce the same invariant in the internal constructor so no instance can carry a non-positive price. Boxes with a regular price parse and calculate exactly as before. New BabelFeeSpec property builds babel boxes with price 0 and -1 directly (bypassing the builder) and asserts both are rejected, and that a regular price still parses and calculates.
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.
Fixes #262
BabelFeeBoxStateBuilderalready enforcespricePerToken > 0, but theBabelFeeBoxState(TransactionBox)constructor — used for boxes loaded from the chain, whose registers anyone could have set — read the price from R5 unchecked. A box with price 0 then crashedgetMaxTokenAmountToBuy()/calcTokensToSellForErgAmount()withArithmeticException: / by zero(reachable viaBabelFeeOperations.addBabelFeeBoxes), and a negative price made the calculations return nonsense amounts.This PR enforces the builder's invariant on the parse path:
BabelFeeBoxState(TransactionBox)throwsIllegalStateExceptionforpricePerToken <= 0(same exception style as the token-id mismatch check in the same constructor).IllegalArgumentException, so no instance can carry a non-positive price. This is inert for existing callers: the builder validates first, andbuildSucceedingStatecopies an already-valid price.Boxes with a regular price parse and calculate exactly as before.
Test: new
BabelFeeSpecproperty "babel fee box with non-positive price is rejected" — it builds babel fee boxes with price 0 and −1 directly (bypassing the validating builder, the way an externally created box appears on chain) and asserts both are rejected, and that a regular price still parses and calculates. Ondevelopthe new property fails with "Expected exception IllegalStateException to be thrown, but no exception was thrown"; with the fix,BabelFeeSpecis 4/4 and the fullsbt testrun is green (appkit module: 96 tests, 0 failures, per the test reports; common: 18/18).Submitted by @Kshot9000 (https://x.com/kshot9000) · Tips: ERG
9fcM5RWnAjmP4vx5bnW6yohB6H9bLq8sJbaPLHtwZLtQPB32Pvy