Skip to content

Instantly share code, notes, and snippets.

@deanmlittle
deanmlittle / fib.md
Last active February 24, 2025 11:45
fib.so teardown

Deconstructing fib.so, a minimal sBPF program

For this deconstruction, we will be researching fib.so, a hand-rolled sBPF assembly program that calculates the fibonacci number based upon a u8 input.

Structure of an sBPF program

The structure of an sBPF program has 4 sections:

1. ELF Header

The starting point of the file, describing the overall file format, target environment, and offsets for program and section headers.

2. Program Headers

Define the memory segments and their attributes (readable, writable, executable) for runtime execution.

@deanmlittle
deanmlittle / bitcoin_winternitz_vault.s
Last active January 9, 2025 10:28
Bitcoin Winternitz Vault
/*******************
* UNLOCKING SCRIPT *
*******************/
// Reverse-ordered Winternitz signature scalar and hash offset pairs
<0x6a1e8e25ac52d4073e6e6792deae3dd16d12580130e8fb1338629cf09cde415f> <0x08>
<0x171582236c86aacab7a0bdfde1d841bed34a4c712748b46a141bd9a743cb965a> <0x0a>
<0xc42ebffb891ff91b5cd75c0b2cfa1b1658eb3586bad9a4aaea05a34846765491> <0xf0>
<0x7faa84fe7faa005ebc37f02b15aa8db41c9ed7c63d8480573471533a0c942096> <0xb0>
<0xe7bbce18cacf2dbc2ae36122365462a07850e873e961ec4ea318dc6506498790> <0x15>
@deanmlittle
deanmlittle / mollusk_generate.sh
Last active October 30, 2024 07:22
Generate a Mollusk SDK for a mainnet-beta program
#!/bin/bash
# Check if program ID and name are provided
if [ "$#" -ne 2 ]; then
echo "Usage: ./mollusk_generate.sh <ProgramID> <name>"
exit 1
fi
PROGRAM_ID="$1"
NAME="$2"
@deanmlittle
deanmlittle / target_os_solana.md
Last active September 23, 2024 14:15
Make Rust Analyzer recognize target_os="solana"

To make Rust analyzer target target_os="solana" try the following:

  1. Find active_release_dir from your config file with cat ~/.config/solana/install/config.yml (or whatever your config directory is)
  2. Create a .vscode/settings.json file in your project workspace and add the following:
{
    "rust-analyzer.cargo.target": "sbf-solana-solana",
    "rust-analyzer.cargo.extraEnv": {
        "CARGO": "<your_active_release_directory>/bin/sdk/sbf/dependencies/platform-tools/rust/bin/cargo",
 "RUSTC": "/bin/sdk/sbf/dependencies/platform-tools/rust/bin/rustc"
@deanmlittle
deanmlittle / anchor-fix-m3-mac.md
Created April 30, 2024 01:52
Fix Anchor build on Mac M3

Fix Anchor build on Mac M3

  1. Make sure you have installed XCode from the App store
  2. Select xcode version from appstore: sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
  3. Confirm by running xcodebuild -version
  4. Install GCC 12 brew install gcc@12
  5. Create a symlink to your usr/local/include folder to make includes discoverable: sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
@deanmlittle
deanmlittle / jupiter.rs
Created January 17, 2024 01:52
Jupiter swap lib
use anchor_lang::{prelude::*, Discriminator};
pub mod jupiter {
use super::*;
declare_id!("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");
#[derive(AnchorDeserialize, AnchorSerialize)]
pub struct SharedAccountsRoute {
pub id: u8,
pub route_plan: Vec<RoutePlanStep>,
pub in_amount: u64,
@deanmlittle
deanmlittle / anchor-setup.ts
Created November 30, 2023 15:33
Anchor setup with airdrop and log/confirm functions
const program = anchor.workspace.AnchorVault as Program<AnchorVault>;
const connection = anchor.getProvider().connection;
const signer = Keypair.generate();
const vault = PublicKey.findProgramAddressSync([Buffer.from("vault"), signer.publicKey.toBuffer()], program.programId)[0];
const confirm = async (signature: string): Promise<string> => {
const block = await connection.getLatestBlockhash();
@deanmlittle
deanmlittle / Readme.md
Last active December 24, 2024 09:49
Metaplex validator

How to setup :

  1. Create a valid8 folder in your path: mkdir ~/.local/share/valid8

  2. Dump the metaplex program there: solana program dump -u m metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ~/.local/share/valid8/metadata.so

  3. Create bash script with sudo nano /usr/local/bin/metaplex-test-validator then paste in the following code and save: (if the /user/local/bin directory doesn't exist, you can create it using sudo mkdir -p -m 775 /usr/local/bin)

#!/bin/bash
@deanmlittle
deanmlittle / lib.rs
Last active August 24, 2023 01:24
Anchor hash-based social content ranking
use anchor_lang::prelude::*;
// This is your program's public key and it will update
// automatically when you build the project.
declare_id!("HL1HGm4o5ygkrMYcyS3WYLK3XXPVLyvp9bPksHQZUeWb");
#[program]
mod hello_anchor {
use super::*;
pub fn initialize(ctx: Context<Initialize>, _hash: Vec<u8>) -> Result<()> {
@deanmlittle
deanmlittle / lib.rs
Created May 17, 2023 14:46
Anchor counter increment
use anchor_lang::prelude::*;
// This is your program's public key and it will update
// automatically when you build the project.
declare_id!("HAcYnZCEXGs31qKPXEJUEjPDBnxSLLL2CxSqp4zrpHze");
#[program]
mod plus_one {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {