security: gate pda-mint-authority native and pinocchio mint_to behind the token's original creator - #699
Open
kartsan03 wants to merge 1 commit into
Conversation
… the token's original creator solana-foundation#692 gated the anchor variant. The native and pinocchio siblings still let any caller mint the NFT because the mint-authority PDA signs unconditionally. Record the create_token payer in a per-mint config PDA and reject mint_to from anyone else, before the master edition is created.
Contributor
Greptile SummaryThe PR closes unauthorized first-mint front-running in the native and Pinocchio PDA mint-authority examples.
Confidence Score: 5/5The PR appears safe to merge with the new creator authorization consistently enforced across both implementations and their clients. The per-mint PDA derivation, stored administrator layout, signer checks, ownership checks, account ordering, and client inputs are aligned, and no concrete blocking or non-blocking defect remains. Important Files Changed
Reviews (1): Last reviewed commit: "security: gate pda-mint-authority native..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#692 gated
mint_tokenintokens/pda-mint-authorityanchor behind aMintConfigPDA. That PR's write-up already flagged the leftover on the siblings:That leftover is still unfixed. In both variants the mint authority is a program PDA (
seeds = [b"mint_authority"]) thatinvoke_signeds theMintToCPI for whoever callsmint_to. There is no check that the caller is the wallet that paidcreate_token. Anyone who sees a freshly created mint can mint the NFT to themselves.Unlike the anchor bug this is bounded to one NFT per mint (the subsequent Metaplex Master Edition CPI takes over mint/freeze authority), but it is still unauthorized first-mint / front-running of the creator, and it is still the same "PDA signs unconditionally for whoever calls" hole #692 closed on the other variant.
This PR does not change the teaching point (PDA as mint authority +
invoke_signed). It only records thecreate_tokenpayer in a per-mintMintConfigPDA (seeds = [b"mint_config", mint]) and rejectsmint_tounless the caller matches that admin.The PDA is bound to the mint (unlike the anchor variant's global
[b"mint_config"]) because native/pinocchio create one mint percreate_tokencall, not a single program-wide mint.Fix
create_tokencreates[b"mint_config", mint]owned by the program and writesadmin = payer.mint_tore-derives that PDA, checks program ownership, and returnsInvalidArgumentifadmin != payer.payer.is_signer; pinocchio does the same viapayer.is_signer().mint_configis writable on create (account is allocated there) and readonly on mint.Test changes
Added a negative test in both
native/tests/test.tsandpinocchio/tests/test.ts.The existing happy-path mint already creates a Metaplex Master Edition, which would make a second
mint_toon the same mint fail even without the admin check. The new tests therefore:create_tokena fresh mint as the original payermint_toon that mintFailedTransactionMetadataThe Create tests also assert the new config PDA exists and is owned by the program.
Verification
From WSL Ubuntu (
cargo-build-sbf 4.1.0,pnpm 10.33.0):Out of scope