# How a failed transaction steered a Bittensor MEV bot

The taostats research team unravelled a MEV bot's mechanism.  In release 492, this MEV attack vector was stopped.

_Source: https://taostats.io/blog/how-a-failed-transaction-steered-a-bittensor-mev-bot_  
_Author: Doug Sillars, Head of Community and Education_  
_Published: 2026-11-21_  
_Category: Research_

# What MEV is
MEV (maximal extractable value) is profit made by controlling the order of transactions in a block. Typically a bot places its own trades just before and just after someone else's.

## Staking sandwich attack
Staking TAO into a subnet swaps it for that subnet's alpha through a pool, and a big stake pushes the alpha price up. A sandwich bot stakes just before you and unstakes just after you, in the same block. It pockets the price move your stake caused, and you get a little less alpha.

To do that, the bot has to get its first trade in ahead of yours.

## The Sandwich attack (now blocked)

Here's one such attack, which the taostats research team uncovered. We provided this vector to the chain developers through private channels, and the developers moved quickly to shut down this vector.

### Step 1: get in line every block
Every block, the bot sent a call to its own smart contract. That call didn't say what to trade. When it ran, it first checked for instructions. Because it was sent early, it sat near the front of the queue.

### Step 2: watch the mempool
The operator watched pending transactions. Most blocks had nothing worth attacking, so it sent nothing else. The contract call ran, found no instructions and did nothing.

### Step 3: send the order as a tip
When the operator saw a trade it could sandwich, it sent a second transaction from a separate signal wallet. That transaction called `set_heap_pages`, which only the chain's admin is allowed to use, so it always failed.

But failure was the point. The bot only cared about the tip that was included in the call, not the call itself. A failed transaction still pays its fee and tip. The tip amount was a code that said what to do (stake or unstake), which subnet, and which size from a fixed list of stakes. The code was scrambled with a key that changed every block, so you couldn't read it just by looking at the tips.

### Step 4: jump the queue
Before release 492, `set_heap_pages` counted as an "Operational" call. That class gets top priority, so the failed signal executed before the waiting contract call, even though it was sent later.

The wallet that sent the call had the transaction fee, and the tip balance removed from it's account balance.

### Step 5: read the balance
When the contract call ran, it checked how much the signal wallet's balance had dropped. Take away the known fee and what's left is the tip, which gives the order.  (We include how the tip was decoded in the deep dive at the end of this article.) The contract has two options:

#### Order found: 
Stake into the target subnet, let the victim's trade go through, unstake straight after in the same block.  MEV accomplished.
#### No order: 
Do nothing. Pay the small transaction fee for an empty extrinsic.

## The cost
The bot paid for one small contract call every block, and for a signal fee plus tip only when it attacked. Watching was cheap, and it paid more only when there was money to make.

## How it was closed
While analysing the pattern, Taostats worked out how these attacks were being made and alerted the Opentensor Foundation (OTF) through a private channel. The fix was [subtensor PR #3341](https://github.com/RaoFoundation/subtensor/pull/3341), shipped in runtime 492. It went live at block 9,542,321 on 19 Nov 2026. 

Now only Operational calls signed by the admin key keep top priority. A signal from an ordinary wallet waits in line like any other transaction, so it can't get ahead of the contract call any more.

## What happened next
The bots we tracked stopped trading in the hours before 492 went live and moved their stake back to root. We've seen no trading from their known wallets since.

**This closes one route. It doesn't end MEV on Bittensor.**

## Under the hood: a deep dive
The five steps above are the whole idea. This section shows the actual numbers, for the bot we call Tip Bot.

### 1. Priority beat tips
Before runtime 492, every transaction got a priority number from its type:

* Operational calls such as `set_heap_pages`: 10,000,000,000
* Normal calls, including the bot's contract call: 1.
* Among equal-priority transactions, the one that was ready first went first. That's why the bot sent its contract call early.

### 2. The code inside the tip
The `set_heap_pages` order tip was always between 65,536 and 131,071 rao (well under 0.001 TAO). The top bit marked it as a real order, and the 16 bits below it held the code. Before reading it, the contract unscrambled those 16 bits with a key built into its code and the block number, so the same order looked different in every block.

Tip Bot order, 16 bits, after unscrambling:
* Action: 2 bits
* Subnet: 7 bits
* Size: 4 bits
* Other: 3 bits
  
What each term meant: 

* Action: stake, or unstake.
* Subnet: which subnet to trade.
* Size: a number from 0 to 15 that picks a stake from a fixed list: 3, 5, 8, 11, 16, 22, 30, 40, 52, 66, 82, 100, 120, 145, 170 or 199 TAO.
* Other: we never found a role for these bits.

### 3. How the contract read the balance
The contract call carried the signal wallet's balance from the block before. When the call ran, the contract measured what was left in the wallet. The drop was the signal's fee plus its tip. Taking off the known fee left the tip, which the contract unscrambled into the order.

If the balance hadn't dropped, there was no order and the contract stopped without trading.

### 4. One real block: 9,435,627, subnet 38
| Extrinsic |	What happened |	Ready at our node |
|---|---|---|
|  4   |   Signal: set_heap_pages fails, tip 67,652 rao    |  0.04 s after the slot started      |
|6	| Tip Bot stakes 16 TAO	| 11.2 s before |
| 14	| Another bot stakes 4.66 TAO	| 7.0 s before| 
| 16	| User stakes|  9.97 TAO| 	7.0 s before| 
| 17	| The other bot unstakes| 	not recorded| 
| 24| 	Tip Bot unstakes, gets 16.0456 TAO back	| 0.04 s after| 

The contract call was ready 11 seconds early, and the signal arrived at the last moment. The signal still ran first. Tip Bot put in 16 TAO and took out 16.0456 TAO. That is before costs, and it isn't a measured loss for the user.

> [!NOTE]
> ### Decoding the tip: 
> 67,652 rao → stake, subnet 38, 16 TAO
> How do we get there?
>
> **Step 1:** check the marker. 67,652 is above 65,536 (2^16), so the marker bit is set and this is a real order. Take off the marker:
>
> 67,652 − 65,536 = 2,116 → in binary: 0000 1000 0100 0100
>
> **Step 2:** make this block's key. Hash the key stored in the contract's code together with the block number (9,435,627) using keccak256. Keep the last 16 bits:
>
> …c20f1ae0 → last 16 bits 0x1AE0 → 0001 1010 1110 0000
>
> **Step 3:** unscramble (XOR). Line the two up, and wherever the bits differ the answer is 1:
>
> |   |    |
> | ---|---|
> | tip |     0000 1000 0100 0100 |
> |key  |    0001 1010 1110 0000|
>  | |        ------------------- |
> | order |    0001 0010 1010 0100|
>
> **Step 4:** split the order into fields.
>
> |   |    | | | | 
> | ---|---|---|---|---|
> |order |   00 | 0100101 | 0100 | 100|
> |      | action    |  subnet - 1       = 37       | size   = 4|     other (unused)|
>
> * Size 4 = 5th entry of the list 3, 5, 8, 11, 16, … = 16 TAO
>
> **Result:**: Stake 16 TAO into subnet 38. That's exactly what Tip Bot did at position 6, right after the signal.
>
> Because the key changes with the block number, the same order would need a different tip in the next block. Reading the tips on their own tells you nothing; you need the key from the contract.

### 5. What runtime 492 changed
PR #3341 keeps the Operational priority only for calls signed by the sudo key. A failing set_heap_pages from an ordinary wallet now gets normal priority and no longer jumps the line. The signal can't arrive before the contract call, so the contract has nothing to read when it runs.

Observed on Bittensor mainnet, runtime v486, November 2026. For the full investigation, including a second bot that used the same trick, see the [technical paper](https://s3.hippius.com/rufus/public/mev-bot-evm-signalling-paper.html).
