Skip to content

Commit

Permalink
Add close authority check
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Nov 22, 2023
1 parent 9a6623d commit 8f6f29c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion programs/token-metadata/program/src/processor/metadata/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
program::{invoke, invoke_signed},
program_option::COption,
pubkey::Pubkey,
};
use spl_token_2022::state::{Account, Mint as MintAccount};
Expand Down Expand Up @@ -128,14 +129,34 @@ pub fn mint_v1(program_id: &Pubkey, ctx: Context<Mint>, args: MintArgs) -> Progr
],
)?;
} else {
validate_token(
let token = validate_token(
ctx.accounts.mint_info,
ctx.accounts.token_info,
ctx.accounts.token_owner_info,
ctx.accounts.spl_token_program_info,
metadata.token_standard,
None, // we already checked the supply of the mint account
)?;

// validates that the close authority on the token is either None
// or the master edition account for programmable assets

if let COption::Some(close_authority) = token.close_authority {
let invalid = if let Some(master_edition) = ctx.accounts.master_edition_info {
close_authority != *master_edition.key
} else {
// the close authority must match the master edition if there is one set
matches!(
metadata.token_standard,
Some(TokenStandard::ProgrammableNonFungible)
| Some(TokenStandard::ProgrammableNonFungibleEdition)
)
};

if invalid {
return Err(MetadataError::InvalidCloseAuthority.into());
}
}
}

let token = unpack_initialized::<Account>(&ctx.accounts.token_info.data.borrow())?;
Expand Down

0 comments on commit 8f6f29c

Please sign in to comment.