Skip to main content

Module solana

Module solana 

Source
Expand description

Fetch a Solana on-chain program and return its raw ELF bytes. Strips the loader-state header so the resulting bytes feed straight into ud_translate::decompile::decompile.

Solana stores SBF programs under one of three loaders, each with its own account-data layout:

  • BPFLoader2111… (non-upgradeable, legacy). The program’s account data IS the ELF — no header to strip.
  • BPFLoaderUpgradeab1e… (today’s default). Two accounts: the Program account holds a 36-byte UpgradeableLoaderState::Program (a Borsh enum tag of 2 plus a 32-byte pubkey pointing at the ProgramData account). The ProgramData account starts with an UpgradeableLoaderState::ProgramData header (45 bytes when an upgrade authority is set, 13 bytes when it’s None) followed by the ELF.
  • LoaderV411… (Agave’s newer loader). A LoaderV4State of 48 bytes (slot + authority pubkey + 8-byte status) followed by the ELF.

All three are recognised here. The strip routine validates that the bytes immediately after the header carry the ELF magic (\x7fELF), so a mismatched layout fails loudly rather than producing garbage.

Fetching uses Solana’s standard JSON-RPC getAccountInfo method against a public mainnet endpoint by default; the caller can override with --rpc. Fetched ELFs are cached under ~/.cache/univdreams/solana/ keyed by program ID (and, for upgradeable programs, the ProgramData slot — upgrades invalidate the cache).

Constants§

DEFAULT_RPC
Default RPC endpoint when --rpc isn’t given. Solana’s public mainnet endpoint — heavily rate-limited but the universally-known fallback.

Functions§

fetch_program_elf
Fetch the raw ELF bytes for program_id, caching under ~/.cache/univdreams/solana/. With use_cache = false, the cached copy is ignored and overwritten.