Wrong Equals Logic
The equals function in BytesUtils.sol incorrectly returns true when comparing a byte array with an offset to a shorter byte array, because it checks if self.length is greater than or equal to offset + other.length instead of equal. An attacker could exploit this to cause incorrect equality checks, potentially leading to logic errors in the DNSSEC oracle.
Submitted by 0x1f8b, also found by alan724
equals with offset might return true when equals without offset returns false.
Proof of Concept
The problem is that self.length could be greater than other.length + offset, it should be ==, or it should contain a length argument.
Here you have an example of the failure:
equals(0x0102030000, 0, 0x010203)=>return true
decoded input {
"bytes self": "0x0102030000",
"uint256 offset": "0",
"bytes other": "0x010203"
}
decoded output {
"0": "bool: true"
}
Recommended Mitigation Steps
function equals(bytes memory self, uint offset, bytes memory other) internal pure returns (bool) {
- return self.length >= offset + other.length && equals(self, offset, other, 0, other.length);
+ return self.length == offset + other.length && equals(self, offset, other, 0, other.length);
}
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
The length check uses >= instead of ==, allowing self to be longer than offset + other.length.
What the attacker needed
None
The fix
The fix is to change the comparison from >= to == in the equals function.
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 bug in a smart contract function that compares two pieces of data (byte arrays). The function is supposed to check if they are exactly the same, but due to a wrong comparison operator, it can say they are equal even when one is longer than the other. This could trick other parts of the contract into accepting invalid data.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.