Skip to content

Commit

Permalink
token-2022: Zeroize account data on close (#2764)
Browse files Browse the repository at this point in the history
* token-2022: Zeroize account data on close

* Address feedback
  • Loading branch information
joncinque committed Jan 21, 2022
1 parent 81f5012 commit f5a6dc6
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 62 deletions.
13 changes: 12 additions & 1 deletion token/program-2022/src/lib.rs
Expand Up @@ -16,7 +16,12 @@ mod entrypoint;

// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;
use solana_program::{entrypoint::ProgramResult, program_error::ProgramError, pubkey::Pubkey};
use solana_program::{
entrypoint::ProgramResult,
program_error::ProgramError,
program_memory::sol_memcmp,
pubkey::{Pubkey, PUBKEY_BYTES},
};

/// Convert the UI representation of a token amount (using the decimals field defined in its mint)
/// to the raw amount
Expand All @@ -38,3 +43,9 @@ pub fn check_program_account(spl_token_program_id: &Pubkey) -> ProgramResult {
}
Ok(())
}

/// Checks two pubkeys for equality in a computationally cheap way using
/// `sol_memcmp`
pub fn cmp_pubkeys(a: &Pubkey, b: &Pubkey) -> bool {
sol_memcmp(a.as_ref(), b.as_ref(), PUBKEY_BYTES) == 0
}

0 comments on commit f5a6dc6

Please sign in to comment.