Courses

Smart Contract Security Best Practices
Solana · Chapter 11

Smart Contract Security Best Practices

Programs must check the accounts and permissions they receive. A polished interface cannot stop someone from calling your program directly with different inputs.

The basics

  • Check required signers, account ownership and the relationship between a user and their data.
  • For a program-derived address (PDA), validate the expected seeds. A PDA is a reproducible address derived from a program ID and chosen inputs.
  • Validate lengths and arithmetic, and use account constraints carefully. Calling another program is a cross-program invocation (CPI); verify its identity and supplied accounts.

Try it yourself

For a journal entry, list tests for the correct author, a different wallet, the wrong data account and an overly long entry. Each invalid request should fail.

Read more in the official documentation

@ Daniel Burlacu