The LPP proposer may not be reimbursed their gas costs by the bonds at MAX_GAME_DEPTH because step() does not check if the LPP proposer is the one that called it
The step() function in the FaultDisputeGame contract does not check who proposed the Large Preimage Proposal (LPP) when awarding the bond, so an attacker can call squeezeLPP() and then step() to receive the bond that was intended to reimburse the LPP proposer for their high gas costs.
Originally disclosed on Code4rena
Submitted by RadiantLabs
Part of the reason bonds exist is to refund honest challengers for the gas costs incurred from countering malicious claims. We can observe in the Optimism specs how bond prices are chosen:
FPM bonds are priced in the amount of gas that they are intended to cover. Bonds start at the very first depth of the game at a baseline of
400_000gas. The400_000value is chosen as a deterrence amount that is approximately double the cost to respond at the top level. Bonds scale up to a value of300_000_000gas, a value chosen to cover approximately double the cost of a max-size Large Preimage Proposal.
As per to Optimism specs, we can see that at MAX_GAME_DEPTH the bond price is specifically chosen to reimburse the winning party for the high gas costs of proposing an LPP if necessary, as the proposer must call addLeavesLPP() many times. The intention is that the honest party creates an LPP and subsequently calls step() to receive the bond of the MAX_GAME_DEPTH claim they are countering.
However, the step() function is actually permissionless: it does not check if the user who proposes an LPP or loads data into the preimage oracle is the caller of step() when it accesses such data, and it always grants the bond to the caller.
This means that an attacker can call step() (and squeezeLPP() before that if necessary, as soon as the challenge period has passed) before the proposer to receive the bond, stealing their reimbursement for the high gas costs of proposing the LPP.
File: FaultDisputeGame.sol
234: function step(
235: uint256 _claimIndex,
236: bool _isAttack,
237: bytes calldata _stateData,
238: bytes calldata _proof
239: )
240: public
241: virtual
242: {
...
309: // Set the parent claim as countered. We do not need to append a new claim to the game;
310: // instead, we can just set the existing parent as countered.
311: parent.counteredBy = msg.sender;
312: }
Impact
Honest LPP proposers may not be reimbursed for the high gas costs of proposing an LPP, defeating the intended purpose of bonds and leading to misaligned incentives.
Proof of Concept
- Alice (honest proposer) and Bob (attacker) are engaged in a fault dispute game at
MAX_GAME_DEPTH. Alice needs to counter Bob’s false claim. - Alice initializes and submits an LPP on the
PreimageOracle, incurring significant gas costs in the process. - As soon as the challenge period ends, Bob calls
squeezeLPP()to finalize the LPP. - Immediately after, Bob calls
step()on the FaultDisputeGame contract, providing the necessary proof that uses Alice’s LPP data. - The
step()function succeeds, countering the false claim. However, it assigns the large bond to Bob (msg.sender) instead of Alice. - Bob receives their bond back, griefing Alice of the reimbursement for her significant gas expenditure.
Recommended Mitigation Steps
If a step() reads from a preimage oracle, the bonds from step() should be assigned to the one that loaded the data into the oracle.
A possible way to do this would be to set a new variable currentPreimageProposer using a preimageProposer mapping during the readPreimage call, and then read this value from the oracle to find out who to send the step() bond to:
/// @inheritdoc IFaultDisputeGame
function step(
uint256 _claimIndex,
bool _isAttack,
bytes calldata _stateData,
bytes calldata _proof
)
public
virtual
{
...
+ IPreimageOracle oracle = VM.oracle();
+ // Clear the previous preimage proposer if it exists.
+ oracle.clearPreimageProposer();
bool validStep = VM.step(_stateData, _proof, uuid.raw()) == postState.claim.raw();
bool parentPostAgree = (parentPos.depth() - postState.position.depth()) % 2 == 0;
if (parentPostAgree == validStep) revert ValidStep();
// INVARIANT: A step cannot be made against a claim for a second time.
if (parent.counteredBy != address(0)) revert DuplicateStep();
// Set the parent claim as countered. We do not need to append a new claim to the game;
// instead, we can just set the existing parent as countered.
- parent.counteredBy = msg.sender;
+ address preimageProposer = oracle.currentPreimageProposer();
+ parent.counteredBy = preimageProposer == address(0) ? msg.sender : preimageProposer;
}
+ function clearPreimageProposer() external {
+ currentPreimageProposer = address(0);
+ }
- function readPreimage(bytes32 _key, uint256 _offset) external view returns (bytes32 dat_, uint256 datLen_) {
+ function readPreimage(bytes32 _key, uint256 _offset) external returns (bytes32 dat_, uint256 datLen_) {
...
+ currentPreimageProposer = preimageProposer[_key][_offset];
}
squeezeLPP()pays out to the claimant, not caller, and that’s the reward for doingaddLeavesLPP(), so it is correct.
@obront, I believe there is a misunderstanding in your comment here.
squeezeLPP pays out to the claimant, not caller, and that’s the reward for doing addLeavesLPP
Here, the bonds we are referring to are the FDG bonds, not the LPP bonds. To pass an LPP the proposer will stake the bonds in the
initLPPand after the challenge period,squeezeLPPcan be called to pay back the bond to the proposer.However, the gas required for a maximum size LPP proposal is extremely large (
150_000_000), and that is why the FDG bonds atMAX_GAME_DEPTHare300_000_000 * 200gwei in order to reimburse the gas cost of proposing a maximum size LPP, as we already pointed out:FPM bonds are priced in the amount of gas that they are intended to cover. Bonds start at the very first depth of the game at a baseline of
400_000gas. The400_000value is chosen as a deterrence amount that is approximately double the cost to respond at the top level. Bonds scale up to a value of300_000_000gas, a value chosen to cover approximately double the cost of a max-size Large Preimage Proposal.Here, we show that an attacker can call
squeezeLPP, and then callstep(), which will cause the FDG bond to go to the attacker and the proposer will not be reimbursed.
@clabby - Can you weigh in? It seems from the code like the intention is that the LPP bonds should cover the LPP costs, and the FDG bonds should focus on FDG itself.
But the warden points out that the docs explain that FDG bonds are based on LPP cost.
Can you provide some more context?
@obront - The LPP bond offers an incentive to challenge the LPP; The incentive for creating the LPP itself is encapsulated by the incentive within the FDG, as creating the LPP may be required for performing a successful
step.@haxatron is correct here that another party can take advantage of someone else’s work in the large preimage proposal in order to receive the bond over in the FDG. You could do this by waiting until a valid large preimage proposal for the
stephas been finalized and is ready to be squeezed, and then finally using it to callstep(where the LPP proposer would not be the one that received the incentive over in the FDG).There is not an expectation within the system that the LPP submitter will always be the one that actually receives the reward; it does also hinge upon them being the first party to call
stepusing their LPP.
Whether this is intentional or not, the LPP submitter will have to spend 150 million gas to propose a max size LPP and as @clabby has mentioned - “The incentive for creating the LPP itself is encapsulated by the incentive within the FDG”.
But the problem is that anyone, even the attacker himself, can steal this incentive by calling
squeezeLPP()after 1 day challenge period and then callstep()to receive the FDG bond. Meanwhile, the LPP submitter will not be reimbursed the 150 million gas cost of creating the LPP.
@haxatron, I’ve thought about this a lot more and I’m in agreement. If the FDG bonds are intended to cover the LPP, this system is clearly not reliable.
Given there is no way for anyone to create an LPP with confidence they’ll get the reward, this is a fundamental problem that a user cannot protect themselves against.
@obront , let me explain why I think the system is still reliable.
The reliability of the system is ensured not only by incentivizing the honest party to act, but also by disincentivizing the evil party to act.
This issue can be simplified to, honest actor spend X ETH but may not get the bond (2X ETH), and the evil party could lose the bond (2X ETH). The safety is guaranteed by “evil party’s loss will be larger than honest party’s loss”, so if the ratio (2) is large enough, we can consider the system as safe.
Let’s use top level move as another example. Evil party can risk to lose 2Y ETH to post an invalid root. But an honest actor’s move could also be frontrunned (even they send the tx privately they still cannot guarantee it to be the first), and they could lose the gas they spent (Y ETH). It is unavoidable that a malicious party can grief an honest party, causing them to lose money. So I’d rather call this a design tradeoff rather than a security issue.
@xuwinnie - I see your point, but the unavoidable downside to challengers makes this more than a design trade off, in my opinion. I’m going to stick with the decision to reward as a 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 step() function does not verify that the caller is the same party that proposed the LPP, so it unconditionally assigns the bond to msg.sender.
Impact
Honest LPP proposers may not be reimbursed for the high gas costs of proposing an LPP, defeating the intended purpose of bonds and leading to misaligned incentives.
What the attacker needed
A fault dispute game at MAX_GAME_DEPTH; an honest party submits an LPP; attacker waits for challenge period to end
The fix
The step() function should assign the bond to the party that loaded the data into the preimage oracle, for example by tracking the preimage proposer and using that address instead of msg.sender.
How it was found
- Alice (honest proposer) and Bob (attacker) are engaged in a fault dispute game at MAX_GAME_DEPTH. Alice needs to counter Bob’s false claim.
- Alice initializes and submits an LPP on the PreimageOracle, incurring significant gas costs in the process.
- As soon as the challenge period ends, Bob calls squeezeLPP() to finalize the LPP.
- Immediately after, Bob calls step() on the FaultDisputeGame contract, providing the necessary proof that uses Alice’s LPP data.
- The step() function succeeds, countering the false claim. However, it assigns the large bond to Bob (msg.sender) instead of Alice.
- Bob receives their bond back, griefing Alice of the reimbursement for her significant gas expenditure.
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.
In this system, people who make claims in a dispute game must put up a bond (a deposit) that is paid to whoever successfully counters a false claim. The step() function is what counters a claim, and it always pays the bond to whoever calls it. The problem is that the person who did the expensive work of preparing the data (the LPP proposer) might not be the one who calls step(), so someone else can take the reward.
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.