Skip to content

fix(spl): deprecate cpi_guard#4465

Merged
jamie-osec merged 4 commits into
otter-sec:masterfrom
jamie-osec:cpi-guard-deprecate
Apr 24, 2026
Merged

fix(spl): deprecate cpi_guard#4465
jamie-osec merged 4 commits into
otter-sec:masterfrom
jamie-osec:cpi-guard-deprecate

Conversation

@jamie-osec

@jamie-osec jamie-osec commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Closes #4458

This feature was originally added in #2789. However, the cpi_guard_enable/disable instructions are not usable from in a CPI (https://docs.rs/crate/spl-token-2022/10.0.0/source/src/extension/cpi_guard/processor.rs#42-44), which means an Anchor CPI wrapper is not useful.

I added these tests in #4322 (cc @0xIchigo), but due to the pre-existing import { it } from "node:test";, ts-mocha was not able to properly recognise the test failures. This test has been failing since then without marking CI as failed.

Remove the broken tests, fix the incorrect import, and deprecate the feature.

cc @acheroncrypto as the original reviewer for a double-check.

The tests invoke the anchor-spl cpi_guard_enable / cpi_guard_disable
wrappers through a CPI from the test program. Token-2022's
process_toggle_cpi_guard explicitly rejects in_cpi() calls with
CpiGuardSettingsLocked, so the wrappers cannot succeed from any
on-chain program. Remove the tests; the wrappers themselves are
deprecated in a follow-up commit.

Also drop the `import { it } from "node:test"` — it caused mocha to
report "0 passing" and not observe failures, letting the CPI Guard
tests appear to pass on CI despite failing at runtime. With it gone,
mocha's global `it` picks up all suites and actually enforces the
outcome.
@jamie-osec jamie-osec added spl fix Bug fix PR labels Apr 24, 2026
@vercel

vercel Bot commented Apr 24, 2026

Copy link
Copy Markdown

@jamie-osec is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@jamie-osec jamie-osec changed the title fix: deprecate cpi_guard fix(spl): deprecate cpi_guard Apr 24, 2026
@tiago18c

Copy link
Copy Markdown
Collaborator

Does it make sense to mark as deprecated instead of outright removal? It was never useable from CPIs (otherwise protocols could disable cpi guard before calling a possible transfer, completely bypassing the idea behind the extension). The only valid reason to keep it is so that no-one tries to re-add it

You've fixed the tests as well, I'll close #4459 then.

@jamie-osec

Copy link
Copy Markdown
Collaborator Author

Ah thanks, didn't notice your issue/PR. Deprecation would be more semver compliant, and it allows us to give a useful error message to people who are trying to use it pointing them to the right place. For v2 we can just not port this extension across

@tiago18c tiago18c left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double checked that there are no more node:test imports.

lgtm

Comment thread spl/src/token_2022_extensions/cpi_guard.rs Outdated
Comment thread spl/src/token_2022_extensions/cpi_guard.rs Outdated
Token-2022's process_toggle_cpi_guard returns CpiGuardSettingsLocked
whenever in_cpi() is true, which is always the case for these anchor-spl
wrappers (they invoke Token-2022 via CpiContext from an on-chain
program). The only workable path for toggling the guard is a
client-side instruction sent directly to Token-2022, which does not
need an anchor-spl wrapper. Mark the two functions and the accompanying
Accounts struct as deprecated so new callers get compiler guidance.
@jamie-osec jamie-osec force-pushed the cpi-guard-deprecate branch from cbc4848 to c6c914b Compare April 24, 2026 16:23
Comment thread CHANGELOG.md Outdated
Co-authored-by: acheron <98934430+acheroncrypto@users.noreply.github.com>
@jamie-osec jamie-osec merged commit 7630372 into otter-sec:master Apr 24, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix PR spl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI not failing with failing tests

3 participants