Skip to content

Commit

Permalink
fix based ottersec report
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsource147 committed Aug 22, 2024
1 parent ea153bd commit af9f413
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
16 changes: 5 additions & 11 deletions programs/locker/src/instructions/create_vesting_escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ pub struct CreateVestingEscrowCtx<'info> {
)]
pub escrow: AccountLoader<'info, VestingEscrow>,

#[account(mut)]
#[account(
mut,
associated_token::mint = sender_token.mint,
associated_token::authority = escrow
)]
pub escrow_token: Box<Account<'info, TokenAccount>>,

#[account(mut)]
Expand Down Expand Up @@ -86,16 +90,6 @@ pub fn handle_create_vesting_escrow(

require!(frequency != 0, LockerError::FrequencyIsZero);

let escrow_token = anchor_spl::associated_token::get_associated_token_address(
&ctx.accounts.escrow.key(),
&ctx.accounts.sender_token.mint,
);

require!(
escrow_token == ctx.accounts.escrow_token.key(),
LockerError::InvalidEscrowTokenAddress
);

let mut escrow = ctx.accounts.escrow.load_init()?;
escrow.init(
vesting_start_time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// Accounts for [locker::update_vesting_escrow_recipient].
#[derive(Accounts)]
#[event_cpi]
pub struct UpdateVestingEscrowRecipientCtx<'info> {
/// Escrow.
#[account(mut)]
Expand Down Expand Up @@ -85,14 +86,14 @@ pub fn handle_update_vesting_escrow_recipient(
anchor_lang::system_program::transfer(cpi_context, lamports_diff)?;

// realloc
escrow_metadata_info.realloc(new_len, true)?;
escrow_metadata_info.realloc(new_len, false)?;
// update new recipient_email
escrow_metadata.recipient_email = recipient_email;
} else {
return Err(LockerError::InvalidEscrowMetadata.into());
}
}
emit!(EventUpdateVestingEscrowRecipient {
emit_cpi!(EventUpdateVestingEscrowRecipient {
escrow: ctx.accounts.escrow.key(),
signer,
old_recipient,
Expand Down
1 change: 0 additions & 1 deletion tests/locker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ describe("Full flow", () => {
updateRecipientMode: 0,
});


while (true) {
const currentBlockTime = await getCurrentBlockTime(program.provider.connection);
if (currentBlockTime > cliffTime.toNumber()) {
Expand Down
11 changes: 10 additions & 1 deletion tests/update_recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,22 @@ describe("Update recipient", () => {
isAssertion: true
});

console.log("Update recipient");
console.log("Update recipient with bigger email size");
await updateRecipient({
escrow,
newRecipient: ReceipentKP.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: "[email protected]",
});

console.log("Update recipient with smaller email size");
await updateRecipient({
escrow,
newRecipient: ReceipentKP.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: "[email protected]",
});
});
});

0 comments on commit af9f413

Please sign in to comment.