Soldev

Solana overview

Last updated:

The Solana blockchain is a proof of stake blockchain with extra sauce:

Proof of history uses a mechanism called nLocktime that postdates transactions using block height instead of the usual timestamp.

There is no mempool, instead there is deterministic leader selection and nodes forward transactions to future leaders.

Clients declare memory locations it needs beforehand.

Multiple transactions on the same program happen in parallel with SIMD instructions. Signatures are verified on GPU's

Solana uses

  1. ed25519 for encryption
  2. sha256 for hashing (same hashing as bitcoin).

Much more complicated to develop on than Ethereum based chains.

Even normal SOL transfers on Solana are handled by a smart contract.

Programs written in Rust are pretty limited. Public types should be basic in general forget about custom crates, you can't even use most of std::collections.

For example you cannot use HashMap without modifications because by default it actually uses some sneaky thread-local static state for caching keys. Static mutable state is forbidden in Solana so it won't work.

The anchor CLI also doesn't know how to turn HashMap into IDL. For now your easiest bet is to just use a sequence of key-value pairs unfortunately.

Solana virtual machine

The actual virtual machine responsible for executing programs is usually rBPF. Not all validators use the same one, but that is the canonical.

The specific format is a custom version of eBPF called Solana Bytecode Format (sBPF).

eBPF was originally created to filter packets in the kernel but has applications in profiling because of its efficiency.

This bytecode is processed by a virtual machine called rBPF. This virtual machine only has a set of 11 registers.

namefeature setkindSolana ABI
r0allGPRReturn value
r1allGPRArgument 0
r2allGPRArgument 1
r3allGPRArgument 2
r4allGPRArgument 3
r5allGPRArgument 4 or stack spill ptr
r6allGPRCall-preserved
r7allGPRCall-preserved
r8allGPRCall-preserved
r9allGPRCall-preserved
r10allFrame pointerSystem register
r11from v2Stack pointerSystem register
pcallProgram counterHidden register

You first have your General-Purpose Registers (GPRs):

After that we have:

The virtual machine can execute eBPF programs in two ways:

  1. An intepreter
  2. Just-in-Time (JIT) compilation to x86_64 machine code

Interpreters walk each instruction one-by-one. This adds a slight runtime overhead in exchange for a big reduction in load time.

JIT is favored as it makes the runtime execution faster at the cost of a longer load time due to the increased initial compilation.

Development cycle

The development cycle on Solana looks like this:

  1. Code your program in rust
  2. Build your program which should generate an Interface Description Language (IDL) JSON file.
  3. Generate a client from this IDL file
  4. Test the programs behavior acting as a client of the chain

These are our system specs. They test behavior from the perspective of the user with all the bells and whistles of the blockchain.

The solana-test-validator can be used to set up a local chain to try these transactions out on and fetch the data to see if it is what we expect.