fix: cap maximum guardians to 9 in add_guardian - #75
Open
Ash739-ux wants to merge 1 commit into
Open
Conversation
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.
Closes #27
pr description
Context & Problem
Currently, the asset registry implements an explicit, documented cap (
MAX_ASSETS = 50) to keep the contract well within Soroban's ~100 KB instance storage ceiling. However, theadd_guardianfunction lacked an equivalent bound.The
Guardiansvector lives in instance storage, meaning it shares a very tight size budget with every other piece of contract instance state (Admin, PendingUpgrade, RecoveryConfig, etc.). Without a cap:Vec<Address>.require_guardian,add_guardianduplicate scans, andremove_guardianrebuilds require O(n) linear scans. An inflated guardian list makes the social recovery path progressively more expensive, potentially bricking the exact recovery mechanism the guardians are meant to protect.Solution
This PR introduces a strict upper bound to the guardian list, mirroring the protective design of the asset registry:
MAX_GUARDIANSConstant: Added and set to9. This value is consistent with realistic social-recovery configurations (which rarely exceed 5-9 members) while keeping instance storage consumption nominal and bounding O(n) scan costs.WalletError::GuardianLimitExceeded(code 1031).add_guardiannow explicitly checks the list length before allowing apush_backoperation.test_guardian_list_has_upper_boundto ensure that adding guardians up to the cap succeeds, but any subsequent addition properly triggers theGuardianLimitExceedederror.Impact