Skip to content
Business logic Audit finding Advanced

An attacker can manipulate each pod and gain an advantage over the remainder Operators

The smart contract selects a pod and an operator using the same random number, creating a biased distribution. An attacker can manipulate pod membership to increase their chance of being selected for jobs.

eighty Follow

Originally disclosed on Code4rena

Submitted by eighty, also found by d3e4, eighty, Lambda, and eighty

In contracts/HolographOperator.sol#crossChainMessage, each Operator is selected by:

  • Generating a random number (L499)
  • A pod is selected by dividing the random with the total number of pods, and using the remainder (L503)
  • An Operator of the selected pod is chosen using the same random and dividing by the total number of operators (L511).

This creates an unintended bias since the first criterion (the random) is used for both selecting the pod and selecting the Operator, as explained in a previous issue (M001-Biased distribution). In this case, an attacker knowing this flaw can continuously monitor the contracts state and see the current number of pods and Operators. Accordingly to the documentation and provided flow:

  • An Operator can easily join and leave a pod, albeit when leaving a small fee is paid
  • An Operator can only join one pod, but an attacker can control multiple Operators
  • The attacker can then enter and leave a pod to increase (unfairly) his odds of being selected for a job

Honest Operators may feel compelled to leave the protocol if there are no financial incentives (and lose funds in the process), which can also increase the odds of leaving the end-users at the hands of a malicious Operator.

Proof of Concept

Consider the following simulation for 10 pods with a varying number of operators follows (X → “does not apply”):

Pod n | Pon len | Op0 | Op1 | Op2 | Op3 | Op4 | Op5 | Op6 | Op7 | Op8 | Op9 | Total Pod |

P0 | 10 | 615 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 615 |

P1 | 3 | 203 | 205 | 207 | X | X | X | X | X | X | X | 615 |

P2 | 6 | 208 | 0 | 233 | 0 | 207 | 0 | X | X | X | X | 648 |

P3 | 9 | 61 | 62 | 69 | 70 | 65 | 69 | 61 | 60 | 54 | X | 571 |

P4 | 4 | 300 | 0 | 292 | 0 | X | X | X | X | X | X | 592 |

P5 | 10 | 0 | 0 | 0 | 0 | 0 | 586 | 0 | 0 | 0 | 0 | 586 |

P6 | 2 | 602 | 0 | X | X | X | X | X | X | X | X | 602 |

P7 | 7 | 93 | 93 | 100 | 99 | 76 | 74 | 78 | X | X | X | 613 |

P8 | 2 | 586 | 0 | X | X | X | X | X | X | X | X | 586 |

P9 | 6 | 0 | 190 | 0 | 189 | 0 | 192 | X | X | X | X | 571 |

At this stage, an attacker Mallory joins the protocol and scans the protocol (or interacts with - e.g. getTotalPods, getPodOperatorsLength). As an example, after considering the potential benefits, she chooses pod P9 and sets up some bots [B1, B2, B3]. The number of Operators will determine the odds, so:

Pod P9 | Alt len | Op0 | Op1 | Op2 | Op3 | Op4 | Op5 | Op6 | Op7 | Op8 | Op9 | Total Pod |

P9A | 4 | 0 | 276 | 0 | 295 | X | X | X | X | X | X | 571 |

P9B | 5 | 0 | 0 | 0 | 0 | 571 | X | X | X | X | X | 571 |

P9 | 6 | 0 | 190 | 0 | 189 | 0 | 192 | X | X | X | X | 571 |

P9C | 7 | 66 | 77 | 81 | 83 | 87 | 90 | 87 | X | X | X | 571 |

P9D | 8 | 0 | 127 | 0 | 147 | 0 | 149 | 0 | 148 | X | X | 571 |

And then:

  1. She waits for the next job to fall in P9 and keeps an eye on the number of pods, since it could change the odds.
  2. After an Operator is selected (he pops from the array), the number of available Operators change to 5, and the odds change to P9B.
  3. She deploys B1 and it goes to position Op5, odds back to P9. If the meantime the previously chosen Operator comes back to the pod, see the alternative timeline.
  4. She now has 1/3 of the probability to be chosen for the next job:

4.1 If she is not chosen, she will assume the position of the chosen Operator, and deploys B2 to maintain the odds of P9 and controls 2/3 of the pod. 4.2 If she is chosen, she chooses between employing another bot or waiting to execute the job to back to the pod (keeping the original odds). 5. She can then iterate multiple times to swap to the remainder of possible indexes via step 4.1.

Alternative timeline (from previous 3.):

  1. The chosen Operator finishes the job and goes back to the pod. Now there’s 7 members with uniform odds (P9C).
  2. Mallory deploys B2 and the length grows to 8, the odds turn to P9D and she now controls two of the four possible indexes from which she can be chosen.

There are a lot of ramifications and possible outcomes that Mallory can manipulate to increase the odds of being selected in her favor.

Recommended Mitigation Steps

As stated in M001-Biased distribution, use two random numbers for pod and Operator selection. Ideally, an independent source for randomness should be used, but following the assumption that the one used in L499 is safe enough, using the most significant bits (e.g. random >> 128) should guarantee an unbiased distribution. Also, reading the EIP-4399 could be valuable.

Additionally, since randomness in blockchain is always tricky to achieve without an oracle provider, consider adding additional controls (e.g. waiting times before joining each pod) to increase the difficulty of manipulating the protocol.

And finally, in this particular case, removing the swapping mechanism (moving the last index to the chosen operator’s current index) for another mechanism (shifting could also create conflicts with backup operators?) could also increase the difficulty of manipulating a particular pod.

gzeon (judge) commented:

Considering this as duplicate of #169 since they share the same root cause.

ACC01ADE (Holograph) confirmed and commented:

Really love this analysis!

gzeon (judge) commented:

Judging this as high risk due to possible manipulation.

Trust (warden) commented:

Agree this is a high severity find. Believe issue #167 and this one are essentially different exploits of the same flaw and therefore should be bulked. Relevant org discussion here.

gzeon (judge) commented:

Agreed.


The original report as published on Code4rena, by eighty. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the same random number is used for both pod and operator selection, causing a biased distribution.

Impact

An attacker could increase their odds of being selected for jobs, potentially disadvantaging honest operators and end-users.

What the attacker needed

Attacker controls multiple operators; attacker can join and leave pods; attacker can monitor contract state

The fix

Use two independent random numbers for pod and operator selection, and consider adding controls like waiting times before joining a pod.

How it was found

  1. Attacker scans the protocol to see the number of pods and operators.
  2. Attacker chooses a pod and sets up multiple operator bots.
  3. Attacker waits for a job in that pod and monitors the number of pods.
  4. After an operator is selected, the number of available operators changes, altering the odds.
  5. Attacker deploys a bot to restore the odds and control a larger fraction of the pod.
  6. Attacker repeats the process to swap to other possible indexes and increase selection odds.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract picks a random operator to do a job, but it uses the same random number twice, which makes some operators more likely to be picked. An attacker can join and leave groups of operators to take advantage of this and get picked more often.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Holograph contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.