feat(contracts): rounding policy, queue safety, packed storage, rescu… - #1012
Merged
Merged
Conversation
…e flow Closes Junirezz#971, Junirezz#961, Junirezz#965, Junirezz#964. Junirezz#971 — Deterministic rounding policy and cross-language fixtures share-price-math/src/rounding.rs: explicit Rounding{Down,Up} and Op {Deposit,Mint,Withdraw,Redeem}, a checked mul_div, and conversion helpers that apply the policy direction per operation (deposit/redeem round down, mint/withdraw round up) so rounding dust always stays with the vault. FIXTURES is the canonical conformance table, mirrored verbatim by fixtures/rounding_fixtures.json for the TS SDK and backend quote service. Junirezz#961 — Withdrawal queue safety checks for edge-case liquidity vault/src/withdrawal_queue_safety.rs: check_queue_admission() is a pure pre-queue guard covering non-positive and overflowing requests, corrupt balances, requests beyond idle liquidity, and requests that would draw down the reserve buffer. max_admissible() exposes the same boundary as a hint for callers. Junirezz#965 — Storage layout optimized for reduced gas vault/src/packed_storage.rs: the four u32 scalar params (fee, liquidity buffer, cooldown, batch size) share one u128 word, collapsing four storage reads and four rent-bearing keys into one. Per-field accessors let hot paths read a single value without materialising the struct. Junirezz#964 — Emergency rescue flow with strict authorization vault/src/emergency_rescue.rs: rescue requires a signature from one of two configured, distinct emergency approvers; the vault's underlying asset is never rescuable, so user deposits stay out of reach. check_rescue_ authorization() is pure and unit-tested; authorize_rescue() binds it to stored approvers and require_auth(). Tests: 36 new unit tests (6 rounding + 30 vault-module). Note: the Soroban error-enum spec caps VaultError at 50 cases and the enum was already at 49, so only RescueUnauthorized was added; the remaining new failure paths reuse MathOverflow, GovernanceSignersNotConfigured and InvalidAmount. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@Otaiki1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
…e flow
Closes #971 ,
closes #961 ,
closes #965 ,
closes #964 .
#971 — Deterministic rounding policy and cross-language fixtures
share-price-math/src/rounding.rs: explicit Rounding{Down,Up} and Op
{Deposit,Mint,Withdraw,Redeem}, a checked mul_div, and conversion helpers
that apply the policy direction per operation (deposit/redeem round down,
mint/withdraw round up) so rounding dust always stays with the vault.
FIXTURES is the canonical conformance table, mirrored verbatim by
fixtures/rounding_fixtures.json for the TS SDK and backend quote service.
#961 — Withdrawal queue safety checks for edge-case liquidity
vault/src/withdrawal_queue_safety.rs: check_queue_admission() is a pure
pre-queue guard covering non-positive and overflowing requests, corrupt
balances, requests beyond idle liquidity, and requests that would draw
down the reserve buffer. max_admissible() exposes the same boundary as a
hint for callers.
#965 — Storage layout optimized for reduced gas
vault/src/packed_storage.rs: the four u32 scalar params (fee, liquidity
buffer, cooldown, batch size) share one u128 word, collapsing four storage
reads and four rent-bearing keys into one. Per-field accessors let hot
paths read a single value without materialising the struct.
#964 — Emergency rescue flow with strict authorization
vault/src/emergency_rescue.rs: rescue requires a signature from one of two
configured, distinct emergency approvers; the vault's underlying asset is
never rescuable, so user deposits stay out of reach. check_rescue_
authorization() is pure and unit-tested; authorize_rescue() binds it to
stored approvers and require_auth().
Tests: 36 new unit tests (6 rounding + 30 vault-module).
Note: the Soroban error-enum spec caps VaultError at 50 cases and the enum was already at 49, so only RescueUnauthorized was added; the remaining new failure paths reuse MathOverflow, GovernanceSignersNotConfigured and InvalidAmount.
Pull Request Template
📋 Description
Add a complete environment variable matrix (
docs/ENV_VARIABLE_MATRIX.md) covering every env var consumed across the backend and frontend, with defaults, required flags, and production recommendations. UpdateREADME.mdandENV_QUICK_REFERENCE.mdto link to the new document.🔗 Type of Change
🔒 SECURITY REVIEW (⭐ MANDATORY FOR SMART CONTRACT CHANGES)
For all smart contract code changes, complete the following checklist.
See
docs/SECURITY_CHECKLIST.mdfor detailed guidance.Required: Security Checklist Sign-Off
I have reviewed this PR against the Internal Security Checklist (
docs/SECURITY_CHECKLIST.md)onlyOwner,onlyRole(), etc.)require(success, ...))If any checkbox cannot be verified, explain below:
Slither Static Analysis Results
Ran Slither locally:
slither . --config-file slither.config.jsonGitHub Actions Slither workflow passed:
If this PR has security findings, document them below:
Handling Security Findings
Option A: Fixed in This PR ✅
Option B: False Positive 🟡
contracts/.false-positives.mdwith:Option C: Accepted Risk⚠️
📝 Testing
Functional Testing
Security Testing
For state-changing functions:
For external integrations:
Test Coverage
N/A — documentation only, no executable code added🚀 Deployment Notes
No deployment steps required. This PR adds a Markdown file and updates two existing Markdown files only.
Mainnet Readiness
Breaking Changes
If this PR introduces breaking changes:
[timeframe]📊 Automated Scan Results
Slither Analysis
Related Documentation
✅ Reviewer Checklist
For code reviewers (use this to guide your security-focused review):
📞 Questions or Issues?
docs/SECURITY_CHECKLIST.mddocs/FALSE_POSITIVE_HANDLING.md@security-teamin comments📋 Pre-Submit Checklist
Before marking PR as ready for review:
npm testnpm run lintslither . --config-file slither.config.jsondocs/RELEASE_READINESS_CHECKLIST.mdcompleted and linked in PR description✅ Ready for Review? Ensure all items above are checked before requesting review.