From 4a8e9d3d840727616734ea1facb455c2da40c6d7 Mon Sep 17 00:00:00 2001 From: nheingit <60185486+nheingit@users.noreply.github.com> Date: Tue, 12 Jul 2022 17:43:08 -0500 Subject: [PATCH] update secure pda example --- programs/8-pda-sharing/secure/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/programs/8-pda-sharing/secure/src/lib.rs b/programs/8-pda-sharing/secure/src/lib.rs index 066be29..65a7170 100644 --- a/programs/8-pda-sharing/secure/src/lib.rs +++ b/programs/8-pda-sharing/secure/src/lib.rs @@ -13,6 +13,13 @@ pub mod pda_sharing_secure { ctx.accounts.pool.withdraw_destination.as_ref(), &[ctx.accounts.pool.bump], ]; + let (address, expected_bump) = Pubkey::find_program_address(seeds, ctx.program_id); + if address != ctx.accounts.pool.key() { + return Err(ProgramError::InvalidArgument); + } + if expected_bump != ctx.accounts.pool.bump { + return Err(ProgramError::InvalidArgument); + } token::transfer(ctx.accounts.transfer_ctx().with_signer(&[seeds]), amount) } }