# MEV miner can mint larger than expected UDT total supply

Unlock Protocol reimburses gas via tx.gasprice, letting a miner inflate gas price to mint up to half of UDT total supply.

- Payout: Audit contest
- Severity: high
- Program: Unlock Protocol
- Found by: elprofesor
- Disclosed: 2022-04-20
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2021-11-unlock-findings/issues/135
- Library page: https://bugbountylibrary.com/r/c4%3A2021-11-unlock%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:code4rena sev:high tech:evm technique:source-review vuln:accounting-error vuln:oracle-manipulation

**Target:** UnlockProtocol.recordKeyPurchase gas reimbursement logic
**Root cause:** Gas reimbursement tokensToDistribute is computed from user-supplied tx.gasprice with no oracle or bounds, so an arbitrary gas price directly inflates minted UDT up to maxTokens (half total supply).
**Steps:**
1. Call `recordKeyPurchase` with a purchase amount and an arbitrarily high `tx.gasprice`.
2. Observe `tokensToDistribute = (estimatedGasForPurchase * tx.gasprice) * (125 * 10**18) / 100 / udtPrice` scales linearly with gasprice.
3. As a miner, include the tx in your own block and reimburse the gas cost to yourself.
4. Mint up to `maxTokens` (totalSupply/2) UDT and sell on the open market.
**How found:** Code reading of the reimbursement formula noticing tx.gasprice is attacker-controllable and only bounded by maxTokens, which is set to totalSupply/2.
**Exploitation:** Miner submits or colludes on a purchase tx with inflated tx.gasprice, pays the gas to themselves, and receives inflated UDT reimbursement capped at half total supply, then sells tokens on market for profit.
**Escalation:** Miner controls blockspace so can fill blocks with such txs and repeatedly extract value; single tx can distribute half of token supply.
**Insight:** When a contract reimburses gas using tx.gasprice, treat it as attacker-controlled input; miners can self-reimburse, so any linear scaling to a mint cap becomes a value-extraction primitive.
