surfpool-core 1.3.1

Where you train before surfing Solana
Documentation
/// Minimal valid SBF ELF (352 bytes) — just returns SUCCESS (r0=0).
///
/// Used as a placeholder in `init_programdata_account` to satisfy LiteSVM's
/// ELF validation when bootstrapping program accounts. This gets stripped
/// by `write_program_data_account_with_offset` before actual program data
/// is written.
///
/// Layout (352 bytes):
///   0x000..0x040  ELF64 header (ET_DYN, EM_SBPF=0x107, SBPFv0, entry=0x78)
///   0x040..0x078  1× PT_LOAD program header (text at 0x78, 16 bytes, RX)
///   0x078..0x088  .text section: mov64 r0,0 ; exit
///   0x088..0x099  .shstrtab contents: "\0.text\0.shstrtab\0"
///   0x099..0x0A0  padding (7 bytes, align section headers to 8)
///   0x0A0..0x0E0  Section header [0]: SHT_NULL
///   0x0E0..0x120  Section header [1]: .text
///   0x120..0x160  Section header [2]: .shstrtab
pub const NOOP_PROGRAM_ELF: &[u8] = &[
    // ===== ELF64 Header (64 bytes) =====
    // e_ident: EI_MAG0..3, EI_CLASS=2(64-bit), EI_DATA=1(LE), EI_VERSION=1,
    //          EI_OSABI=0, padding
    0x7F, b'E', b'L', b'F', 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // e_type=ET_DYN(3), e_machine=EM_SBPF(0x107)
    0x03, 0x00, 0x07, 0x01, // e_version=1
    0x01, 0x00, 0x00, 0x00, // e_entry=0x78 (start of .text)
    0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // e_phoff=0x40 (program headers right after ELF header)
    0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // e_shoff=0xA0 (section headers at offset 160)
    0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // e_flags=0 (SBPFv0)
    0x00, 0x00, 0x00, 0x00, // e_ehsize=64
    0x40, 0x00, // e_phentsize=56
    0x38, 0x00, // e_phnum=1
    0x01, 0x00, // e_shentsize=64
    0x40, 0x00, // e_shnum=3
    0x03, 0x00, // e_shstrndx=2
    0x02, 0x00, // ===== Program Header (56 bytes) =====
    // p_type=PT_LOAD(1)
    0x01, 0x00, 0x00, 0x00, // p_flags=PF_R|PF_X(5)
    0x05, 0x00, 0x00, 0x00, // p_offset=0x78
    0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_vaddr=0x78
    0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_paddr=0x78
    0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_filesz=16
    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_memsz=16
    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_align=8
    0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // ===== .text section (16 bytes at 0x78) =====
    // mov64 r0, 0  (opcode=0xb7, dst=r0, src=0, off=0, imm=0)
    0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // exit         (opcode=0x95, dst=0, src=0, off=0, imm=0)
    0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // ===== .shstrtab contents (17 bytes at 0x88) =====
    // "\0.text\0.shstrtab\0"
    0x00, b'.', b't', b'e', b'x', b't', 0x00, b'.', b's', b'h', b's', b't', b'r', b't', b'a', b'b',
    0x00, // ===== Padding to align section headers to 8 bytes (7 bytes) =====
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    // ===== Section Header [0]: SHT_NULL (64 bytes at 0xA0) =====
    0x00, 0x00, 0x00, 0x00, // sh_name=0
    0x00, 0x00, 0x00, 0x00, // sh_type=SHT_NULL(0)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_flags=0
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addr=0
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_offset=0
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_size=0
    0x00, 0x00, 0x00, 0x00, // sh_link=0
    0x00, 0x00, 0x00, 0x00, // sh_info=0
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addralign=0
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_entsize=0
    // ===== Section Header [1]: .text (64 bytes at 0xE0) =====
    0x01, 0x00, 0x00, 0x00, // sh_name=1 (index into .shstrtab: ".text")
    0x01, 0x00, 0x00, 0x00, // sh_type=SHT_PROGBITS(1)
    0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_flags=SHF_ALLOC|SHF_EXECINSTR(6)
    0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addr=0x78
    0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_offset=0x78
    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_size=16
    0x00, 0x00, 0x00, 0x00, // sh_link=0
    0x00, 0x00, 0x00, 0x00, // sh_info=0
    0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addralign=8
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_entsize=0
    // ===== Section Header [2]: .shstrtab (64 bytes at 0x120) =====
    0x07, 0x00, 0x00, 0x00, // sh_name=7 (index into .shstrtab: ".shstrtab")
    0x03, 0x00, 0x00, 0x00, // sh_type=SHT_STRTAB(3)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_flags=0
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addr=0
    0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_offset=0x88
    0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_size=17
    0x00, 0x00, 0x00, 0x00, // sh_link=0
    0x00, 0x00, 0x00, 0x00, // sh_info=0
    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addralign=1
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_entsize=0
];

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_noop_program_elf_size() {
        assert_eq!(NOOP_PROGRAM_ELF.len(), 352);
    }
}