Summary
Programs deployed via loader-v3 can be upgraded when an upgrade authority is set. Revoking the authority makes the program immutable. Covers the upgrade mechanism, loader-v3 deployment and upgrade instructions, build verification, and the available loader programs.
Deploying programs
Native Rust
Deploy using the Solana CLI with solana program deploy.
Anchor
Deploy using the Anchor framework with anchor deploy.
Upgrading programs
To upgrade a program, an account must hold the upgrade authority (typically the
account that originally deployed the program).
During deployment or upgrade, new bytecode is uploaded to a temporary buffer
account, then written to the program data account. Setting the upgrade authority
to None makes the program immutable and permanently prevents further
updates.
Upgrade mechanism
When
UpgradeableLoaderInstruction::Upgrade
is processed, the runtime:
- Verifies the Program account is writable and owned by loader-v3.
- Verifies the Buffer account contains a
Bufferstate with the correct authority. - Verifies the ProgramData account's
upgrade_authority_addressmatches and is notNone. - Verifies the program was not already deployed in the current slot
(
clock.slot != slot). - Loads and verifies the new ELF bytes from the buffer.
- Copies the new bytecode from the buffer into the ProgramData account and zeros remaining bytes.
- Funds the ProgramData account to rent-exemption.
- Drains the buffer account (sets lamports to 0) and truncates its data.
- The new version becomes effective in the next slot (
deployment_slot + 1).
The Program account itself (its state and the programdata_address pointer)
does not change during an upgrade. Only the ProgramData account's bytecode
and slot metadata are updated.
Loader-v3 instruction reference
Loader-v3 (BPF Loader Upgradeable) is the current default loader for deploying programs on Solana.
| Instruction | Description |
|---|---|
InitializeBuffer | Sets a buffer account's state to Buffer with the specified authority. Fails if already initialized. |
Write | Writes bytes at the specified offset in a buffer account. Authority must sign. |
DeployWithMaxDataLen | Creates a new program: derives the ProgramData address, creates the ProgramData account via CPI to System Program, verifies and deploys the ELF from the buffer, sets the Program account's state and marks it executable. |
Upgrade | Replaces the bytecode in an existing program's ProgramData account from a buffer. |
SetAuthority | Changes the authority of a Buffer or ProgramData account. Setting to None on ProgramData makes the program immutable. Buffer authority cannot be set to None. |
SetAuthorityChecked | Like SetAuthority, but requires the new authority to also sign the transaction. |
Close | Closes a buffer, uninitialized, or ProgramData account by transferring its lamports to a recipient. Closing ProgramData also writes a Closed tombstone to the program cache. Cannot close a program that was deployed in the current slot. |
ExtendProgramChecked | Extends the ProgramData account's allocation by additional bytes, funding the extra rent from the payer. |
Verifying programs
Solana supports verifiable builds, which let users confirm that a program's onchain bytecode matches its public source code. The Anchor framework provides built-in support for verifiable builds.
To check verification status for a deployed program, search for its program ID on the Solana Explorer, or use the Ellipsis Labs Solana Verifiable Build CLI to independently verify onchain programs.
Loader programs
| Loader | Address | Upgradeable | Description |
|---|---|---|---|
| Native Loader | NativeLoader1111111111111111111111111111111 | Only via validator software upgrade | Owns builtins (System, Vote, Stake) and other loaders |
| BPF Loader (v1) | BPFLoader1111111111111111111111111111111111 | No (loader management disabled) | Legacy programs |
| BPF Loader (v2) | BPFLoader2111111111111111111111111111111111 | No (loader management disabled) | Legacy programs |
| BPF Loader Upgradeable | BPFLoaderUpgradeab1e11111111111111111111111 | Yes, if upgrade authority is set | Owns all newly deployed programs |
Is this page helpful?