404Paymaster
Description¶
Do you know what AA is? You should know that.
Solution¶
- The DN404 paymaster, which allows users to pay fees with DN404 tokens, has deposited
5 * 1e16
WETH into the entry point. To solve the challenge, we need to consume the paymaster's deposit to below1e10
-
The entry point executes userOps by two loops: validation loop and execution loop
-
During the validation loop, the required prefund fee is calculated based on arguments in userOps and deducted from the paymaster's deposit. Meanwhile, the paymaster will precharge DN404 tokens corresponding to 120% of the gas fee based on the cached price
handleOps()
will callpostOp()
on the paymaster after making the execution call. In thepostOp()
, the paymaster will refund tokens to users based on the actual gas cost and use the received tokens to refill the deposit-
Since DN404 tokens are charged at 120% of the fee, after normal execution, the paymaster's deposit will be higher than before execution. And the paymaster is using Uniswap V2 to swap DN404 tokens back to WETH. We may be able to manipulate the price by swapping, but the price cached in the paymaster obtains reserved data from the Uniswap V2 pair (i.e. flash loans won't work) and we hold too few tokens compared to the pair
-
If
innerHandleOp()
reverts due topostOp
execution failure, the entry point will only roll back the current execution instead of the entire transaction andpostOp()
will be called again withpostOpReverted
mode. In this case,postOp()
will do nothing, including refilling the deposit and refunding tokens. However, the storage that was changed during the validation loop will not be reverted and the entry point will be charged according to the gas consumed. Thus, the paymaster's deposit can be reduced -
Utilize the Uniswap V2 reentrancy lock to cause swap to fail is an easy way to let
postOp()
reverts - Then, since the gas price is under control, to increase
actualGasCost
, we need to consider how to consume as much gas as possible in a userOp - The
actualGas
calculation consists of two parts: the gas consumed by the execution and user-providedpreVerificationGas
. ThepreVerificationGas
is the extra gas to pay the bundler and can be used to increase gas consumption greatly
Exploitation¶
References¶
- ERC-4337: Account Abstraction Using Alt Mempool
- [M-01] Balance check during
MagicSpend
validation cannot ensure thatMagicSpend
has enough balance to cover the requested fund