How to Protect Against Frontrunning on SOL

Introduction


Front-running occurs when malicious actors exploit pending transactions to manipulate prices and gain an unfair advantage. On Solana, the mempool operates differently compared to Ethereum. The mempool stream is shared from RPC nodes to validators only when they are about to become the leader (a 1.2 to 3.6-second window). This design limits access to pending transactions, making it harder for attackers to exploit them directly.

However, some validators exploit this system by operating proxy relays within their environment. These relays leak pending transaction data to malicious searchers, who then execute sandwich attacks. In such attacks, searchers place a buy order ahead of the target trade and a sell order immediately after. This manipulation inflates the price for the user's trade, causing the user to receive worse terms and undermining the integrity of the transaction.

How To Protect


Option 1: Use Jito

Using Jito is the most common way to make your transaction private. However, for the Jito Block Engine to accept your transaction, you need to include an extra priority tip in the form of a transfer instruction.

Priority Tip:

  1. The tip must be a minimum of 1,000 Lamports. However, for better prioritization, we recommend tipping at least 10,000–20,000 Lamports.

  2. The tip should be a transfer instruction directed to one of the following addresses:

[
    "ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt",
    "3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT",
    "96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
    "HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
    "Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY",
    "ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49",
    "DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
    "DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL"
]

Code Example:

const { Connection, PublicKey, Transaction, SystemProgram, Keypair } = require("@solana/web3.js");

// Set up connection and payer
const connection = new Connection("https://sol-rpc.kolibr.io/?tx_broadcast_mode=jito");
const payer = Keypair.generate(); // Replace with your wallet Keypair
const tipAddress = new PublicKey("ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt");

// Create and send transaction with TIP instruction
(async () => {
  const transaction = new Transaction().add(
    SystemProgram.transfer({
      fromPubkey: payer.publicKey,
      toPubkey: tipAddress,
      lamports: 10000, // Priority tip in lamports
    })
  );

  const signature = await connection.sendTransaction(transaction, [payer]);
  console.log(`Transaction submitted: ${signature}`);
})();

Url To Submit: https://sol-rpc.kolibr.io/?tx_broadcast_mode=jito

Option 2: Use Kolibrio Subsidy Transactions


If adding a priority tip directly to the target transaction is not possible, Kolibrio supports subsidy transactions. In this case, the originator sends a standard transaction to Kolibrio's RPC endpoint. Url To Submit: https://sol-rpc.kolibr.io/?tx_broadcast_mode=subsidy Kolibrio automatically generates an additional transaction with a Jito tip, bundles it with the original transaction, and submits the bundle to Jito. This approach ensures the transaction is prioritized and protected against front-running without modifying the original transaction. Learn more

Last updated