Miners Can Re-Roll the VRF Output to Game the Protocol
The protocol uses a verifiable random function (VRF) to generate random numbers, but the VRF output is fulfilled in the same block as the request. A miner or well-funded user can re-org the chain to exclude the VRF output and produce a new one, potentially gaining an advantage in the protocol.
Submitted by leastwood.
Impact
Miners are able to rewrite a chain’s history if they dislike the VRF output used by the protocol. Consider the following example:
- A miner or well-funded user is participating in the PoolTogether protocol.
- A VRF request is made and fulfilled in the same block.
- The protocol participant does not benefit from the VRF output and therefore wants to increase their chances of winning by including the output in another block, producing an entirely new VRF output. This is done by re-orging the chain, i.e. following a new canonical chain where the VRF output has not been included in a block.
- This attack can be continued as long as the attacker controls 51% of the network. The miner itself could control a much smaller proportion of the network and still be able to mine a few blocks in succession, although this is of low probability but entirely possible.
- A well-funded user could also pay miners to re-org the chain on their behalf in the form of MEV to achieve the same benefit.
The PoolTogether team is aware of this issue but is yet to mitigate this attack vector fully.
Proof of Concept
- https://docs.chain.link/docs/vrf-security-considerations/#choose-a-safe-block-confirmation-time-which-will-vary-between-blockchains
- https://github.com/pooltogether/pooltogether-rng-contracts/blob/master/contracts/RNGChainlink.sol
- https://github.com/pooltogether/v4-core/blob/master/contracts/DrawBeacon.sol#L311-L324
- https://github.com/pooltogether/v4-core/blob/master/contracts/DrawBeacon.sol#L218-L232
- https://github.com/pooltogether/blockhash-analysis-simulation
Tools Used
- Manual code review
- Discussions with Brendan
Recommended Mitigation Steps
Consider adding a confirmation time between when the actual VRF request was made and when it was later fulfilled on-chain. This could be as few as 5 blocks, reducing the probability of an effective chain reorganization to extremely close to 0.
asselstine (PoolTogether) acknowledged:
Yes, this is something I’ve known for awhile. The VRF operator whose signature we are requesting could collude with a miner to manipulate the blockhash that is being fed to the VRF.
We’re using the original VRF implementation by Chainlink. VRF 2.0 is rolling out soon, and we’ll explore confirmation times with their team.
Alex the Entreprenerd (judge) commented:
The warden has identified a “supply chain” attack on the VRF, while the finding may seem innocuous, it does pose the fundamental question as to whether Chainlink’s VRF is a source of truly verifiable randomness that won’t be gamed for personal gains.
The sponsor does agree on the attack vector, the miner and the chainlink provider could collude with the purpose of gaming the system.
I find it hard to leave this as a High Severity finding, because it implies that Chainlink’s VRF Service is flawed in it’s design
However, if trace of proof of collusion between miners and chainlink operators where to be found, this would question the impartiality of their service.
Alex the Entreprenerd (judge) commented:
After a day of thinking I’ve decided to leave the finding as high risk. Not as a statement to Chainlink’s security model, as that’s outside of scope, but because the finding is objectively true.
A malicious operator can, in conjunction with a miner, re-roll the VRF to pursue their own gains.
I’m not sure what could be done to mitigate this at the chain level, it seems to me that at this time, there may be no source of true randomness that can be achieved on-chain without assuming a degree of counter-party 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 VRF request and fulfilment occur in the same block, allowing a miner to re-org the chain and obtain a different VRF output.
Impact
A miner or well-funded user could re-org the chain to get a favourable VRF output, potentially increasing their chances of winning, but this requires significant mining power or collusion.
What the attacker needed
Miner or well-funded user; control of mining power or collusion
The fix
The fix should add a confirmation time (e.g., 5 blocks) between the VRF request and fulfilment to reduce the probability of a successful re-org.
How it was found
- A miner or well-funded user participates in the protocol.
- A VRF request is made and fulfilled in the same block.
- The participant does not benefit from the VRF output and wants a different one.
- They re-org the chain to exclude the block containing the VRF output, producing a new VRF output.
- This can be repeated as long as the attacker controls enough mining power.
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 VRF is a service that produces random numbers that can be verified on a blockchain. The protocol uses this randomness to pick winners. The report says that because the random number is generated in the same block as the request, a miner can choose to ignore that block and create a new chain without it, effectively getting a new random number. This could let them cheat the system.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.