Bad source of randomness
The contract used block.number and block.timestamp as a source of randomness to select a primary operator. A compromised layer-zero endpoint could retry the selection until the result favoured the attacker.
Submitted by minhtrng, also found by 141345, adriro, cdahlheimer, d3e4, Deivitto, ladboy233, nadin, teawaterwire, and V_B
HolographOperator.sol#L491-L511
Using block.number and block.timestamp as a source of randomness is commonly advised against, as the outcome can be manipulated by calling contracts. In this case a compromised layer-zero-endpoint would be able to retry the selection of the primary operator until the result is favorable to the malicious actor.
Proof of Concept
An attack path for rerolling the result of bad randomness might look roughly like this:
function attack(uint256 currentNonce, uint256 wantedPodIndex, uint256 numPods, uint256 wantedOperatorIndex, uint256 numOperators, bytes calldata bridgeInRequestPayload) external{
bytes32 jobHash = keccak256(bridgeInRequestPayload);
//same calculation as in HolographOperator.crossChainMessage
uint256 random = uint256(keccak256(abi.encodePacked(jobHash, currentNonce, block.number, block.timestamp)));
require(wantedPodIndex == random % numPods)
require(wantedOperatorIndex == random % numOperators);
operator.crossChainMessage(bridgeInRequestPayload);
}
The attack basically consists of repeatedly calling the attack function with data that is known and output that is wished for until the results match and only then continuing to calling the operator.
Recommended Mitigation Steps
Consider using a decentralized oracle for the generation of random numbers, such as Chainlinks VRF.
It should be noted, that in this case there is a prerequirement of the layer-zero endpoint being compromised, which confines the risk quite a bit, so using a normally unrecommended source of randomness could be acceptable here, considering the tradeoffs of integrating a decentralized oracle.
ACC01ADE (Holograph) confirmed and commented:
Very valid issue.
While sponsor noted this is a design choice to use pseudorandomness, as pointed out by the warden a compromised layer-zero-endpoint can exploit this for profit, judging this as Medium risk.
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 contract relied on block.number and block.timestamp as a source of randomness, which is predictable and can be retried by a compromised layer-zero endpoint.
Impact
A compromised layer-zero endpoint could manipulate operator selection for profit, though the risk is confined by that prerequisite.
What the attacker needed
Compromised layer-zero endpoint
The fix
The report recommends using a decentralised oracle such as Chainlink VRF for random number generation, but notes the tradeoffs given the prerequisite of a compromised endpoint.
How it was found
- Compute the same random value as the contract using the job hash, nonce, block number and timestamp.
- Check whether the random value matches the desired pod index and operator index.
- If it matches, call the operator's crossChainMessage function; otherwise retry with different data.
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.
Randomness on a blockchain is hard because block data is public and predictable. Here, the contract used block number and timestamp to pick an operator, so someone who could resend messages could keep trying until they got the operator they wanted.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.