code-423n4 / 2024-05-arbitrum-foundation-findings

3 stars 2 forks source link

Wining a challenge by engineering time #50

Closed howlbot-integration[bot] closed 4 months ago

howlbot-integration[bot] commented 4 months ago

Lines of code

https://github.com/code-423n4/2024-05-arbitrum-foundation/blob/main/src/challengeV2/EdgeChallengeManager.sol#L511

Vulnerability details

Impact

If the difference between challengePeriodBlocks and the total unrivaled time of a malicious assertion claim is less than the delay between sending a transaction and mining that transaction, the malicious assertion claim will always win regardless of the total unrivaled time of the valid assertion claim.

Proof of Concept

Please have a look at the following time demonstration for better understanding:

 ---- t1 ---- t1 + k ---- t1 + tH ---- t1 + tH + tA ---- t1 + k + tH ---- t1 + tH + tA + k ---- t1 + k + tH + k ----> t

    Honest    Honest       Evil         Evil               Honest               Evil                  Honest
    Create    Create       Rival &      Confirm            Confirm              Confirm               Confirm
                           Create
    Send      Mined        Send         Send               Send                 Mined                 Mined

                                                           Evil
                                                           Rival &
                                                           Create
                                                           Mined

Happy Scenario:

Suppose the total unriveled time of the valid assertion claim is challengePeriodBlocksInTime - tH, so if the evil party delays only tH seconds in rivaling an edge, the honest party will win and can confirm the valid assertion claim by time by calling confirmEdgeByTime.

Unhappy Scenario:

Suppose the total unriveled time of the valid assertion claim is challengePeriodBlocksInTime - tH, so if the evil party delays only tH seconds in rivaling an edge, the honest party will win and can confirm the valid assertion claim by time by calling confirmEdgeByTime.

Moreover suppose that total unriveled time of the malicious assertion claim is challengePeriodBlocksInTime - tA, so if the honest party delays only tA seconds in rivaling an edge, the evil party will win and can confirm the malicious assertion claim by time by calling confirmEdgeByTime.

Even if the honest party rivals the evil party's edge at time t1 + k + tH, it will be mined at t1 + k + tH + k which is too late because the evil party's confirm tx is mined at t1 + k + tH + tA.

The only condition is that tA <= k.

Example 1 (where tA < tH):

 -- 604000 -- 604048 ---- 604100 ------- 604124 ---------- 604148 -------- 604172 ----------------- 604196 ----> t

 ---- t1 ---- t1 + k ---- t1 + tH ---- t1 + tH + tA ---- t1 + k + tH ---- t1 + tH + tA + k ---- t1 + k + tH + k ----> t

    Honest    Honest       Evil         Evil               Honest               Evil                  Honest
    Create    Create       Rival &      Confirm            Confirm              Confirm               Confirm
                           Create
    Send      Mined        Send         Send               Send                 Mined                 Mined

                                                           Evil
                                                           Rival &
                                                           Create
                                                           Mined   

Honest party creates an edge at time 604000, and it is mined at 604000 + 48 = 604048. The total unrivaled time of the valid assertion claim is 604700, so if the evil party makes delay of 100 seconds, the honest party can confirm the valid assertion claim. Moreover, the total unrivaled time of the malicious assertion claim is 604776, so if honest party makes delay of 24 seconds, the evil party can confirm the malicious assertion claim.

Evil party sends a tx at 604000 + 100 = 604100 to rival the honest party's edge and also creates a new edge. Then the evil party sends a tx at 604000 + 100 + 24 = 604124 to confirm the malicious assertion claim.

The honest party notices at 604000 + 48 + 100 = 604148 that the total unrivaled time of valid assertion claim is now 604700 + (604148 - (604000 + 48)) = 604800 which is equal to challengePeriodBlocksInTime. So, he sends the tx to confirm the valid assertion claim.

The evil party's rival and new edge creation tx is mined at 604000 + 48 + 100 = 604148.

The evil party's confirmation tx is mined at 604000 + 48 + 100 + 24 = 604172. This tx will be successful because the time this tx is mined, the total unrivaled time of malicious assertion claim is increased by 24 which makes the total equal to 604800 = challengePeriodBlocksInTime. So, the malicious assertion claim is confirmed, and the evil party wins.

The honest party's confirmation tx will not be successful at 604800 + 48 + 100 + 48 = 604196, because its rival is already confirmed.

Example 2 (where tA > tH):

 -- 604000 -- 604005 ------- 604029 -------- 604048 ------ 604053 -------- 604077 ------------------ 604101 ----> t

 ---- t1 ---- t1 + tH ---- t1 + tH + tA ---- t1 + k ---- t1 + k + tH ---- t1 + tH + tA + k ---- t1 + k + tH + k ----> t

    Honest    Evil          Evil            Honest            Honest              Evil                  Honest
    Create    Rival &       Confirm         Create            Confirm             Confirm               Confirm
              Create             
    Send      Send          Send            Mined             Send                Mined                 Mined

                                                              Evil
                                                              Rival &
                                                              Create
                                                              Mined  

Honest party creates an edge at time 604000. The total unrivaled time of the valid assertion claim is 604795, so if the evil party makes delay of 5 seconds, the honest party can confirm the valid assertion claim. Moreover, the total unrivaled time of the malicious assertion claim is 604776, so if honest party makes delay of 24 seconds, the evil party can confirm the malicious assertion claim.

Evil party sends a tx at 604000 + 5 = 604005 to rival the honest party's edge (which is not still mined) and also creates a new edge. Then the evil party sends a tx at 604000 + 5 + 24 = 604029 to confirm the malicious assertion claim.

The honest party's edge creation is mined at 604000 + 48 = 604048.

The honest party notices at 604000 + 48 + 5 = 604053 that the total unrivaled time of valid assertion claim is now 604795 + (604053 - (604000 + 48)) = 604800 which is equal to challengePeriodBlocksInTime. So, he sends the tx at 604000 + 48 + 5 = 604053 to confirm the valid assertion claim.

The evil party's rival and new edge creation tx is mined at 604000 + 48 + 5 = 604053.

The evil party's confirmation tx is mined at 604000 + 48 + 5 + 24 = 604077. This tx will be successful because the time this tx is mined, the total unrivaled time of malicious assertion claim is increased by 24 which makes the total equal to 604800 = challengePeriodBlocksInTime. So, the malicious assertion claim is confirmed, and the evil party wins.

The honest party's confirmation tx will not be successful at 604800 + 48 + 5 + 48 = 604101, because its rival is already confirmed.

Example 3 (where tA < tH & evil party is not precise):

So far, I was assuming that the evil party's rival and new edge creation is mined exactly at the time the honest party's confirmation tx is sent. This was just for simplicity, and it is not necessary. So, here I assume that the evil party has x seconds delay where x <= k.

 -- 604000 -- 604048 ------ 604112 ---------- 604136 ------------- 604148 ---------- 604160 ------------- 604184 --------------- 604196 ----> t

 ---- t1 ---- t1 + k ---- t1 + tH + x ---- t1 + tH + tA + x ---- t1 + k + tH -- t1 + tH + x + k -- t1 + tH + tA + x + k --- t1 + k + tH + k ----> t

    Honest    Honest       Evil             Evil                    Honest          Evil               Evil                  Honest
    Create    Create       Rival &          Confirm                 Confirm         Rival &            Confirm               Confirm
                           Create                                                   Create
    Send      Mined        Send             Send                    Send            Mined              Mined                 Mined

Honest party creates an edge at time 604000, and it is mined at 604000 + 48 = 604048. The total unrivaled time of the valid assertion claim is 604700, so if the evil party makes delay of 100 seconds, the honest party can confirm the valid assertion claim. Moreover, the total unrivaled time of the malicious assertion claim is 604776, so if honest party makes delay of 24 seconds, the evil party can confirm the malicious assertion claim.

Evil party sends a tx at 604000 + 100 + 12 = 604112 to rival the honest party's edge and also creates a new edge. Then the evil party sends a tx at 604000 + 100 + 24 + 12 = 604136 to confirm the malicious assertion claim.

The honest party notices at 604000 + 48 + 100 = 604148 that the total unrivaled time of valid assertion claim is now 604700 + (604148 - (604000 + 48)) = 604800 which is equal to challengePeriodBlocksInTime. So, he sends the tx to confirm the valid assertion claim.

The evil party's rival and new edge creation tx is mined at 604000 + 48 + 100 + 12 = 604160.

The evil party's confirmation tx is mined at 604000 + 48 + 100 + 24 + 12 = 604184. This tx will be successful because the time this tx is mined, the total unrivaled time of malicious assertion claim is increased by 24 which makes the total equal to 604800 = challengePeriodBlocksInTime. So, the malicious assertion claim is confirmed, and the evil party wins.

The honest party's confirmation tx will not be successful at 604800 + 48 + 100 + 48 = 604196, because its rival is already confirmed.

The root cause of this issue is that there is a delay between the time the honest party sends the confirmation tx and the time it is mined. If the evil party could engineer the time so that the confirmation of malicious assertion claim is mined between these two times, the evil party will always win the scenarios where tA <= k. In other words, the required total unrivaled time of malicious assertion claim to be confirmed should be equal or less than the delay between sending a tx and being mined.

In summary, when the honest party notices that total unrivaled time of valid assertion claim is meeting the threshold, he sends the confirmation tx. There is some delay to have this tx mined. If the evil party during this time delay could mine his confirmation of malicious assertion claim, he is the winner.

Some important notes:

Tools Used

Recommended Mitigation Steps

It should be enforced that the confirmation tx should not be sent before the latest edge creation tx related to the assertion claim is mined.

uint256 public kInBlocks = 48 / 12; // The delay between sending a tx and being mined in blocks
function confirmEdgeByTime(bytes32 edgeId, AssertionStateData calldata claimStateData) public {
    //....
    ChallengeEdge storage topEdge = store.get(edgeId);

    // this is the block in which the last child edge creation related to this edge id is mined.
    uint lastCreatedEdgeInBlock = topEdge.latestCreatedEdge.createdAtBlock; 

    require(block.number - lastCreatedEdgeInBlock >= kInBlocks, "the confirmation is sent earlier than the edge creation is mined");
}

Assessed type

Context

c4-sponsor commented 4 months ago

gzeoneth (sponsor) disputed

gzeoneth commented 4 months ago

Invalid. Misconfigurations are out-of-scope; challengePeriodBlocks should be configured to the attacker censorship budget

Also in README:

It is assumed that off-chain computation costs are negligible, and honest validators can react to malicious action broadcasted on-chain immediately in the same block unless the malicious party spend their censorship budget.

Picodes commented 4 months ago

Flagging as Out-of-Scope as shown by the sponsor.

c4-judge commented 4 months ago

Picodes marked the issue as unsatisfactory: Out of scope