Repository navigation
Conversation
[Medium impact] The PR appears safe to merge; no actionable new issues were found. SummaryAdds a Pinocchio example showing how
Both earlier comments are addressed: deployment names the crate’s output file, and the documentation points readers to Reviews (7) · Last reviewed commit: "token-2022 cpi-guard pinocchio: assert t..." · Reviewed by Greptile |
7e29851 to
8bd3daf
Compare
What and why Adds a Pinocchio version of tokens/token-2022/memo-transfer, which only had an Anchor one. It follows the same kit + LiteSVM + @solana-program template as the merged Token-2022 Pinocchio examples and builds on the account-extension shape from immutable-owner (#696). The single instruction creates a Token-2022 token account with the MemoTransfer extension enabled, so every transfer into it must be preceded by a memo. The program hand-builds three CPIs: CreateAccount, with space for the extension. InitializeAccount3 (variant 18): [18] + owner(32). EnableRequiredMemoTransfers: MemoTransferExtension (30), sub-instruction Enable (0) → [30, 0]. Unlike ImmutableOwner, this extension is enabled after the account is initialized, and the enable must be signed by the account owner (the payer here). The account is 171 bytes: 165 base + 1 account-type byte + a 5-byte MemoTransfer TLV. The JS dependencies match the versions #765 set for the other non-anchor examples. Also: unblocks CI for block-list Adding a workspace member changes the root Cargo.lock, which makes CI rebuild every Pinocchio project, including transfer-hook/block-list/pinocchio, which is currently red on main too. That example is its own workspace with a gitignored Cargo.lock, so its CLI's solana-* = "4.3.2" requirements now resolve to Agave 4.4.1, which needs rustc 1.98.1 while rust-toolchain.toml pins 1.97. One commit holds those four crates at ~4.3.2 (what #773 merged with); with it the example passes tsc, the SBF and CLI builds, its Rust tests and pnpm audit on rustc 1.97.1. The same commit is in #792 and #793, so whichever merges second has nothing left to apply.
dev-jodee
left a comment
There was a problem hiding this comment.
one comment adn i think you need to rebase
| m => appendTransactionMessageInstruction(transferIx, m), | ||
| ); | ||
| const blockedResult = svm.sendTransaction(await signTransactionMessageWithSigners(blockedTx)); | ||
| assert.instanceOf(blockedResult, FailedTransactionMetadata, 'expected the guarded CPI transfer to be rejected'); |
There was a problem hiding this comment.
this only checks that the tx failed, not why, so the blocked case passes on any error, the anchor version pins it to TokenError::CpiGuardTransferBlocked, can we assert on that custom error code from blockedResult.err() instaed
There was a problem hiding this comment.
Fixed in 1071609: the blocked case now asserts InstructionError(0, Custom(42)), i.e. TokenError::CpiGuardTransferBlocked, like the anchor test. Also rebased onto main.
Ports the cpi-guard Token-2022 example to Pinocchio (the anchor example has no native sibling). Unlike the other extension examples, CpiGuard cannot be enabled or disabled through a CPI, so the program cannot initialize it; instead the program exposes a cpi_transfer instruction (a Token-2022 TransferChecked CPI, reading the mint's decimals from account data) and the example demonstrates the guard's effect. The litesvm test creates a source account with CpiGuard enabled (client-side) and funded, then shows the program's CPI transfer is rejected while the guard is on and succeeds once it is disabled, asserting the destination balance. Matches the kit + litesvm template of the other token-2022 pinocchio examples.
Matches the versions solana-foundation#765 set for the other non-anchor examples (kit 8.5, mocha 12, typescript 7) and adds the same pnpm-workspace.yaml overrides, which clears pnpm-audit. The signer role in the hand-built instruction takes 'as const' so kit 8 keeps it as a signer role, as the sibling tests on main do.
cargo build-sbf names the artifact after the crate, so deploy the *.so in the output dir instead of program.so, and stop cicd.sh if the build fails. pinocchio-token-2022 now exists in the workspace, so the comment says the instruction is hand-built to show its layout rather than claiming there is no crate.
pnpm runs package.json scripts through cmd.exe on Windows, which does not expand the *.so glob. Name the file cargo build-sbf writes instead, matching solana-foundation#794.
cpi_transfer read decimals from whatever account was passed as the mint. Token-2022 would still reject a fake mint inside TransferChecked, but an example should show the check: only read a mint's bytes once Token-2022 owns it. The new test passes a byte-for-byte copy of a real mint owned by the System Program and asserts the program fails before any Token-2022 CPI and no tokens move.
solana-foundation#800 removed every example's cicd.sh and replaced em dashes in comments; drop this example's cicd.sh and do the same.
… failure The blocked case only checked that the transaction failed, so it passed on any error. Assert Token-2022's TokenError::CpiGuardTransferBlocked (Custom(42)) on the example's instruction, as the anchor test does.
8bd3daf to
1071609
Compare
Linked issue
Fixes #786
Replaces #701, which the PR-hygiene bot closed before the issue was accepted; GitHub doesn't let the author reopen it.
What and why
Adds a Pinocchio version of
tokens/token-2022/cpi-guard, which only had an Anchor one, following the same kit + LiteSVM template as the other Token-2022 Pinocchio examples.CpiGuardstops privileged token operations (transfer, burn, approve, close) authorized by the account owner from running through a CPI. Token-2022 doesn't allow enabling or disabling the guard through a CPI either, so unlike the other extension examples the program can't initialize it. Instead:cpi_transferinstruction: a Token-2022TransferCheckedCPI (variant 12) from source to destination, signed by the source's owner. It checks that Token-2022 owns the mint account, then readsdecimalsfrom it (offset 44) so the checked transfer matches the mint.The JS dependencies match the versions #765 set for the other non-anchor examples.
Also: unblocks CI for
block-listAdding a workspace member changes the root
Cargo.lock, which makes CI rebuild every Pinocchio project, includingtransfer-hook/block-list/pinocchio, which is currently red onmaintoo. That example is its own workspace with a gitignoredCargo.lock, so its CLI'ssolana-* = "4.3.2"requirements now resolve to Agave 4.4.1, which needs rustc 1.98.1 whilerust-toolchain.tomlpins 1.97. One commit holds those four crates at~4.3.2(what #773 merged with); with it the example passestsc, the SBF and CLI builds, its Rust tests andpnpm auditon rustc 1.97.1. The same commit is in #792 and #793, so whichever merges second has nothing left to apply.Testing
pnpm install --frozen-lockfile,tsc --noEmit,pnpm build,pnpm build-and-testandpnpm auditin a Linux container, pluscargo fmt --check,cargo clippy -D warningsandprettier --check:The test creates a mint and a funded source account with CpiGuard enabled, asserts
cpi_transferfails (FailedTransactionMetadata), disables the guard, and asserts the same call succeeds and the destination balance is1. The success after disabling shows the guard caused the rejection.The second test passes a byte-for-byte copy of a real mint owned by the System Program, and asserts the program fails before any Token-2022 CPI and no tokens move. With the owner check deleted, this test fails (the fake mint reaches
TransferChecked).pnpm run deploynamestoken_2022_cpi_guard_pinocchio_program.so, the filecargo build-sbfwrites; checked in Linux with a real build (same check as #794). The name is explicit rather than a*.soglob because pnpm runs scripts throughcmd.exeon Windows, which doesn't expand globs.AI disclosure
Check exactly one. See CONTRIBUTING.md.