Skip to content
Crypto Audit finding Intermediate

Wrong DOMAIN_SEPARATOR

The DOMAIN_SEPARATOR in the BathToken contract is computed using the contract's name before that name is set, so the separator is based on an empty or incorrect name. This makes it impossible to calculate the correct DOMAIN_SEPARATOR, which could break EIP-712 signature verification.

0x1f8b Follow

Originally disclosed on Code4rena

Submitted by 0x1f8b, also found by rotcivegaf, unforgiven, CertoraInc, eccentricexit, and IllIllI

The DOMAIN_SEPARATOR is wrongly calculated.

Proof of Concept

In the initialize method of the BathToken contract, the name of the contract is used to calculate the DOMAIN_SEPARATOR, however said name is set later, so it will use an incorrect name, making it impossible to calculate the DOMAIN_SEPARATOR correctly.

DOMAIN_SEPARATOR = keccak256(
    abi.encode(
        keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        ),
        keccak256(bytes(name)),
        keccak256(bytes("1")),
        chainId,
        address(this)
    )
);
name = string(abi.encodePacked(_symbol, (" v1")));

Affected source code:

Recommended Mitigation Steps

  • Set the name before using it.

bghughes (Rubicon) confirmed


The original report as published on Code4rena, by 0x1f8b. 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 contract calculates the DOMAIN_SEPARATOR using the `name` variable before that variable is assigned its intended value.

Impact

Signatures relying on the DOMAIN_SEPARATOR may be invalid, potentially preventing legitimate operations that require EIP-712 signatures.

What the attacker needed

None

The fix

The `name` should be set before it is used to calculate the DOMAIN_SEPARATOR.

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 DOMAIN_SEPARATOR is a unique value used in cryptographic signatures to prevent them from being reused on different contracts or networks. Here, the contract tries to build this value using its own name, but it does so before the name has been assigned, so the value is wrong. This means signatures that rely on the separator may not work correctly.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by 0x1f8b

View all

21 more disclosed reports, best first.

More from Rubicon v2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.