Feat: New Account Index Enforcement #23
Draft
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.
Implements vault index restriction to control which sub-accounts (vaults) can be used for transactions.
Overview
increment_account_indexinstructionProgram Changes
New Instruction:
increment_account_index• Increments
account_utilizationfield by 1, unlocking the next vault index• Callable by any signer with
Initiate,Vote, orExecutepermission• Cannot exceed index 250 (because that's for reserved account)
New Errors:
•
AccountIndexLocked- when trying to use a vault index that hasn't been unlocked•
MaxAccountIndexReached- when trying to increment beyond 250Validation Enforcement:
•
transaction_create.rs- validates account index when creating async transactions•
transaction_execute_sync.rs- validates for Settings-based sync transactions•
transaction_execute_sync_legacy.rs- validates for legacy sync transactionsConstants (in
state/settings.rs):• FREE_ACCOUNT_MAX_INDEX = 250
• RESERVED_ACCOUNT_START = 251
Tests
8 new tests:
incrementAccountIndex.ts:• Increment successfully (0→1)
• Increment multiple times (0→3)
• Non-signer cannot increment
• Proposer/Voter/Executor can increment (permission tests)
• Cannot increment beyond max index 250
transactionSynchronous.ts:• Sync transaction with locked index fails
• Reserved index (251) bypasses validation
transactionCreateFromBuffer.ts:• Creating transaction with locked index fails