Under the Hood of Solana Transactions: From PoH to BPF Execution

Tushar Bhatia
5 min readNov 5, 2024

--

Welcome back! If you read my last article on Solana’s Proof of History (PoH), you know PoH is like the backstage manager, ensuring transactions are timestamped and in order. But what happens next? How does Solana actually execute a transaction? And what’s this “BPF Loader” anyway? Where is the Compiler?

Today, we’re going to break down what really happens under the hood when you send a transaction on Solana. From PoH to the BPF Loader, we’ll cover the entire journey in a way that’s easy to digest. Let’s get started!

1. Solana Transaction Lifecycle: It All Starts with a Click

Imagine you’re sending SOL to a friend, buying an NFT, or swapping tokens. You hit Send, and here’s what happens:

Transaction Creation: You specify details like sender, receiver, and any instructions (perhaps a message like “Here’s for coffee!”).

Proof of History (PoH): PoH timestamps and sequences the transaction, ensuring it’s processed in the right order. Learn more about PoH here.

Validation through Proof of Stake (PoS): Solana’s Proof of Stake (PoS) consensus mechanism empowers validators to verify transactions. Validators, chosen based on the amount of SOL they’ve staked, confirm the transaction’s integrity by checking signatures and using PoH’s sequence for order. This dual system allows Solana to maintain ultra-fast speeds with high security. More on PoS in Solana.

2. What Happens Under the Hood?

Once validated, the transaction moves on to Solana’s processing engine. Here’s where Solana’s unique account-based model comes in:

Accounts as State Machines: Every piece of information (from user balances to smart contract data) is stored in “accounts.” Transactions interact with these accounts, updating their state in real time. Check out Solana’s account model here.

Parallel Processing: Solana’s transactions run in parallel, allowing it to handle thousands at once. Unlike blockchains that process transactions one by one, Solana groups and processes non-overlapping transactions simultaneously.

3. The BPF Loader:

If PoH is the bouncer, the BPF Loader is the chef in Solana’s kitchen, handling smart contract execution. Here’s what you need to know:

What’s BPF? BPF (Berkeley Packet Filter) originally came from Linux for network packet filtering. Solana adapted it to efficiently execute smart contracts in a resource-friendly way. More on BPF here.

The BPF Loader’s Role: Solana compiles its smart contracts into BPF bytecode, which the BPF Loader then interprets and runs. It’s like loading a mini program, executing each instruction step-by-step.

Efficiency and Security: The BPF Loader isolates each program’s execution, enhancing security and keeping fees low. Because it’s built for speed, the BPF Loader is a key reason why Solana can handle complex applications without slowing down.

4. From Start to Finish:

Let’s put it all together with an example.

Imagine you’re transferring tokens to a friend:

Initiate the Transfer: You click Send. The transaction specifies the sender, receiver, and instructions.

PoH Timestamps: PoH sequences the transaction.

Validators Verify: Using PoS, validators confirm the transaction details based on the PoH sequence.

Execution with BPF Loader: The BPF Loader loads the smart contract program and executes it, transferring tokens from your account to your friend’s.

Account Updates: Solana’s account model records the transaction and updates balances, making it official!

5. Why the BPF Loader Matters for Solana

The BPF Loader isn’t just an executor — it’s what makes Solana so unique:

Multi-Program Execution: BPF allows multiple programs to run in a single transaction, critical for DeFi and complex applications.

Low Fees and High Efficiency: BPF’s optimized execution keeps fees low while ensuring speed.

  • Security through Isolation: Each program runs in isolation, so an issue with one program doesn’t affect the others.

EVM vs. Solana Transactions: A Quick Comparison

Now that we know how a transaction typically works in Solana, let’s compare it to how EVM (Ethereum Virtual Machine) blockchains like Ethereum handle transactions. This way, we’ll get a better sense of what makes Solana so unique!

1. Execution Environment: EVM vs. BPF Loader

EVM: In EVM-based blockchains, like Ethereum, smart contracts are written in Solidity (or Vyper) and then run directly in the EVM, which is basically Ethereum’s smart contract engine. Transactions are executed one at a time, so they wait in line until it’s their turn. Plus, each transaction needs gas (a.k.a. fees) based on its complexity. This can lead to high fees, especially when the network is busy.

Solana’s BPF Loader: Solana’s programs (a.k.a. smart contracts) are written in Rust or C, then compiled into BPF bytecode, which the BPF Loader interprets and executes. This system is designed for super-fast processing, so it’s a big reason why Solana fees stay low. Solana also processes transactions in parallel, which lets it handle thousands at once, unlike the EVM’s single-file-line approach.

2. Sequential vs. Parallel Processing

EVM: EVM processes transactions sequentially, like a single-lane road. Each transaction has to wait for the previous one to complete before moving ahead. This setup can cause bottlenecks and high fees during peak times.

Solana: Solana’s parallel processing is like a multi-lane highway. Transactions that don’t interact with the same accounts can be processed at the same time, so it can handle tons of transactions without slowing down. This is one of the main reasons Solana can keep fees low and speeds high, even with lots of users on the network.

3. Stateless vs. Stateful Programs

EVM (Stateful): On Ethereum, contracts hold their own data and state (memory), which can be convenient but can also limit scalability. Each transaction modifies this “state” directly, which means it can only handle one change at a time per contract. If you’re interacting with a popular smart contract, get ready for potential congestion.

Solana (Stateless): Solana takes a different approach. Programs are stateless, meaning they don’t store data themselves. Instead, all data and state info is held in separate “accounts” that the programs interact with. This design allows more flexibility and enables Solana’s parallelism magic since programs don’t have to worry about keeping track of their own state — everything they need to read or write is external.

Wrapping Up:

So, from PoH keeping things in order to the BPF Loader making sure smart contracts run smoothly, you can see that Solana’s design is all about speed and efficiency. Every part: PoH, PoS validation, accounts, and the BPF Loader plays a role in making sure your transactions are fast, secure, and cheap.

Now, we’ve touched on accounts here, but Solana’s account and ownership system is unique and deserves its own spotlight. Stay tuned for a future article where we’ll break down how accounts and ownership actually work in Solana — because understanding that piece really brings the whole system together. In the meantime, check out Solana’s docs if you’re curious, and feel free to drop questions in the comments!

--

--

Tushar Bhatia
Tushar Bhatia

Written by Tushar Bhatia

Not Your Regular NERD Blockchain Security Expert | DeFi Innovator | Advanced Solidity Developer | Foundry Lover | Solana Enthusiast

No responses yet