Sign in

PDAs: addresses with no private key

Suggest an edit

A normal Solana account is controlled by whoever holds its private key. That works for wallets, where a person is in charge. It does not work for programs, because a program cannot keep a key secret. The fix is a different kind of address: one derived from a program ID and some seeds, with no private key in existence anywhere. The program signs for that address using the seeds themselves. These are called Program-Derived Addresses, or PDAs.

Why PDAs have to exist

A normal account's address is the public key of an Ed25519 keypair. To authorize anything that account does, you sign a transaction with the matching private key. That model is fine when there's a human or a server holding the key in secret.

A program can't do this. The program is bytecode running on every validator at once, and anyone can read it. If a program tried to hold a private key, everyone who reads the bytecode could sign with it, so the key would be public.

But programs need to control accounts: vaults that hold user deposits, state accounts that only the program is allowed to mutate, pools the program signs token transfers out of. None of that works with the standard keypair model.

The resolution is a kind of address that nobody can sign for in the normal way, with a special ability for the program to sign for it instead. A PDA is a 32-byte value that looks like a public key but isn't one, derived deterministically from the program's address and some seeds chosen by the developer. No private key exists for it, because the derivation lands at a point that isn't on the Ed25519 curve, and the curve is where valid keypairs come from. If a program submits the seeds, the runtime treats it as authorization for the PDA those seeds derive to.

Two ways an account gets an address: normal wallet vs program-derived PDAThe diagram compares two ways a Solana account gets its address, side by side: a normal wallet on the left and a PDA on the right. The wallet's private key derives a public key, a point on the curve, as its address; the PDA's program ID and seeds go through a hash and bump search to land on a point off the curve, so only the program can sign for it. Two ways an account gets an address a normal account (a wallet) private key a random 256-bit number Ed25519 derivation public key a point ON the curve = the address account address 8fK3...wXyz to authorize anything, you sign with the private key controlled by whoever holds it a PDA (program-controlled) program ID + seeds public, anyone can read hash + bump search a 32-byte value a point OFF the curve = the address account address 2pQr...mN8h no private key exists. only the program can sign for it. controlled by the program's code A PDA is the same kind of 32-byte address, derived a different way. The point off the curve is the trick.

The address is the lookup

The second reason for PDAs is what the derivation gives you besides signing. Because the address is a hash of public inputs, anyone who knows the inputs can compute where the account is.

For one vault per user, use seeds [b"vault", user.key()]. Each user's pubkey produces a unique PDA, and to find a user's vault you compute the PDA from their pubkey. In a normal database, you'd have a users table mapping user IDs to vault row IDs. Here the address of the vault is a hash of the user's identity, so no mapping table is needed.

Seeds can combine several values. A vote record that's unique per user and per proposal can use seeds [b"vote", user.key(), proposal.key()]. A daily counter PDA could use [b"counter", day_number.to_le_bytes()]. Any tuple of public values that uniquely identifies the account you want can be the seeds. The runtime guarantees the resulting address is unique to that tuple under your program.

Each seed can be at most 32 bytes, and there can be at most 16 seeds. Addressing accounts this way also has costs. The program cannot list all vaults, because it sees only the accounts a transaction passes in, so the client has to know which user it wants and derive the address. The seeds of an existing account cannot change, because different seeds give a different address. And every PDA is a separate account with its own rent deposit, so one vault per user means one deposit per user.

The bump keeps the address off the curve

The derivation hashes the seeds, a single byte called the bump, and the program ID with SHA-256. The result is 32 bytes. If those 32 bytes happen to land on the Ed25519 curve, a matching private key could exist, which a PDA must not have. So if the result is on the curve, the derivation rejects it and tries again with a smaller bump byte.

The bump starts at 255 and decreases. Roughly half of all 32-byte values land on the curve, so on average two tries are enough to find one that doesn't. The first off-curve result encountered, with the highest bump, is the canonical PDA for those seeds. The bump that produced it is the canonical bump.

find_program_address bump search from 255 down to the canonical PDAThe flowchart tries bump values starting at 255 and checks each candidate address against the curve. Bumps 255 and 254 land on the curve and are rejected, but bump 253 falls off the curve and is returned as the canonical PDA with canonical_bump = 253. How find_program_address finds the bump inputs: seeds = [b"vault", user.key()], program_id = MyProgram try bump = 255 candidate = sha256(seeds || [255] || program_id || "ProgramDerivedAddress") → falls ON the curve. reject. try bump = 254 candidate = sha256(seeds || [254] || program_id || "ProgramDerivedAddress") → falls ON the curve. reject. try bump = 253 candidate = sha256(seeds || [253] || program_id || "ProgramDerivedAddress") → falls OFF the curve. accept this. return: (PDA = 2pQr...mN8h, canonical_bump = 253) the canonical bump is the highest value (255 down to 0) that produces an off-curve point Roughly half the candidates fall on the curve. The loop finds the first off-curve one within a few tries.

The function that runs this loop is called find_program_address. You hand it the seeds and the program ID, and it returns the canonical PDA along with the bump that produced it. Off-chain code calls it before submitting a transaction so the right account address can be included.

On-chain code mostly avoids find_program_address, since running the loop costs 1,500 compute units for every bump it tries. A cheaper function called create_program_address takes a known bump and checks it directly. So programs compute the canonical bump once, store it on the account in a field like pub bump: u8, and pass it in from then on.

The bump a program checks against has to be the canonical one, because it is not the only bump that gives an off-curve address. Roughly half of the lower bumps do too, each at a different address. If a program accepted any bump the caller supplied, one set of seeds would have several valid addresses, and one user could have more than one vault.

Anchor handles this for you when you write seeds = [...] and bump. The bump keyword without a value means "compute and verify the canonical bump." In the init instruction you store the value Anchor computed in the account's bump field, and every later instruction writes bump = state.bump on the seeds constraint, which skips the search and uses the stored value.

The client derives the same address from the same seeds

Most of the time you need to know the PDA address from your TypeScript client before you can build a transaction that touches it. The Anchor SDK uses it to fill in the accounts list, and your tests use it to fetch state back after the call. The function is PublicKey.findProgramAddressSync from @solana/web3.js:

typescript
import { PublicKey } from "@solana/web3.js";

const programId = new PublicKey("Fg6PaFpoGXkYsidMpWxqSWPg2J9eRMK8RnPwYxNb8nN");
const user = userKeypair.publicKey;

// Same algorithm as find_program_address on chain, just running off-chain.
const [vaultPda, vaultBump] = PublicKey.findProgramAddressSync(
  [Buffer.from("vault"), user.toBuffer()],
  programId,
);

console.log("vault address:", vaultPda.toBase58());
console.log("canonical bump:", vaultBump);

programId is the address from the program's declare_id!. The function returns a tuple of the PDA and the canonical bump. Since the seeds are public and the program ID is public, you can compute any PDA your program uses from outside the program.

Vault PDAs derived from seeds b"vault" plus pubkey for Alice, Bob, CarolFor Alice, Bob, and Carol, the seeds b"vault" and the user's pubkey are combined to deterministically derive that user's vault PDA and bump. No user-to-vault mapping table is needed, since the address itself is the lookup, like content-addressed storage. The address IS the lookup. One PDA per (seeds) combination. seeds spec: [b"vault", user.key().as_ref()] a literal string + the user's pubkey Alice seeds: b"vault" alice_pubkey Alice's vault PDA: 9Hx2...mK3p bump = 254 deterministic from Alice's pubkey Bob seeds: b"vault" bob_pubkey Bob's vault PDA: 3rQv...nP7w bump = 253 deterministic from Bob's pubkey Carol seeds: b"vault" carol_pubkey Carol's vault PDA: 7xKp...rT2v bump = 255 deterministic from Carol's pubkey No mapping table needed To find Alice's vault, you compute the PDA from her pubkey. The address is the lookup. No "user → vault address" map. The address mechanism is the map. Same idea as content-addressed storage. The hash of the identity is the location.

The seed bytes have to be the same on both sides. If your program declares seeds = [b"vault", user.key().as_ref()], your client has to pass Buffer.from("vault") and user.toBuffer() in the same order. The common bug here is a seed encoding mismatch: passing a string where the program expects a number, or swapping the order of two seeds. When this happens, the client computes a different PDA than the program expects, and the transaction fails at constraint-check time with a "seeds constraint violated" error. Calling .toString() instead of .toBuffer() on a pubkey fails earlier, in the client: the Base58 string is 43 or 44 bytes, over the 32-byte seed limit, so findProgramAddressSync throws Max seed length exceeded.

The account at a PDA is an ordinary account

A PDA does not change anything about the account model. The account at a PDA still has the same five fields: lamports, data, owner, executable, and an address. Reading from it works the way reading from any account works. Writing to it requires it to be owned by the program, the way any program-owned account requires. What changes is who can sign for it: the program does, by supplying the seeds inside a cross-program invocation. The PDAs as signers lesson shows that in code.