Skip to content
Business logic Audit finding Intermediate

BytesUtils : compare will not revert when the offset and len exceeds the bytes lengths

The compare function in BytesUtils.sol does not validate that the provided offset and length parameters are within the bounds of the input byte arrays. An attacker could supply malformed DNS names with out-of-range offsets and lengths, causing compare to return incorrect results without reverting.

zzzitron Follow

Originally disclosed on Code4rena

Submitted by zzzitron

BytesUtils.sol#L44-L51

Compare will return false answer without reverting when the inputs are not valid.

Proof of Concept

The compare function is used for compareNames. The names are supposed to be DNS wire format. If the strings are malformed, it is possible to give out-of-range offset, len, otheroffset, and otherlen. When it happens, the compare will return some false values, without reverting, since the validity of offset and len are not checked.

// dnssec-oracle/BytesUtils.sol::compare
// The length of self and other are not enforced

 44     function compare(bytes memory self, uint offset, uint len, bytes memory other, uint otheroffset, uint otherlen) internal pure returns (int) {
 45         uint shortest = len;
 46         if (otherlen < len)
 47         shortest = otherlen;
 48
 49         uint selfptr;
 50         uint otherptr;

Recommended Mitigation Steps

Check whether the offset, len are within the length of self, as well as for the other.

makoto (ENS) acknowledged and commented:

It’s lacking enough test to prove the bug.

Arachnid (ENS) confirmed and commented:

compareNames does not sanity check the lengths passed in, so this is a legitimate bug.


The original report as published on Code4rena, by zzzitron. 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 compare function lacks bounds checks on the offset and length parameters relative to the actual byte array lengths.

Impact

The compare function may return false results without reverting, potentially causing incorrect behaviour in name comparison logic.

What the attacker needed

Malformed DNS name input

The fix

The compare function should check that offset and len are within the length of self, and similarly for other.

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 smart contract function that compares two pieces of data does not check if the starting positions and lengths given for the comparison actually fit inside the data. If someone provides bad numbers, the function gives a wrong answer instead of stopping with an error. This could lead to incorrect decisions in the contract.

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 zzzitron

View all

21 more disclosed reports, best first.

More from ENS

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.