Skip to content
Smart contracts Audit finding Advanced

Incorrect implementation of RRUtils.serialNumberGte

The serial number comparison function in the DNSSEC oracle contract did not correctly implement RFC1982 serial number arithmetic, so certain pairs of serial numbers could cause a revert or incorrect comparison. An attacker could potentially exploit this to disrupt DNSSEC validation, though the issue would not occur until far in the future.

GimelSec Follow

Originally disclosed on Code4rena

Submitted by GimelSec, also found by Lambda and zzzitron

RRUtils.sol#L266-L268

Comparing serial numbers should follow RFC1982 due to the possibility of numbers wrapping around. RRUtils.serialNumberGte tried to follow the RFC but failed to do so, leading to incorrect results in comparison.

Proof of Concept

For a serial number i1 to be greater than i2, the rules provided by RFC1982 is as follow ((i1 < i2) && ((i2 - i1) > (2**31))) || ((i1 > i2) && ((i1 - i2) < (2**31)))

ENS implements int32(i1) - int32(i2) > 0, which will suffer from revert in cases such as i1=0x80000000, i2=0x7fffffff

Recommended Mitigation Steps

Use the naive implementation instead return (i1 == i2) || ((i1 < i2) && ((i2 - i1) > (2**31))) || ((i1 > i2) && ((i1 - i2) < (2**31)));

Arachnid (ENS) disagreed with severity and commented:

This is intentional, see https://en.wikipedia.org/wiki/Serial_number_arithmetic#General_solution

Nevertheless, this should be documented. Recommend triaging as QA.

Arachnid (ENS) commented:

Correction - while the operation is correct per the Wikipedia article, it should be in an unchecked block to allow overflow. Recommend triaging as 2.

LSDan (judge) decreased severity to Medium and commented:

Agree with the sponsor. This is a bug and it does potentially impact protocol functionality, but it will not occur until far in the future, making it fairly unlikely. Medium makes sense here.


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

The implementation used signed integer subtraction without an unchecked block, which can revert on overflow instead of correctly handling serial number wraparound as required by RFC1982.

Impact

The bug could cause the contract to revert or produce incorrect comparison results, potentially disrupting DNSSEC validation, but it will not occur until far in the future, making it fairly unlikely.

What the attacker needed

Specific serial number values; far in the future

The fix

The function should be placed in an unchecked block to allow overflow, or the naive RFC1982 implementation should be used.

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.

Serial numbers in DNSSEC are like a clock that wraps around after reaching a maximum value. The code that compares them used a method that could fail for certain values, causing the contract to revert or give the wrong answer. This could break DNSSEC validation, but only for specific serial numbers that are unlikely to appear soon.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by GimelSec

View all

18 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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.