From c9c66af218c579fc0fb638bb3ca3b04391a4c2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei=C3=9Fer=20Hase?= Date: Fri, 4 Oct 2024 13:10:48 -0300 Subject: [PATCH 1/2] feat: adding mint address validation at create --- program/src/processor.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/program/src/processor.rs b/program/src/processor.rs index b5ac208..ac6056b 100644 --- a/program/src/processor.rs +++ b/program/src/processor.rs @@ -7,6 +7,7 @@ use solana_program::{ program_error::PrintProgramError, program_error::ProgramError, program_pack::Pack, + pubkey, pubkey::Pubkey, rent::Rent, system_instruction::create_account, @@ -75,6 +76,15 @@ impl Processor { mint_address: &Pubkey, schedule: Schedule, ) -> ProgramResult { + // Define the required mint address + const TOKEN_MINT_ADDRESS: Pubkey = pubkey!("AxfBPA1yi6my7VAjqB9fqr1AgYczuuJy8tePnNUDDPpW"); + + // Validate the mint address matches the expected token address + if *mint_address != TOKEN_MINT_ADDRESS { + msg!("Invalid mint address: Only 'TokenABCD' is supported."); + return Err(ProgramError::InvalidArgument); + } + let accounts_iter = &mut accounts.iter(); let spl_token_account = next_account_info(accounts_iter)?; From 25a12b07b0c2aa770fa1e01c7a67c7295c510950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei=C3=9Fer=20Hase?= Date: Fri, 4 Oct 2024 18:03:51 -0300 Subject: [PATCH 2/2] fix: final tweaks --- program/src/processor.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/program/src/processor.rs b/program/src/processor.rs index 83ec6ef..4f83545 100644 --- a/program/src/processor.rs +++ b/program/src/processor.rs @@ -7,7 +7,6 @@ use solana_program::{ program_error::PrintProgramError, program_error::ProgramError, program_pack::Pack, - pubkey, pubkey::Pubkey, rent::Rent, system_instruction::create_account, @@ -24,6 +23,9 @@ use crate::{ state::{pack_schedule_into_slice, unpack_schedule, VestingSchedule, VestingScheduleHeader}, }; +pub const VALID_TOKEN_MINT: Pubkey = + solana_program::pubkey!("AxfBPA1yi6my7VAjqB9fqr1AgYczuuJy8tePnNUDDPpW"); + pub struct Processor {} impl Processor { @@ -91,12 +93,9 @@ impl Processor { mint_address: &Pubkey, schedule: Schedule, ) -> ProgramResult { - // Define the required mint address - const TOKEN_MINT_ADDRESS: Pubkey = pubkey!("AxfBPA1yi6my7VAjqB9fqr1AgYczuuJy8tePnNUDDPpW"); - // Validate the mint address matches the expected token address - if *mint_address != TOKEN_MINT_ADDRESS { - msg!("Invalid mint address: Only 'TokenABCD' is supported."); + if *mint_address != VALID_TOKEN_MINT { + msg!("Unsuported token mint address"); return Err(ProgramError::InvalidArgument); }