# Potential economic attack on UDT grants to the referrer

Unlock's recordKeyPurchase mints UDT to referrers based on hardcoded estimatedGasForPurchase*gasprice, letting attackers inflate gas via gas-saving tokens to mint excess UDT.

- Payout: Audit contest
- Severity: medium
- Program: Unlock Protocol
- Found by: WatchPug
- Disclosed: 2022-04-20
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2021-11-unlock-findings/issues/186
- Library page: https://bugbountylibrary.com/r/c4%3A2021-11-unlock%3AM-02
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:reward-distribution

**Target:** Unlock.sol recordKeyPurchase UDT distribution
**Root cause:** UDT reward to referrer is computed as estimatedGasForPurchase * tx.gasprice / udtPrice, using a hardcoded gas estimate and the caller-controlled tx.gasprice rather than actual gas spent.
**Steps:**
1. Create a lock with a gas-saving token (SELFDESTRUCT-refund token) as payment token
2. Mint gas-saving token cheaply at 1 gwei
3. Call purchase() with high tx.gasprice (e.g. 1000 gwei) using 48 storage slots to maximize gas refund
4. Receive UDT worth estimatedGasForPurchase * tx.gasprice, exceeding actual gas cost
**How found:** Code review of recordKeyPurchase reward formula; noticed reward depends on tx.gasprice and a hardcoded gas estimate rather than actual gas used, then reasoned about gas-refund tokens to decouple real cost from reward.
**Exploitation:** Attacker creates a lock accepting a gas-refund token, purchases at inflated gasprice so the hardcoded estimatedGasForPurchase*gasprice formula mints UDT far exceeding real gas spent, netting ~0.8 ETH worth of UDT per cycle.
**Escalation:** Repeat purchases across many locks to scale minted UDT; also exploitable if estimatedGasForPurchase is misconfigured high or network upgrades lower real gas cost.
**Insight:** When a reward formula multiplies a hardcoded gas estimate by caller-supplied tx.gasprice, look for ways to make real gas cost far below the estimate (gas-refund/SELFDESTRUCT tokens, EIP-1559 changes) to mint value.
