MEV miner can mint larger than expected UDT total supply
The Unlock Protocol calculates gas reimbursement using the transaction's gas price, which a miner can arbitrarily set. A malicious miner could therefore inflate the number of UDT tokens minted as reimbursement, potentially up to half the total supply, and sell them for profit.
Originally disclosed on Code4rena
Submitted by elprofesor
UnlockProtocol attempts to calculate gas reimbursement using tx.gasprice, typically users who falsify tx.gaspricewould lose gas to miners and therefore not obtain any advantage over the protocol itself. This does present capabilities for miners to extract value, as they can submit their own transactions, or cooperate with a malicious user, reimbursing a portion (or all) or the tx.gasprice used. As the following calculation is made;
uint tokensToDistribute = (estimatedGasForPurchase * tx.gasprice) * (125 * 10 ** 18) / 100 / udtPrice;
we can see that arbitrary tx.gasprices can rapidly inflate the tokensToDistribute. Though capped at maxTokens, this value can be up to half the total supply of UDT, which could dramatically affect the value of UDT potentially leading to lucrative value extractions outside of the pool.
Recommended Mitigation Steps
Using an oracle service to determine the average gas price and ensuring it is within some normal bounds that has not been subjected to arbitrary value manipulation.
julien51 (Unlock Protocol) disputed and commented:
we can see that arbitrary tx.gasprices can rapidly inflate the tokensToDistribute. Though capped at maxTokens, this value can be up to half the total supply of UDT, which could dramatically affect the value of UDT potentially leading to lucrative value extractions outside of the pool.
As you noted it would be capped by the actual increase of the GDP transaction.
However we could indeed use an oracle to determine the average gas price over a certain number of blocks to limit the risk even further.
0xleastwood (judge) commented:
I think the warden has raised a valid issue of value extractions. Whether the value extracted is capped at a certain number of tokens, I don’t think the issue is nullified as a result. Miners can realistically fill up blockspace by abusing this behaviour and then selling netted tokens on the open market. I’ll consider marking this as
medium, what do you think @julien51 ?
0xleastwood (judge) commented:
I think
maxTokenswill be set toIMintableERC20(udt).totalSupply() / 2upon the first call torecordKeyPurchase(). If I’m not mistaken, this could allow a malicious miner could effectively distribute half of the token supply in one tx.
0xleastwood (judge) commented:
After further offline discussions with @julien51. We agree that this is an issue that needs to be addressed.
If we consider real-world values for
IMintableERC20(udt).totalSupply()andIMintableERC20(udt).totalSupply()as1_000_000e18and400e18respectively. Then a miner could mint up to ~1247UDTtokens valued at $USD 124,688 if they provide a single Ether as their purchase amount. Obviously this can be abused to generate a huge amount of profit for miners, so as this is a viable way to extract value from the protocol, I will be keeping this ashighseverity.
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
The reimbursement formula uses the user-supplied `tx.gasprice` without any validation or cap relative to a trusted oracle, allowing a miner to manipulate the minted amount.
Impact
A malicious miner could mint up to half of the UDT total supply in a single transaction and sell the tokens on the open market, extracting significant value from the protocol.
What the attacker needed
Attacker must be a miner or collude with one; attacker can submit a transaction with arbitrary gas price
The fix
The gas price used in the reimbursement calculation should be determined by an oracle that provides an average over a number of blocks, and the value should be bounded to prevent arbitrary manipulation.
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.
When you buy a key on Unlock Protocol, the protocol pays you back in its own token (UDT) for the gas you spent. The amount is calculated using the gas price you set in your transaction. A miner, who decides which transactions go into a block, can set a very high gas price for their own transaction, get a huge UDT payout, and then sell those tokens.
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.