Add Token-2022 default-account-state Pinocchio example#652
Open
MarkFeder wants to merge 1 commit into
Open
Conversation
Ports the default-account-state Token-2022 example to Pinocchio, matching the mint-close-authority template (kit + litesvm, official @solana-program packages, real Rent::get()). The program hand-rolls two DefaultAccountStateExtension (variant 28) CPIs around InitializeMint: it initializes the default state to Frozen before the mint is initialized, then updates it to Initialized afterwards (which the freeze authority signs). Mint size is 171 bytes (one 1-byte AccountState TLV value). The litesvm test decodes the mint with the official Token-2022 codec and asserts the stored default state is Initialized.
Greptile SummaryAdds a Pinocchio implementation of the Token-2022 default-account-state example.
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness or security defects identified. The program preserves Token-2022's required initialization ordering, uses the documented shared payer and authority account relationship, and the integration test validates the resulting mint and extension state. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Example as Pinocchio Program
participant System as System Program
participant Token as Token-2022
Client->>Example: CreateMint(decimals)
Example->>System: Create 171-byte mint account
Example->>Token: Initialize DefaultAccountState(Frozen)
Example->>Token: InitializeMint(authority, freeze authority)
Example->>Token: Update DefaultAccountState(Initialized)
Token-->>Example: Mint configured
Example-->>Client: Success
Reviews (1): Last reviewed commit: "token-2022 default-account-state: add pi..." | 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.
What
Adds a Pinocchio implementation of the Token-2022
default-account-stateexample, alongside the existinganchorandnativeversions. This continues the Token-2022 Pinocchio sub-series (aftermint-close-authority#624 andnon-transferable#630) and follows the same kit + litesvm + official-@solana-program-packages template.How it works
The single instruction creates a Token-2022 mint carrying the
DefaultAccountStateextension. New token accounts for the mint inherit this default state, so aFrozendefault requires the freeze authority to thaw each account before use.To exercise both extension instructions (mirroring the
nativeexample), the program hand-rolls twoDefaultAccountStateExtension(variant28) CPIs aroundInitializeMint:Initializethe default state toFrozen— beforeInitializeMint(extensions must be initialized before the mint).Updatethe default state toInitialized— afterInitializeMint, signed by the mint's freeze authority.The mint authority doubles as the freeze authority and is supplied as the same key as the payer, so a single signature covers funding the account and signing the update. The extended mint is 171 bytes (base 166 + a 5-byte TLV entry whose value is a single
AccountStatebyte).Test
litesvm+@solana/kit. The test builds the mint, then decodes it with the official@solana-program/token-2022codec and asserts:decimals, andDefaultAccountStateextension's stored state isInitialized.Verified locally:
cargo build-sbf,ts-mocha,tsc --noEmit, biome,cargo fmt --check, clippy, andpnpm install --frozen-lockfileall clean.