Skip to content
Memory corruption Audit finding Advanced

Incorrect Encoding of Order Hashes

The order hashes were encoded incorrectly because a pointer was advanced past the end of the array, so the copy precompile read unallocated memory. This caused functions such as _encodeRatifyOrder and _encodeValidateOrder to produce incorrect order hashes, meaning zones and contract offerers could not rely on the orderHashes array.

0xsomeone Follow

Originally disclosed on Code4rena

Submitted by 0xsomeone

contracts/lib/ConsiderationEncoder.sol#L569-L574

The order hashes are incorrectly encoded during the _encodeOrderHashes mechanism, causing functions such as _encodeRatifyOrder and _encodeValidateOrder to misbehave.

Proof of Concept

The order hashes encoding mechanism appears to be incorrect as the instructions srcLength.next().offset(headAndTailSize) will cause the pointer to move to the end of the array (i.e. next() skips the array’s length bitwise entry and offset(headAndTailSize) causes the pointer to point right after the last element). In turn, this will cause the 0x04 precompile within MemoryPointerLib::copy to handle the data incorrectly and attempt to copy data from the srcLength.next().offset(headAndTailSize) pointer onwards which will be un-allocated space and thus lead to incorrect bytes being copied.

Tools Used

Manual inspection of the codebase, documentation of the ETH precompiles, and the Solidity compiler documentation.

Recommended Mitigation Steps

We advise the offset instruction to be omitted as the current implementation will copy from unsafe memory space, causing data corruption in the worst-case scenario and incorrect order hashes being specified in the encoded payload. As an additional point, the _encodeOrderHashes will fail execution if the array of order hashes is empty as a headAndTailSize of 0 will cause the MemoryPointerLib::copy function to fail as the precompile would yield a returndatasize() of 0.

0age (OpenSea) confirmed, but disagreed with severity and commented:

This is a confirmed issue (though categorizing it as high-risk seems unfair. At worst, it just means that zones and contract offerers wouldn’t be able to rely on the orderHashes array) and has been fixed here: https://github.com/ProjectOpenSea/seaport/pull/918

hickuphh3 (judge) decreased severity to Medium and commented:

Agree that high severity is overstated. Given that it would affect upstream functions (_encodeRatifyOrder and _encodeValidateOrder is called by a few other functions like _assertRestrictedAdvancedOrderValidity()), medium severity would be more appropriate.

2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.


The original report as published on Code4rena, by 0xsomeone. 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

Root cause

Likely the encoding code advanced the source pointer with both next() and offset(headAndTailSize), skipping past the array contents so the copy read unallocated memory.

Impact

The incorrect encoding meant zones and contract offerers could not rely on the orderHashes array; the judge rated it medium because assets were not at direct risk.

What the attacker needed

Orders processed through the affected encoding path

The fix

The offset instruction should be omitted so the copy does not read unsafe memory, and the empty-array case should be handled; the maintainer says it has been fixed.

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.

This is a smart contract that builds a block of data in memory and then copies it. A pointer used to find where the data starts was moved too far, past the end of the array, so the copy read empty memory instead of the real values. The result was wrong order hashes, which are identifiers other parts of the system use to check orders.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by 0xsomeone

View all

7 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.