Referrer discount token amount can be manipulated
The Unlock protocol mints UDT tokens to referrers based on the transaction gas price, which the purchaser controls. An attacker could buy a key with themselves as referrer at a high gas price to receive more UDT tokens, potentially profiting if the market price of UDT is favourable.
Submitted by cmichel
The Unlock.recordKeyPurchase function is called on each key purchase (MixinPurchase.purchase) and mints UDT tokens to the referrer. The amount to mint is based on the transaction’s gas price which is controlled by the caller (purchaser):
uint tokensToDistribute = (estimatedGasForPurchase * tx.gasprice) * (125 * 10 ** 18) / 100 / udtPrice;
Impact
Tokens can be minted by purchasing a key with themself as the referrer at a high transaction gas price. Depending on the UDT price on external markets, it could be profitable to buy a key at a high gas price, receive UDT and then sell them on a market for a profit.
Recommended Mitigation Steps
The amount minted should be more predictable and not depend on the user’s gas price input. Consider declaring an average gas price storage variable that is set by a trusted party and use this one instead.
julien51 (Unlock Protocol) disagreed with severity and commented:
Depending on the UDT price on external markets, it could be profitable to buy a key at a high gas price, receive UDT and then sell them on a market for a profit.
Since we get the token price from the Uniswap oracle, the amount of tokens received is always at most equal to what they would have spent to acquire them on Uniswap.
0xleastwood (judge) commented:
As the uniswap oracle provides averaged price data, if there is any discrepancy between the spot price and the TWAP price, this can definitely be abused to extract value from the protocol. Keeping this as
medium.
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 reward calculation uses the transaction gas price, which is user-controlled, instead of a trusted average gas price.
Impact
An attacker could mint more UDT tokens than intended and potentially profit by selling them, though the Uniswap oracle may limit the profit.
What the attacker needed
Purchaser can set gas price; attacker can be referrer
The fix
The amount minted should be based on a trusted average gas price rather than the user's gas price.
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 in this system, the person who referred you gets some reward tokens. The amount of reward is calculated using the gas price you paid, which you can set yourself. So you could pay a very high gas price to get a bigger reward, and if those reward tokens are worth more than the extra gas cost, you make a profit.
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.