|
| 1 | +title = "Out-of-order retryable transactions" |
| 2 | +verbose_name = "out-of-order-retryable" |
| 3 | +severity = "major" |
| 4 | +category = "antipattern" |
| 5 | +weight = 60 |
| 6 | +description = """ |
| 7 | +Out-of-order retryable transactions |
| 8 | +
|
| 9 | +<!--more--> |
| 10 | +
|
| 11 | +## Exploit Scenario |
| 12 | +
|
| 13 | +```solidity |
| 14 | +contract L1 { |
| 15 | + function doStuffOnL2() external { |
| 16 | + // Retryable A |
| 17 | + IInbox(inbox).createRetryableTicket({ |
| 18 | + to: l2contract, |
| 19 | + l2CallValue: 0, |
| 20 | + maxSubmissionCost: maxSubmissionCost, |
| 21 | + excessFeeRefundAddress: msg.sender, |
| 22 | + callValueRefundAddress: msg.sender, |
| 23 | + gasLimit: gasLimit, |
| 24 | + maxFeePerGas: maxFeePerGas, |
| 25 | + data: abi.encodeCall(l2contract.claim_rewards, ()) |
| 26 | + }); |
| 27 | + // Retryable B |
| 28 | + IInbox(inbox).createRetryableTicket({ |
| 29 | + to: l2contract, |
| 30 | + l2CallValue: 0, |
| 31 | + maxSubmissionCost: maxSubmissionCost, |
| 32 | + excessFeeRefundAddress: msg.sender, |
| 33 | + callValueRefundAddress: msg.sender, |
| 34 | + gasLimit: gas, |
| 35 | + maxFeePerGas: maxFeePerGas, |
| 36 | + data: abi.encodeCall(l2contract.unstake, ()) |
| 37 | + }); |
| 38 | + } |
| 39 | +} |
| 40 | +
|
| 41 | +contract L2 { |
| 42 | + function claim_rewards() public { |
| 43 | + // rewards is computed based on balance and staking period |
| 44 | + uint unclaimed_rewards = _compute_and_update_rewards(); |
| 45 | + token.safeTransfer(msg.sender, unclaimed_rewards); |
| 46 | + } |
| 47 | +
|
| 48 | + // Call claim_rewards before unstaking, otherwise you lose your rewards |
| 49 | + function unstake() public { |
| 50 | + _free_rewards(); // clean up rewards related variables |
| 51 | + balance = balance[msg.sender]; |
| 52 | + balance[msg.sender] = 0; |
| 53 | + staked_token.safeTransfer(msg.sender, balance); |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | +Bob calls `doStuffOnL2` but the first retryable ticket calling `claim_rewards` fails. The second retryable ticket calling `unstake` is executed successfully. As a result, Bob loses his rewards. |
| 58 | +
|
| 59 | +## Recommendation |
| 60 | +Do not rely on the order or successful execution of retryable tickets. |
| 61 | +
|
| 62 | +## Learn more |
| 63 | +[out-of-order-retryable](https://github.com/crytic/slither/wiki/Detector-Documentation#out-of-order-retryable-transactions) on Slither's wiki. |
| 64 | +""" |
0 commit comments