Skip to content

Conversation

@0xLeo-sqds
Copy link
Collaborator

Implements vault index restriction to control which sub-accounts (vaults) can be used for transactions.

Overview

  • User accounts (0-250): Must be unlocked sequentially via increment_account_index instruction
  • Reserved accounts (251-255): Bypass validation, always available

Program Changes

New Instruction: increment_account_index
• Increments account_utilization field by 1, unlocking the next vault index
• Callable by any signer with Initiate, Vote, or Execute permission
• 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 250

Validation 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 transactions

Constants (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

@0xLeo-sqds
Copy link
Collaborator Author

Additional changes in commit 5f93ea4:

Rust (Program):
• payloads.rs: Added validate_account_indices() method to PolicyCreationPayload that extracts account indices from each policy type and validates them against settings
• settings.rs: Added validate_account_indices_unlocked() helper + calls to validate indices during PolicyCreate and PolicyUpdate execution

Tests:
• policyCreation.ts: Added increment loops to unlock indices 1-3 for existing test + new test for AccountIndexLocked error on policy create
• policyUpdate.ts: Added increment loops + new test for AccountIndexLocked error on policy update
• tests/index.ts: Enabled policyCreation and policyUpdate test suites

While running some tests caught a regression on the SDK that i created in the last PR so here's the SDK changes:
• fix-smallvec.js: Fixed CompiledHook.instructionData to use u16 length prefix (was incorrectly u8)
• CompiledHook.ts: Regenerated with correct smallArray(beet.u16, beet.u8)
• closeTransactionBuffer.ts + IDL: Regenerated (unrelated upstream changes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant