Multiple implementations of Solana programs across languages: Rust, Zig, C, and even assembly.
More programs will be added over time!
- Install Rust: https://www.rust-lang.org/tools/install
- Install Solana tools
./install-solana.sh- Go to a program directory
cd helloworld- Build a program
cargo build-sbf- Test a program
cargo test-sbf- Get the compiler
./install-solana-zig.sh- Go to the Zig implementation of a program
cd helloworld/zig- Build the program
../../solana-zig/zig build- Test it
cd ..
SBF_OUT_DIR="./zig/zig-out/lib" cargo test- OR use the helper from the root of this repo to build and test
./test-zig.sh helloworld- Install Solana C compiler
./install-solana-c.sh- Install Solana tools
./install-solana.sh- Go to a program directory
cd helloworld/c- Build a program
make- Test it
cd ..
SBF_OUT_DIR="./c/out" cargo test- OR use the helper from the root of this repo to build and test
./test-c.sh helloworld- Install Solana LLVM tools
./install-solana-llvm.sh- Go to a program directory
cd helloworld/asm- Build a program
make- Test it
cd ..
SBF_OUT_DIR="./asm/out" cargo test- OR use the helper from the root of this repo to build and test
./test-asm.sh helloworldLogs a static string using the sol_log_ syscall.
| Language | CU Usage |
|---|---|
| Rust | 105 |
| Zig | 105 |
| C | 105 |
| Assembly | 104 |
Since this is just doing a syscall, all the languages behave the same. The only difference is that the Assembly version doesn't set the return code to 0, and lets the VM assume it worked.
Moves lamports from a source account to a destination, with the amount given by a little-endian u64 in instruction data.
| Language | CU Usage |
|---|---|
| Rust | 459 |
| Zig | 38 |
| C | 104 |
| Assembly | 30 |
| Rust (pinocchio) | 28 |
This one starts to get interesting since it requires parsing the instruction input. Since the assembly version knows exactly where to find everything, it can be hyper-optimized. The pinocchio version performs better than the assembly implementation!
Allocates a PDA given by the seed "You pass butter" and a bump seed in the
instruction data. This requires a call to create_program_address to check the
address and invoke_signed to CPI to the system program.
| Language | CU Usage | CU Usage (minus syscalls) |
|---|---|---|
| Rust | 3698 | 1198 |
| Zig | 2809 | 309 |
| C | 3122 | 622 |
| Rust (pinocchio) | 2802 | 302 |
Note: create_program_address consumes 1500 CUs, and invoke consumes 1000, so
we can subtract 2500 CUs from each program to see the actual cost of the program
logic.
A program to compare two Pubkey instances. This operation is very common in
on-chain programs, but it can be expensive.
| Language | CU Usage |
|---|---|
| Rust | 14 |
| Zig | 15 |
A reduced instruction set from SPL-Token. Includes an entrypoint, instruction deserialization, and account serde. The Rust version is the full SPL Token program.
- Initialize Mint
| Language | CU Usage |
|---|---|
| Rust | 1115 |
| Zig | 152 |
- Initialize Account
| Language | CU Usage |
|---|---|
| Rust | 2071 |
| Zig | 175 |
- Mint To
| Language | CU Usage |
|---|---|
| Rust | 2189 |
| Zig | 154 |
- Transfer
| Language | CU Usage |
|---|---|
| Rust | 2208 |
| Zig | 145 |
- Burn
| Language | CU Usage |
|---|---|
| Rust | 2045 |
| Zig | 141 |
- Close Account
| Language | CU Usage |
|---|---|
| Rust | 1483 |
| Zig | 122 |