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.
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
namebefore using it.
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.