sBPF BooksBPF Book
Program Development

Input Region Layout

Byte-by-byte layout of the buffer the runtime places at r1 on entry to your program.

Reference for the serialised input buffer at r1 on program entry. For the conceptual walkthrough, see Program Structure.

Top-level structure

FieldSizeNotes
num_accounts8 bytesu64, total accounts passed to this instruction
accountsN × 0x2860 byteseach non-duplicate account is exactly 0x2860
instruction_data_len8 bytesu64
instruction_dataix_len bytesthe bytes the caller passed
program_id32 bytesthe pubkey of the program being executed

Per-account block (0x2860 bytes)

Offset (from account start)SizeFieldType
+0x001dup_flagu8, 0xff for unique accounts
+0x011is_signeru8, 0 or 1
+0x021is_writableu8, 0 or 1
+0x031is_executableu8, 0 or 1
+0x044paddingalways zero
+0x0832pubkeythe account's address
+0x2832ownerprogram ID that owns this account's data
+0x488lamportsu64 balance
+0x508data_lenu64, actual bytes used
+0x5810240data + paddingactual data plus MAX_PERMITTED_DATA_INCREASE
+0x28588rent_epochu64

Block total: 1 + 1 + 1 + 1 + 4 + 32 + 32 + 8 + 8 + 10240 + 8 = 10336 bytes = 0x2860.

Instruction data and program ID offsets

Accountsinstruction_data_leninstruction_dataprogram_id
00x00080x00100x0010 + ix_len
10x28680x28700x2870 + ix_len
20x50c80x50d00x50d0 + ix_len
30x79280x79300x7930 + ix_len

Pattern: instruction_data_len = 0x0008 + N × 0x2860 where N is the account count.

Standard .equ block for a one-account program

.equ NUM_ACCOUNTS,         0x0000

.equ ACCT0_HEADER,         0x0008
.equ ACCT0_KEY,            0x0010
.equ ACCT0_OWNER,          0x0030
.equ ACCT0_LAMPORTS,       0x0050
.equ ACCT0_DATA_LEN,       0x0058
.equ ACCT0_DATA,           0x0060
.equ ACCT0_RENT_EPOCH,     0x2860

.equ INSTRUCTION_DATA_LEN, 0x2868
.equ INSTRUCTION_DATA,     0x2870

For each additional account, add an ACCT<N>_* block at offsets shifted by 0x2860, and push INSTRUCTION_DATA_LEN / INSTRUCTION_DATA down by the same amount.

Memory regions (virtual addresses)

RegionBaseSizeWritableNotes
Program0x100000000variesno.text + .rodata
Stack0x2000000004 KByesgrows downward; r10 points at top
Heap0x30000000032 KByesopt-in; rarely used in pure asm
Input0x400000000variesmixedwhat r1 points at on entry

On this page

Edit on GitHub