Programs

On Solana, "smart contracts" are called programs. Programs are deployed on-chain to accounts that contain the program's compiled executable binary. Users interact with programs by sending transactions containing instructions that tell the program what to do.

Key Points

  • Programs are accounts containing executable code, organized into functions called instructions.
  • While programs are stateless, they can include instructions that create and update other accounts to store data.
  • An upgrade authority can update programs. Once this authority is removed, the program becomes immutable.
  • Users can verify an on-chain program account's data matches its public source code through verifiable builds.

Writing Solana Programs

Solana programs are predominantly written in the Rust programming language, with two common approaches for development:

  • Anchor: A framework designed for Solana program development. It provides a faster and simpler way to write programs, using Rust macros to significantly reduce boilerplate code. For beginners, it is recommended to start with the Anchor framework.

  • Native Rust: This approach involves writing Solana programs in Rust without leveraging any frameworks. It offers more flexibility but comes with increased complexity.

Updating Solana Programs

To learn more about deploying and upgrading programs, see the deploying programs page.

On-chain programs can be directly modified by an account designated as the "upgrade authority", which is typically the account that originally deployed the program. If the upgrade authority is revoked and set to None, the program becomes immutable and can no longer be updated.

Verifiable Programs

Verifiable builds allow anyone to check if a program's on-chain code matches its public source code, making it possible to detect discrepancies between source and deployed versions.

The Solana developer community has introduced tools to support verifiable builds, enabling both developers and users to verify that onchain programs accurately reflect their publicly shared source code.

  • Searching for Verified Programs: To quickly check for verified programs, users can search for a program address on the SolanaFM Explorer and navigate to the "Verification" tab. View an example of a verified program here.

  • Verification Tools: The Solana Verifiable Build CLI by Ellipsis Labs enables users to independently verify onchain programs against published source code.

  • Support for Verifiable Builds in Anchor: Anchor provides built-in support for verifiable builds. Details can be found in the Anchor documentation.

Berkeley Packet Filter (BPF)

Solana uses LLVM to compile programs into ELF files. These files contain Solana's custom version of eBPF bytecode, called "Solana Bytecode Format" (sBPF). The ELF file contains the program's binary and is stored on-chain in an executable account when the program is deployed.

Mục lục

Chỉnh sửa trang