Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix based ottersec report #10

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 5 additions & 2 deletions tests/escrow_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
import { claimToken, createEscrowMetadata, createLockerProgram, createVestingPlan } from "./locker_utils";


const provider = anchor.AnchorProvider.env();
let provider = anchor.AnchorProvider.env();
provider.opts.commitment = 'confirmed';

describe("Escrow metadata", () => {
const tokenDecimal = 8;
Expand All @@ -41,7 +42,9 @@ describe("Escrow metadata", () => {
null,
tokenDecimal,
web3.Keypair.generate(),
null,
{
commitment: "confirmed",
},
TOKEN_PROGRAM_ID
);

Expand Down
8 changes: 5 additions & 3 deletions tests/locker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
import { claimToken, createLockerProgram, createVestingPlan } from "./locker_utils";


const provider = anchor.AnchorProvider.env();
let provider = anchor.AnchorProvider.env();
provider.opts.commitment = 'confirmed';

describe("Full flow", () => {
const tokenDecimal = 8;
Expand All @@ -42,7 +43,9 @@ describe("Full flow", () => {
null,
tokenDecimal,
web3.Keypair.generate(),
null,
{
commitment: "confirmed",
},
TOKEN_PROGRAM_ID
);

Expand Down Expand Up @@ -110,7 +113,6 @@ describe("Full flow", () => {
updateRecipientMode: 0,
});


while (true) {
const currentBlockTime = await getCurrentBlockTime(program.provider.connection);
if (currentBlockTime > cliffTime.toNumber()) {
Expand Down
1 change: 1 addition & 0 deletions tests/locker_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function createLockerProgram(
const provider = new AnchorProvider(AnchorProvider.env().connection, wallet, {
maxRetries: 3,
});
provider.opts.commitment = 'confirmed';
const program = new Program<Locker>(LockerIDL, LOCKER_PROGRAM_ID, provider);
return program;
}
Expand Down
16 changes: 14 additions & 2 deletions tests/update_recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { claimToken, createEscrowMetadata, createLockerProgram, createVestingPla


const provider = anchor.AnchorProvider.env();
provider.opts.commitment = 'confirmed';

describe("Update recipient", () => {
const tokenDecimal = 8;
Expand All @@ -42,7 +43,9 @@ describe("Update recipient", () => {
null,
tokenDecimal,
web3.Keypair.generate(),
null,
{
commitment: "confirmed",
},
TOKEN_PROGRAM_ID
);

Expand Down Expand Up @@ -261,13 +264,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]",
});
});
});
Loading