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.
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.
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.