Skip to content

Commit 7f201ae

Browse files
committed
feat: added account index check on batch create as well
1 parent 5f93ea4 commit 7f201ae

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

programs/squads_smart_account_program/src/instructions/batch_create.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ pub struct CreateBatch<'info> {
4545
}
4646

4747
impl CreateBatch<'_> {
48-
fn validate(&self) -> Result<()> {
48+
fn validate(&self, args: &CreateBatchArgs) -> Result<()> {
4949
let Self {
5050
settings,
5151
creator,
5252
..
5353
} = self;
5454

55+
settings.validate_account_index_unlocked(args.account_index)?;
56+
5557
// creator
5658
require!(
5759
settings.is_signer(creator.key()).is_some(),
@@ -66,7 +68,7 @@ impl CreateBatch<'_> {
6668
}
6769

6870
/// Create a new batch.
69-
#[access_control(ctx.accounts.validate())]
71+
#[access_control(ctx.accounts.validate(&args))]
7072
pub fn create_batch(ctx: Context<Self>, args: CreateBatchArgs) -> Result<()> {
7173
let settings = &mut ctx.accounts.settings;
7274
let creator = &mut ctx.accounts.creator;

programs/squads_smart_account_program/src/state/settings.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ use crate::{
1919
pub const MAX_TIME_LOCK: u32 = 3 * 30 * 24 * 60 * 60; // 3 months
2020

2121
// Account index constants
22-
// Free accounts: 0-250 (251 accounts)
23-
// Reserved accounts: 251-255 (5 accounts) - bypass index validation
24-
pub const FREE_ACCOUNT_MAX_INDEX: u8 = 250;
25-
pub const RESERVED_ACCOUNT_START: u8 = 251;
22+
// Free accounts: 0-249 (250 accounts)
23+
// Reserved accounts: 250-255 (6 accounts) - bypass index validation
24+
pub const FREE_ACCOUNT_MAX_INDEX: u8 = 249;
2625

2726
#[account]
2827
pub struct Settings {
@@ -740,10 +739,10 @@ impl Settings {
740739
}
741740

742741
/// Validates that the given account index is unlocked.
743-
/// Reserved accounts (251-255) bypass this check.
742+
/// Reserved accounts (250-255) bypass this check.
744743
pub fn validate_account_index_unlocked(&self, index: u8) -> Result<()> {
745-
// Reserved accounts (251-255) bypass the check
746-
if index >= RESERVED_ACCOUNT_START {
744+
// Reserved accounts (250-255) bypass the check
745+
if index > FREE_ACCOUNT_MAX_INDEX {
747746
return Ok(());
748747
}
749748
require!(

0 commit comments

Comments
 (0)