Submitted by RadiantLabs, also found by kuprum, n4nika, alexfilippov314, and Femboys
https://github.com/code-423n4/2024-07-optimism/blob/70556044e5e080930f686c4e5acde420104bb2c4/packages/contracts-bedrock/src/cannon/PreimageOracle.sol#L417https://github.com/code-423n4/2024-07-optimism/blob/70556044e5e080930f686c4e5acde420104bb2c4/packages/contracts-bedrock/src/cannon/PreimageOracle.sol#L431
It was reported in the Spearbit review (5.2.5 Preimage proposals can be initialized multiple times) that it is possible to re-initialize LPPs, at a loss for the caller, because the initLPP function doesnt check for the LPP to exist already.
If we look at the initLPP() function, however, we can see that there is another vulnerability that can be chained: at L431, the to-be-initialized LPPMetadata is unnecessarily read from storage instead of being initialized empty:
Because of this, L431 and L432 in fact allow to arbitrarily change an existing LPPs partOffset and claimedSize metadata, while leaving unchanged its other metadata, including its finalization timestamp if set.
Additionally, squeezeLPP() does not check that bytesProcessed == claimedSize since this check is already performed on finalization in addLeavesLPP().
By exploiting these three issues, it is then possible that:
Similar attacks are also possible by instead (or additionally) altering the partOffset,  with the same outcome of producing an incorrect memRoot leading to an incorrect state hash.
Malicious actors can trick the VM into producing an incorrect state and therefore, allow a dishonest participant to win the fault dispute game, stealing the bonds of honest participants.
The following PoC compares side-by-side the outcome of two courses of action: one that is honest, and one that exploits the above-mentioned vulnerabilities to tamper with the preimage lengths. At the end, the test proves that the two courses of action yield a different state of the MIPS VM.
Foundry
Consider fixing the three issues exploited in the PoC:
Invalid Validation
ajsutton (Optimism) confirmed via duplicate Issue #14
