mock-amm.initialize doesn't validate rate_bps bounds - #68
Closed
Johnpii1 wants to merge 4 commits into
Closed
Conversation
…-amm.initialize Validate mock AMM initialize rate bounds
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Adds validation for the mock AMM pool rate during initialization to prevent invalid configurations that could result in zero-value swap outputs or arithmetic overflows.
The initialization flow now enforces explicit minimum and maximum rate bounds and returns a clear error when the provided rate is outside the supported range.
Closes #22
Type of change
Checklist
Branch is based on the latest
mainand the PR targetsmain.Local checks pass:
cargo test -p mock-ammNo secrets, keys, or
.envfiles are committed.Tests cover the new validation behavior.
CHANGELOG.mdupdated if required.COMPATIBILITY.md/protocol-versions.jsonnot applicable.Policy documentation not applicable.
Impact
This change improves mock AMM safety by preventing invalid pool-rate configuration at initialization.
rate_bps = 0is rejected to prevent swaps from producing consistently zero outputs.1,000,000BPS are rejected to prevent unreasonable configurations and potential arithmetic overflow scenarios.Admin,TokenIn,TokenOut, andRatestorage entries normally.Changes
Added
MIN_RATE_BPS: u32 = 1.Added
MAX_RATE_BPS: u32 = 1_000_000.Added the
Error::InvalidRateerror variant.Updated
initializeto returnResult<(), Error>.Added rate validation before persisting initialization state.
Invalid rates now return
Err(Error::InvalidRate).Valid rates return
Ok(())and preserve the existing storage behavior.Added unit tests for:
Added Soroban test snapshots covering invalid initialization cases.
Testing
Test Command
cargo test -p mock-ammTest Results
The new tests verify:
Screenshots / logs
No UI changes. Test output is provided above.
Additional context
The validation is performed during initialization so invalid pool configuration cannot be persisted. Existing valid initialization behavior remains unchanged.