Skip to content

Commit

Permalink
Check seed
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrena-Corto committed Oct 7, 2024
1 parent a371e23 commit dd0d07e
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions programs/thread/src/instructions/thread_delete.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
crate::state::*,
crate::{constants::SEED_THREAD, state::*},
anchor_lang::{prelude::*, solana_program::system_program},
sablier_network_program::errors::SablierError,
};
Expand Down Expand Up @@ -63,18 +63,36 @@ pub fn handler(ctx: Context<ThreadDelete>) -> Result<()> {

// Verify the account provided
let thread_account = &ctx.accounts.thread;
{
// Verify the account is initialized
require!(
thread_account.owner != &system_program::ID && thread_account.lamports() > 0,
SablierError::InvalidThreadAccount
);

// Verify the account is initialized
require!(
thread_account.owner != &system_program::ID && thread_account.lamports() > 0,
SablierError::InvalidThreadAccount
);
// Verify the account is owned by the program
require!(
thread_account.owner == &crate::ID,
SablierError::InvalidThreadAccount
);

// Verify the account is owned by the program
require!(
thread_account.owner == &crate::ID,
SablierError::InvalidThreadAccount
);
// Verify the seed derivation
let default_vec = Vec::new();
let thread_bump = thread.bump.to_le_bytes();
let seed = [
SEED_THREAD,
thread.authority.as_ref(),
thread.id.as_slice(),
thread.domain.as_ref().unwrap_or(&default_vec).as_slice(),
thread_bump.as_ref(),
];
let expected_thread_key = Pubkey::create_program_address(&seed, &crate::ID)
.map_err(|_| SablierError::InvalidThreadAccount)?;
require!(
expected_thread_key == *thread_key,
SablierError::InvalidThreadAccount
);
}
}

// Transfer lamports out (implicit close)
Expand Down

0 comments on commit dd0d07e

Please sign in to comment.