Build verification execution
Build verification execution is the CLI workflow that turns a source snapshot into a Solana program artifact and checks that artifact against the deployed program. It isolates the build in a Docker environment, records the source and build context, compares hashes, and can publish the verification result for later checks.
Verification lifecycle
The verification lifecycle starts with a repository and program ID. It ends with either a matching hash or a clear failure. The CLI supports local verification from a repository, verification from an existing image, and a remote job path that reports the same comparison through a server.
This diagram shows how source input becomes a rebuilt artifact and then a verification result.
flowchart TD
A[Repository URL or image] --> B[Select source snapshot]
B --> C[Resolve program and workspace]
C --> D[Validate build inputs]
D --> E[Build in Docker]
E --> F[Collect program artifact]
F --> G[Hash rebuilt artifact]
H[Deployed program on Solana] --> I[Read on-chain bytes]
I --> J[Hash deployed bytes]
G --> K{Hashes match?}
J --> K
K -->|Yes| L[Report verified]
K -->|No| M[Report mismatch]
L --> N[Optionally publish build metadata]
The CLI also handles interrupts during this lifecycle. It stops the active container and removes the temporary verification directory so a cancelled run does not leave its build environment behind. [src/main.rs#L61-L111]
References: src/main.rs• L1440-1559 src/main.rs• L1561-1607
Source snapshot
The source snapshot is the exact repository state used for the check. verify-from-repo clones the repository into a temporary location and checks out the requested commit. If no commit is given, the CLI resolves the remote default branch before it starts the workflow. [src/main.rs#L698-L766] [src/main.rs#L1360-L1423]
The source path and workspace path can differ. This supports monorepos where the program lives below a repository root or depends on other crates from a separate workspace. The target library can be named directly. If it is not named, the CLI accepts the build only when it can find one unambiguous library target. [src/main.rs#L1247-L1357] [src/main.rs#L1871-L1910]
References: src/main.rs• L1360-1423 src/main.rs• L1440-1494 src/main.rs• L1247-1357
Build environment
The build environment is a Docker image chosen to make the rebuild repeatable. By default, the CLI derives a Solana version from workspace metadata or the lock file and maps that version to a pinned image. A caller can provide a base image when the standard map has no suitable entry. [src/main.rs#L936-L975] [src/image_config.rs#L1-L7]
The build requires a Cargo.lock file in the selected workspace. It uses the Solana SBF build command by default and supports the older BPF command for compatible programs. Build arguments, target architecture, and optional Docker CPU and memory limits shape the build without changing the verification comparison. [src/main.rs#L936-L947] [src/main.rs#L1011-L1113] [src/main.rs#L871-L885]
References: src/main.rs• L887-1141 src/image_config.rs• L1-294
Artifact collection
Artifact collection identifies the program’s shared object in the workspace deployment output. The CLI reads the complete file and produces a SHA-256 hash after removing trailing zero bytes. The same normalization is used for program bytes read from Solana, so the comparison covers the meaningful deployed artifact rather than account padding. [src/main.rs#L768-L786] [src/main.rs#L1589-L1606]
The image-based path follows the same goal with a different input. It copies the named executable from a running image into a temporary file, hashes that file, reads the deployed program hash, and reports whether the two values match. [src/main.rs#L1143-L1245]
References: src/main.rs• L768-794 src/main.rs• L1143-1245 src/main.rs• L1561-1607
On-chain comparison
The on-chain comparison reads the program account through the selected Solana RPC connection. Upgradeable programs store their executable bytes in a program-data account. Legacy BPF loaders store them in the program account. The CLI removes the loader metadata from the selected account data before it computes the on-chain hash. [src/main.rs#L788-L861]
The verification result is a comparison of two hashes. A match means the rebuilt executable has the same normalized bytes as the deployed program. A mismatch reports both values and does not publish new verification metadata. RPC reads retry with a short exponential delay before the workflow gives up. [src/main.rs#L1521-L1558] [src/main.rs#L1931-L1953]
References: src/main.rs• L788-861 src/main.rs• L1521-1558 src/main.rs• L1931-1953
Verification metadata
After a successful match, the CLI can publish the build context on Solana. This metadata links the program to its repository URL, commit, CLI version, build arguments, and deployment slot. The upload asks for confirmation unless the caller skips the prompt. [src/solana_program.rs#L102-L109] [src/solana_program.rs#L314-L409]
The metadata is stored in a program-derived account, or PDA. A PDA is a deterministic Solana account derived from the program ID and the signer. Existing metadata for the signer is updated. Metadata from another signer remains separate and can lead the CLI to ask whether to create a new record. [src/solana_program.rs#L357-L404] [src/solana_program.rs#L412-L415]
The upload records the last deployed slot obtained from the program’s on-chain data. This ties the source and build context to the deployment that was checked rather than to an unspecified future deployment. [src/api/solana.rs#L86-L111] [src/solana_program.rs#L339-L355]
References: src/solana_program.rs• L68-89 src/solana_program.rs• L314-415 src/…/solana.rs• L86-111
Remote verification
Remote verification moves the build and comparison to the verification service. The CLI first confirms that the selected network is Solana mainnet and that the uploader’s verification PDA exists. It then submits the program ID and signer to the service. [src/api/client.rs#L92-L123]
The service returns a request ID. The CLI polls the job until it is in progress, completed, failed, or unknown. On completion, it compares the service’s executable and on-chain hashes and prints the repository URL and both hashes. The job and program status URLs remain available for follow-up checks. [src/api/client.rs#L125-L223] [src/api/models.rs#L40-L59]
This remote path is distinct from the local build path. The local path performs the build in the caller’s Docker environment. The remote path reports the result of a server-managed build and uses the signer’s on-chain metadata as its input. [src/main.rs#L488-L551] [src/api/client.rs#L92-L123]
References: src/…/client.rs• L20-21 src/…/client.rs• L92-223 src/…/models.rs• L10-59
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the artifact-byte normalization the same for local files, image files, and on-chain account data. A change in one path can create false mismatches.
- Keep the Solana version lookup and image digest map aligned. A supported version must resolve to the image used for its reproducible build.
- Keep the build argument list recorded in verification metadata aligned with the arguments passed to the build. Otherwise later users cannot reproduce the checked build context.
- Keep the PDA metadata fields and the remote service request fields aligned. Remote jobs depend on the program ID and uploader being tied to the uploaded verification record.
- Keep loader-specific account offsets current when Solana account layouts change. Incorrect offsets change the on-chain hash input.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The selected workspace has no Cargo.lock file. | The build stops before Docker execution. | Put the lock file at the workspace root or select the correct workspace path. |
| The Solana version has no mapped image and no base image is supplied. | The CLI cannot start a version-aligned build. | Add a compatible image with --base-image or update the image map. |
| More than one possible library target is found without an explicit name. | The CLI cannot know which executable to verify. | Set --library-name to the target used for deployment. |
| The rebuilt hash differs from the on-chain hash. | Verification fails and new metadata is not uploaded. | Use the exact source commit and build settings used for the deployed artifact. |
| The deployed program uses an unsupported loader or has missing data. | The CLI cannot compute the comparison hash. | Use a supported BPF loader and a valid deployed program account. |
| A remote job is submitted from a non-mainnet connection. | The remote request is rejected before submission. | Connect to mainnet and confirm the uploader PDA exists there. |
| The process receives an interrupt during Docker work. | The run exits after stopping the container and removing temporary files. | Re-run the verification after checking the source and build inputs. |
Key files
| File | Why to read it |
|---|---|
| src/main.rs | Defines the CLI commands and coordinates repository cloning, preflight checks, Docker builds, artifact hashes, cleanup, and verification results. |
| src/solana_program.rs | Defines the on-chain comparison support and the metadata upload that follows a successful match. |
| src/…/solana.rs | Shows how the deployed slot is read from Solana account data for verification metadata. |
| src/…/client.rs | Explains remote job submission, polling, and result reporting. |
| src/…/models.rs | Defines the result shapes used to display remote verification state and hash values. |
| src/image_config.rs | Provides the pinned image mapping used when the CLI selects a build environment from the Solana version. |
| docs/verifier-cli.md | Parent page for the command-line interface and its user-facing command groups. |
| docs/solana-program-artifacts.md | Related page for the program artifact and hash concepts used by this lifecycle. |
| docs/verified-programs-api.md | Related page for the service-side verified program status and API flow. |
| docs/image-configuration.md | Related page for the image selection and configuration model. |