code-423n4 / 2024-07-optimism-findings

3 stars 0 forks source link

Incorrect Memory Alignment and Proof Verification in 'readMem' and 'writeMem' Functions #89

Closed howlbot-integration[bot] closed 3 months ago

howlbot-integration[bot] commented 4 months ago

Lines of code

https://github.com/code-423n4/2024-07-optimism/blob/70556044e5e080930f686c4e5acde420104bb2c4/packages/contracts-bedrock/src/cannon/MIPS.sol#L538-L584 https://github.com/code-423n4/2024-07-optimism/blob/70556044e5e080930f686c4e5acde420104bb2c4/packages/contracts-bedrock/src/cannon/MIPS.sol#L592-L632

Vulnerability details

Impact

Proof of Concept

Tools Used

Manual review

Recommended Mitigation Steps

Assessed type

Math

mbaxter commented 3 months ago

It's true that we allow unaligned reads / writes, this is a known issue we are considering addressing.

However, the submission doesn't really demonstrate the issue - we already have reverts in the methods mentioned. And we already have memory proof checks. The suggested changes use a different revert style and add some additional proof checks that are incorrect.

Additionally, this issue is highlighted in the Cantina audit (3.3.2) - not sure if that invalidates this submission (I don't see the cantina audit listed in the rules).

mbaxter commented 3 months ago

Switching to confirmed after offline discussion because the unaligned read / write issue is real.

c4-judge commented 3 months ago

zobront marked the issue as satisfactory

c4-judge commented 3 months ago

zobront marked the issue as selected for report

Haxatron commented 3 months ago

This report is invalid, in all the calls to readMem and writeMem the effective address passed will have the two least significant bits zeroed, making them aligned

                    uint32 mem = readMem(a1 & 0xFFffFFfc, 1); // mask the addr to align it to 4 bytes
                    writeMem(a1 & 0xFFffFFfc, 1, mem);

There is indeed a problem with certain instructions not throwing an exception when the effective address is unaligned thus not adhering to MIPS spec, but that is described in https://github.com/code-423n4/2024-07-optimism-findings/issues/82 and not here.

zobront commented 3 months ago

This issue specifically focuses on readMem() and writeMem(), which are always called safely in the code as @Haxatron points out. Therefore, there is no situation in which the memory could be misaligned when these functions are called.

This is in contrast to issue #82, in which LH and LHU do not have this same guarantee, and is therefore valid.

For this reason, I will be marking this issue as Invalid.

c4-judge commented 3 months ago

zobront marked the issue as not selected for report

c4-judge commented 3 months ago

zobront removed the grade

c4-judge commented 3 months ago

zobront marked the issue as unsatisfactory: Invalid