Expand description
Manifest-backed foreign-account lenses.
The Hopper Safety Audit (page 14, “Manifest-backed foreign account lenses”) proposed a verifiable cross-program read API as the next step beyond ad-hoc offset-based foreign reads. This module implements it.
§Problem
Today, reading a field from an account owned by a different program either imports the foreign program’s crate (tight coupling, forces version-lock) or reads raw bytes by hand-maintained offset (no ABI-drift detection. if the foreign program changes its layout, silent misreads result).
§Design
A ForeignManifest is an opaque witness (supplied by the caller)
that carries the foreign program’s wire_fp64 hash plus the layout
discriminator it expects for a particular T: AccountLayout. When
ctx.foreign::<T>(idx, &manifest)? is called:
- The account’s owner must match
manifest.program_id - The account’s header discriminator must match
T::DISCandmanifest.expected_disc - The header’s
wire_fp64must matchT::WIRE_FINGERPRINTandmanifest.expected_wire_fp schema_epochmust fall inmanifest.supported_epochs
Only after all four pass does the lens expose field access. Any
mismatch returns ProgramError::InvalidAccountData. never silent
mis-reads, never UB.
§Manifest sourcing
Hopper does not fetch manifests from RPC inside a program (that would be round-trip CPI with no caching story). Manifests are caller-supplied, typically from:
- An embedded
const ForeignManifestauthored when the program was built (works when the foreign program’s ABI is known at build time) - A manifest account located at the canonical manifest PDA
(
find_program_address(&[MANIFEST_SEED], &foreign_program_id)) whose payload has already been verified by a prior instruction - A Hopper-authored IDL that emits manifest constants as part of its client-generation output
Structs§
- Foreign
Lens - A verified read-only handle into a foreign account.
- Foreign
Manifest - Opaque witness to a foreign program’s layout ABI.