fix: critical auth bypass, O(1) state optimization and TTL rent management#62
Open
davicf400 wants to merge 1 commit into
Open
fix: critical auth bypass, O(1) state optimization and TTL rent management#62davicf400 wants to merge 1 commit into
davicf400 wants to merge 1 commit into
Conversation
|
@davicf400 is attempting to deploy a commit to the mericcintosun Team on Vercel. A member of the Team first needs to authorize it. |
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.
Description
This PR addresses three critical architectural and security vulnerabilities in the
RiskTierContract: access control bypass, state bloat (DoS risk), and state archival prevention (TTL management). These fixes ensure the contract is secure, scalable, and ready for Soroban mainnet deployment.Key Changes & Security Fixes
1. Critical: Auth Bypass in
update_chosen_tieruseraddress parameter but lacked authentication validation. A malicious actor could pass another user's address and forcibly downgrade their chosen tier toTIER_3, potentially triggering unfair liquidations in partner protocols.user.require_auth();to ensure the transaction is securely signed by the actual user modifying their tier.env.mock_all_auths()to support the new security assertion.2. High: State Bloat & CPU Budget Exhaustion (O(1) Optimization)
Vec<Address>). Iterating over this array with.contains()to prevent duplicates creates anVecwith an(tier, "is_member", user)to efficiently prevent duplicate entries.u32counter(tier, "count")to keepget_tier_statsoperational and cheap.get_tier_usersas indexing dynamic lists on-chain is a Soroban anti-pattern (indexers/events should handle this off-chain).3. High: State Archival / Rent Management
DAY_IN_LEDGERS,BUMP_AMOUNT(30 days), andLIFETIME_THRESHOLDconstants. Injectedextend_ttl()calls into all state-modifying and state-reading functions to ensure active scores remain alive indefinitely.4. CI/CD Pipeline Fix
features = ["testutils"]todev-dependenciesinCargo.tomlso the test suite can properly compile and utilizeAddress::generate()without being configured out.Testing
cargo test).test_get_tier_statsto ensure complete backwards compatibility with the existing frontend logic.