1

The comments for the CPI Guard token extension mentions the following:

    /// Lock certain token operations from taking place within CPI for this
    /// Account, namely:
    /// * Transfer and Burn must go through a delegate.
    /// * CloseAccount can only return lamports to owner.
    /// * SetAuthority can only be used to remove an existing close authority.
    /// * Approve is disallowed entirely.

What would be the reason a user would want enable the CPI Guard for a Token Account to prevent these operations from taking place within a CPI?

1 Answer 1

2

The docs still haven't been updated, but there's a PR at https://github.com/solana-labs/solana-program-library/pull/5876 -- I'll give some language from that as motivation:

When interacting with a dapp, users sign transactions that are constructed by frontend code. Given a user's signature, there are three fundamental ways for a dapp to transfer funds from the user to the dapp (or, equivalently, burn them):

  • Insert a transfer instruction in the transaction
  • Insert an approve instruction in the transaction, and perform a CPI transfer under program authority
  • Insert an opaque program instruction, and perform a CPI transfer with the user's authorization

The first two are safe, in that the user can see exactly what is being done, with zero ambiguity. The third is quite dangerous. A wallet signature allows the program to perform any action as the user, without any visibility into its actions. There have been some attempts at workarounds, for instance, simulating the transaction and warning about balance changes. But, fundamentally, this is intractable.

There are two ways to make this much safer:

  • Wallets warn whenever a wallet signature is made available to an opaque (non-system, non-token) instruction. Users should be educated to treat the request for a signature on such an instruction as highly suspect
  • The token program prohibits CPI calls with the user authority, forcing opaque programs to directly ask for the user's authority

The CPI Guard covers the second instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.