Open code423n4 opened 2 years ago
Considering this as duplicate of #169 since they share the same root cause.
Really love this analysis!
Judging this as high risk due to possible manipulation.
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
Agreed
Lines of code
https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographOperator.sol#L484-L539 https://github.com/code-423n4/2022-10-holograph/blob/main/contracts/HolographOperator.sol#L1138-L1144
Vulnerability details
H001 An attacker can manipulate each pod and gain an advantage over the remainder Operators
Impact
In contracts/HolographOperator.sol#crossChainMessage, each Operator is selected by:
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: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
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 podP9
and sets up some bots[B1, B2, B3]
. The number of Operators will determine the odds, so:And then:
P9
and keeps an eye on the number of pods, since it could change the odds.P9B
.B1
and it goes to positionOp5
, odds back toP9
. If the meantime the previously chosen Operator comes back to thepod
, see the alternative timeline.B2
to maintain the odds ofP9
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).Alternative timeline (from previous 3.):
P9C
).B2
and the length grows to 8, the odds turn toP9D
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.
Tools Used
Manual
Recommended Mitigation Steps
Has 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.