Solana OS p-token PoC

p-token — Anza's Pinocchio rewrite of the SPL Token program (SIMD-0266), live on mainnet at the same program id TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA with a byte-compatible instruction set — modeled in pure Lean 4 as Poc/PToken.lean: the full core instruction semantics plus p-token's three additions, with the safety claims as kernel-checked theorems. Pinocchio stays exactly as it is; this gives its token semantics a machine-checked specification.

The core instruction set — SPL-compatible semantics

State is a list of Mint records (supply, decimals, mint/freeze authorities as options — none once renounced, initialized flag, lamports + rent-exempt reserve) and Account records (mint, owner, amount, delegate with remaining allowance, close authority, frozen flag, lamports), plus a wallet lamport ledger that the lamport-moving instructions pay into. Keys are Nat ids, this repo's convention.

transfer — owner-or-delegate authorization, same mint, neither side frozen, sufficient funds. The debit lands before the credit is computed, so a self-transfer nets to zero, as on-chain. A delegate's allowance decreases by exactly the amount and is cleared at zero — SPL's rule, modeled in afterSpend. transferChecked / mintToChecked additionally require the instruction's decimals to equal the mint's.

mintTo — mint-authority-signed only, unfrozen destination; supply rises by exactly the amount. burn — owner-or-delegate, unfrozen; amount and supply drop together. approve / revoke — owner-signed delegate management. setAuthority — mint kinds (mintTokens, freezeAccount) signed by the current authority of that kind; account kinds (accountOwner — the new owner is a key, never none — and closeAccount). Setting a mint authority to none renounces it irreversibly. freezeAccount / thawAccount — the mint's freeze authority only. closeAccount — zero balance, owner- or close-authority-signed; the account is removed and its lamports are paid to the destination wallet.

The three p-token additions (SIMD-0266)

batch (discriminator 255) — one instruction carrying a list of sub-instructions, executed in order, all-or-nothing: any failure returns none and the caller's state is untouched. There is deliberately no batch constructor inside the sub-instruction type, so a batch cannot contain a batch — matching the program, which forbids nested batches.

withdrawExcessLamports — an account (or mint) holding lamports above its rent-exempt reserve withdraws the excess: the token-account form is owner-signed and pays the owner's wallet; the mint form is mint-authority-signed and pays the authority's wallet. The reserve stays behind, exactly.

unwrapLamports — native (wrapped-SOL) mints only, owner-signed: the token amount, the mint supply, and the account's lamports each drop by the unwrapped amount, the owner's wallet gains the same amount, and the rent-exempt reserve must remain.

Why p-token — Anza's published compute figures

Instructionp-tokenSPL Token
transfer76 CU4,645 CU
transferChecked105 CU6,200 CU
mintTo119 CU4,538 CU

Reference points from Anza's p-token materials (solana.com/upgrades/p-token, SIMD-0266) — cited, not measured by this model, which has no compute meter. The point of this PoC is the other half of the story: the cheaper program's semantics, pinned down as theorems.

Theorems — status in Lean (Poc/PToken.lean, 48 total)

transfer_mints · transfer_sumMintPROVED — a transfer never touches the mint table, and it preserves the sum of all account balances of every mint (debit and credit are the same amount of the same mint; a self-transfer nets to zero). (a)

mintTo_supplyPROVED — a successful mintTo increases supply by exactly the amount. Together with the per-instruction preservation lemmas approve_mints · revoke_mints · freeze_mints · thaw_mints · close_mints (mint table untouched) and setMintAuthority_supply (authority change only), mintTo is the only balance instruction that changes supply. (b)

burn_supplyPROVED — a successful burn decreases supply by exactly the amount (and supply-after + amount = supply-before when amount ≤ supply). (c)

transfer_unauthorized · transfer_delegate_overspend · transfer_delegate_allowance · transfer_delegate_cleared · transfer_amountsPROVED — a signer who is neither owner nor delegate can never transfer; a delegate can never overspend its allowance; a successful delegate transfer decreases the allowance by exactly the amount, and clears the delegate when the allowance is spent exactly; a successful transfer lands the exact debit and credit. (d)

transfer_frozen_src · transfer_frozen_dst · mintTo_frozen · burn_frozen · freeze_unauthorized · freeze_facts · thaw_factsPROVED — frozen accounts cannot send, receive, be minted to, or burn; freezing by anyone but the mint's freeze authority always fails; successful freeze/thaw set the flag. (e)

transferChecked_decimals · mintToChecked_decimalsPROVED — the checked variants always fail on a decimals mismatch. (f)

close_nonzero · close_unauthorized · close_factsPROVED — closing a nonzero-balance account always fails; closing signed by anyone but the owner and the close authority always fails; a successful close pays the account's lamports to the destination wallet, exactly. (g)

batch_nil · batch_cons_success · batch_fail_first · batch_fail_restPROVED — the empty batch is the identity; a batch whose head succeeds is sequential composition; if the first sub-instruction fails — or the tail batch fails from the intermediate state, at any depth — the whole batch returns none: atomicity. (h)

mintTo_no_authority · mintTo_unauthorized · renounce_mintToPROVED — with the mint authority gone (or a wrong signer), mintTo always fails; and after setMintAuthority renounces the mint authority to none, mintTo fails on the resulting state for every signer, destination, and amount — renunciation is forever. (i)

withdrawExcessAccount_facts · unwrapLamports_facts · unwrapLamports_not_nativePROVED — a successful excess withdrawal leaves exactly the rent-exempt reserve and credits exactly the excess; a successful unwrap drops amount, supply, and account lamports by exactly the amount and credits the owner's wallet with exactly the amount; unwrapping a non-native token always fails.

approve_delegate · revoke_delegatePROVED — a successful approve sets exactly the given delegate and allowance; a successful revoke clears it.

Helper lemmasPROVED — findMint_id · findAccount_id · findMint_updateMint · findAccount_updateAccount · findMint_updateMint_of · findAccount_updateAccount_of · findAccount_updateAccount_ne · walletOf_creditWallet · sumMint_updateAccount — the list-ledger workhorses the instruction theorems rest on.

Anza's deployed Rust/Pinocchio binary · sBPF refinementNOT MODELED — the theorems specify the semantics; they do not yet say anything about the compiled program. The lean-svm certified-compiler bridge is the path from here to there.

Token-2022 extensions · multisig signer sets · signature cryptographyNOT MODELED — core instruction set only; authorization is the single-key abstraction (one signer key, equality-checked), as in the other PoCs.

Lean demo transcript (poc-ptoken, 54/54 checks)

The binary's scenario: mint 1 (decimals 6) and a native mint 2 (decimals 9); accounts for Alice, Bob, Carol, and Alice's wrapped-SOL account. Minting, plain and checked transfers, a delegate allowance spent down to its exact clearing, freeze/thaw gating, a burn, a two-instruction batch and an atomically-aborting one, a self-transfer, the excess-lamports withdrawal, an unwrap, authority renunciation, and a lamport-paying close — with the failure case of every rule exercised. Every check evaluates the model.

p-token (SIMD-0266) — Lean model of the Pinocchio token program program id TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA (same as SPL Token) setup: mint 1 (dec 6) + native mint 2 (dec 9); accounts 101 Alice, 102 Bob, 103 Carol, 201 Alice/native minted 1000 of mint 1 to Alice; 5000 native to Alice delegate Dave spent 150 then the last 50 of his 200 allowance account 102 frozen by the freeze authority, then thawed batch of two transfers landed; a batch with an overspend aborted whole account 101 withdrew its excess lamports down to the rent reserve unwrapped 2000 native tokens back to lamports mint and freeze authorities renounced — mintTo and freeze are impossible now Carol closed her empty account 103 and took its lamports PASS setup: mint 1 initialized, supply 0 PASS mintTo: mint 1 supply is 1000 PASS mintTo: Alice's account 101 holds 1000 PASS mintTo: native mint 2 supply is 5000 PASS transfer: Alice 700 after sending 300 PASS transfer: Bob 300 after receiving 300 PASS transferChecked: decimals 5 rejected for mint 1 PASS transferChecked: decimals 6 lands — Alice 600 PASS transferChecked: Bob 400 PASS approve: delegate is Dave with allowance 200 PASS delegate spend: Alice 450 after Dave spends 150 PASS delegate spend: allowance down to exactly 50 PASS delegate spend of the last 50: Alice 400 PASS delegate cleared at zero (SPL rule) PASS cleared delegate cannot spend any more PASS stranger Carol cannot transfer Alice's tokens PASS transfer above the balance rejected PASS approve again: delegate Dave with allowance 75 PASS revoke by non-owner Bob rejected PASS revoke by owner clears the delegate PASS freeze by non-freeze-authority Alice rejected PASS freeze by freeze authority: account 102 frozen PASS transfer to a frozen account rejected PASS transfer from a frozen account rejected PASS mintTo to a frozen account rejected PASS thaw: account 102 unfrozen PASS post-thaw transfer: Bob 550 PASS post-thaw transfer: Alice 450 PASS burn: Bob 450 after burning 100 PASS burn: mint 1 supply down to exactly 900 PASS burn from a frozen account rejected PASS mintTo by non-authority Alice rejected PASS mintToChecked: decimals 9 rejected for mint 1 PASS batch: both transfers land — Alice 420 PASS batch: Bob 480 after the batch PASS batch: an overspending middle instruction aborts the whole batch PASS batch: the empty batch is the identity PASS self-transfer nets to zero — Alice still 420 PASS withdrawExcessLamports: account 101 keeps only its 890 rent reserve PASS withdrawExcessLamports: Alice's wallet gains the 9110 excess PASS withdrawExcessLamports by non-owner Alice on Bob's account rejected PASS unwrapLamports: wrapped balance down to 3000 PASS unwrapLamports: account 201 lamports 5030 (reserve kept) PASS unwrapLamports: native supply down to 3000 PASS unwrapLamports: Alice's wallet gains 2000 (11110 total) PASS unwrapLamports on a non-native mint rejected PASS setAuthority by non-authority Alice rejected PASS renounced mint authority: mintTo impossible forever PASS renounced freeze authority: freeze impossible PASS closeAccount with a nonzero balance rejected PASS closeAccount by non-owner Alice rejected PASS closeAccount: Carol's account 103 is removed PASS closeAccount: Carol's wallet paid the account's 2000 lamports PASS final: mint 1 supply is 900 (1000 minted, 100 burned) SUMMARY: 54/54 checks passed RESULT: PASS

Live on chain — SolanaOS p-token program

A small, self-contained token program (solana-os-lean-programs/PToken.lean) with the model's core rules: InitMint, InitAccount, MintTo (authority only), Transfer (owner only, same mint, no overdraft), Burn. It is not SPL Token and not at the SPL program id; it is our own program, compiled by lean-svm, with a top-level theorem over its exact ELF (PToken.Deployed.bytecode_ok, written, not yet kernel-checked; see LAUNCH.md). Devnet only until launch.