Skip to content

Feat: New Account Index Enforcement#23

Open
0xLeo-sqds wants to merge 14 commits into
policiesfrom
feat/implement-account-utilization
Open

Feat: New Account Index Enforcement#23
0xLeo-sqds wants to merge 14 commits into
policiesfrom
feat/implement-account-utilization

Conversation

@0xLeo-sqds
Copy link
Copy Markdown
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
Copy Markdown
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)

@0xLeo-sqds 0xLeo-sqds marked this pull request as ready for review January 27, 2026 21:30
@0xLeo-sqds 0xLeo-sqds force-pushed the feat/implement-account-utilization branch from 7f201ae to 976c890 Compare January 27, 2026 21:37
0xLeo-sqds and others added 11 commits January 27, 2026 23:02
- Regenerated SDK using solita to include missing `program` account parameter
- Updated incrementAccountIndex instruction calls in test files
- Fixed 12 out of 15 failing tests (from 0xbbd AccountNotEnoughKeys error)
- Remaining 3 failures are unrelated to SDK issue

The `program` account was added in commit c0ed7ef for event logging but
the SDK wasn't regenerated, causing tests to fail with error 0xbbd
(AccountNotEnoughKeys - instruction received 2 accounts instead of 3).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add account utilization tracking and restrictions
- Fix internal fund transfer validation
- Add error variants for audit findings
- Fix spending limit and transaction buffer checks
- Add accountIndexSpendingLimit test suite
- Add internalFundTransferDelegate test suite
- Add programInteractionExtensions test suite
- Restore full test suite imports
- Enable transpileOnly in tsconfig for faster test runs
Includes set_account_index, increment_account_index, and audit error variants
- Fix SmartAccountTransactionMessage to use beet.array() for stored
  state Vec<Pubkey> instead of smallArray (1-byte prefix)
- Update fix-smallvec.js to not re-break this on regeneration
- Add incrementAccountIndex calls in smart-account-sdk spending limit
  tests to unlock accountIndex 1 before use
Tests using vault indices > 0 need incrementAccountIndex calls after
smart account creation. Also fixes missing program param in existing
createIncrementAccountIndexInstruction calls.
# Conflicts:
#	sdk/smart-account/scripts/fix-smallvec.js
…ec-remediation-v2' into feat/implement-account-utilization

# Conflicts:
#	programs/squads_smart_account_program/src/state/policies/utils/account_tracking.rs
#	sdk/smart-account/scripts/fix-smallvec.js
#	tests/index.ts
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.

2 participants