Skip to main content

const_program_address

Function const_program_address 

Source
pub const fn const_program_address(
    program_id: &Address,
    seeds: &[&[u8]],
    bump: u8,
) -> Address
Expand description

A program-derived address evaluated at compile time.

For seeds that are all literals (a b"config" singleton, a b"vault" + declared-id pair), the address is a constant of the program, so there is nothing to hash on chain: declare it once and check the account with #[account(address = CONFIG)], a 32-byte compare instead of a sol_sha256 (about 150 CU) or a create_program_address syscall (1,500 CU) on every instruction that touches the account. crate::const_pda! is the same call with the seed list spelled inline.

This computes the hash for the selected bump. It does not search for the canonical bump or check that the result is off-curve. Establish those properties separately before using the result as a PDA. For literal inputs, the facade’s hopper::canonical_pda! macro derives a canonical address and bump on the build host. Account ownership, layout and privilege checks are still separate application obligations.