Skip to content
Crypto Audit finding Advanced

Replay attack in case of hard fork

The contract computes the EIP-712 domain separator once in the constructor using the chain ID at deployment time. If the chain undergoes a hard fork, the cached domain separator remains tied to the old chain ID, so signatures intended for one chain could be replayed on the other.

codexploder Follow

Originally disclosed on Code4rena

Submitted by codexploder, also found by 0x1f8b, 0xNineDec, 0xsanson, berndartmueller, chatch, RustyRabbit, teddav, and Treasure-Seeker

GolomTrader.sol#L98

If there is ever a hardfork for Golom then EIP712_DOMAIN_TYPEHASH value will become invalid. This is because the chainId parameter is computed in constructor. This means even after hard fork chainId would remain same which is incorrect and could cause possible replay attacks

Proof of Concept

  1. Observe the constructor
constructor(address _governance) {
        // sets governance as owner
        _transferOwnership(_governance);

        uint256 chainId;
        assembly {
            chainId := chainid()
        }

        EIP712_DOMAIN_TYPEHASH = keccak256(
            abi.encode(
                keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
                keccak256(bytes('GOLOM.IO')),
                keccak256(bytes('1')),
                chainId,
                address(this)
            )
        );
    }
  1. As we can see the chainId is derived and then hardcoded in EIP712_DOMAIN_TYPEHASH
  2. This means even after hard fork, EIP712_DOMAIN_TYPEHASH value will remain same and point to incorrect chainId

Recommended Mitigation Steps

The EIP712_DOMAIN_TYPEHASH variable should be recomputed everytime by placing current value of chainId.

0xsaruman (Golom) confirmed, but disagreed with severity

0xsaruman (Golom) resolved and commented:

Resolved https://github.com/golom-protocol/contracts/commit/d8a24442b8f3a764139e312ed393e5d5ffb7e596

LSDan (judge) commented:

I’m going to leave this as a medium risk. It would be a very high-impact scenario, but it relies on the external factor of a hard fork. That said, hard forks can and do happen.


The original report as published on Code4rena, by codexploder. 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 EIP-712 domain separator is computed only in the constructor and stored, so it does not update if the chain ID changes after a hard fork.

Impact

Signatures could be replayed across forked chains, but this only matters if a hard fork occurs.

What the attacker needed

A hard fork of the chain occurs

The fix

The domain separator should be recomputed each time using the current chain ID rather than cached in the constructor.

How it was found

  1. Observe the constructor where the domain separator is built.
  2. Note that the chain ID is read and then hardcoded into the stored domain separator.
  3. Conclude that after a hard fork the stored value still points to the old chain ID.

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 uses a special code (domain separator) to make sure a signed message is only valid for that contract on that specific blockchain. The code includes the blockchain's ID number, but here it is saved only once when the contract is created. If the blockchain later splits into two (a hard fork), both copies keep the same saved ID, so a signature made for one copy might also work on the other.

What is Crypto?

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

More by codexploder

View all

3 more disclosed reports, best first.

More from Golom contest

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.