Skip to content

Commit

Permalink
feat(SQ-002): add sanity checks in realloc_if_needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacodes committed Oct 24, 2023
1 parent 5d222a6 commit fecbb0e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions programs/squads_multisig_program/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ pub enum MultisigError {
ProtectedAccount,
#[msg("Time lock exceeds the maximum allowed (90 days)")]
TimeLockExceedsMaxAllowed,
#[msg("Account is not owned by Multisig program")]
IllegalAccountOwner,
}
9 changes: 9 additions & 0 deletions programs/squads_multisig_program/src/state/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anchor_lang::prelude::*;
use anchor_lang::system_program;

use crate::errors::*;
use crate::id;

pub const MAX_TIME_LOCK: u32 = 3 * 30 * 24 * 60 * 60; // 3 months

Expand Down Expand Up @@ -82,6 +83,14 @@ impl Multisig {
rent_payer: AccountInfo<'a>,
system_program: AccountInfo<'a>,
) -> Result<bool> {
// Sanity checks
require_keys_eq!(
*system_program.key,
system_program::ID,
MultisigError::InvalidAccount
);
require_keys_eq!(*multisig.owner, id(), MultisigError::IllegalAccountOwner);

let current_account_size = multisig.data.borrow().len();
let account_size_to_fit_members = Multisig::size(members_length);

Expand Down
5 changes: 5 additions & 0 deletions sdk/multisig/idl/squads_multisig_program.json
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,11 @@
"code": 6030,
"name": "TimeLockExceedsMaxAllowed",
"msg": "Time lock exceeds the maximum allowed (90 days)"
},
{
"code": 6031,
"name": "IllegalAccountOwner",
"msg": "Account is not owned by Multisig program"
}
],
"metadata": {
Expand Down
23 changes: 23 additions & 0 deletions sdk/multisig/src/generated/errors/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fecbb0e

Please sign in to comment.