Skip to content
Business logic Audit finding Advanced

MIPS - Incorrect implementation of SRAV instruction

The MIPS emulator used in the dispute game implemented the SRAV shift instruction without masking the shift count to the low five bits of the register, so large shift amounts produced zero instead of the correct arithmetic shift. This could cause a valid root claim to be resolved as false.

KupiaSec Follow with Zubat

Originally disclosed on Code4rena

Submitted by KupiaSec, also found by Zubat

Incorrect dispute game resolution - it will make True root claim to be False.

Proof of Concept

MIPS-ISA: Page 153(A-141)

SRAV instruction does arithmetic shift right, the bit shift count is specified by the low-order five bits of rs register.

else if (func == 0x07) {
    return SE(rt >> rs, 32 - rs);
}

However, in implementation it does not validate low-level five bits of rs register, but use it as a whole for shift.

As a result, if any of bits after 5th bit is one, the shift results will always be zero.

Recommended Mitigation Steps

As it did for other shifts, it should apply & 0x1F before shifting.

else if (func == 0x07) {
    return SE(rt >> (rs & 0x1F), 32 - (rs - 0x1F));
}

Assessed type

Context

mbaxter (Optimism) confirmed and commented:

Looks right - originally misread the code but looks like we do need to mask rs.

Note: For full discussion, see here.


The original report as published on Code4rena, by KupiaSec. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Impact

A correct root claim could be resolved as false, breaking dispute game resolution.

What the attacker needed

Dispute game using the MIPS emulator; program executes SRAV with large shift count

The fix

The shift count should be masked with 0x1F before shifting, as is done for the other shift instructions.

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.

A dispute game is a contract-based system that checks whether a claimed result of running a program is correct. The program runs on an emulated MIPS processor, and one of its shift instructions was implemented wrongly, so the emulator could compute a different answer than a real processor. That mismatch could make a correct claim look wrong.

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.

More by KupiaSec

View all

28 more disclosed reports, best first.

More from Optimism Superchain

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.