Skip to content
Smart contracts Audit finding Advanced

EIP-155 is not enforced, allowing attackers/malicious operators to profit from replaying transactions

The zkSync Era L2 did not enforce EIP-155 for legacy transactions, so a transaction signed without a chain ID could be replayed on zkSync. An attacker could replay an old mainnet transaction to steal funds from a user who had deposited into zkSync.

OffsideLabs Follow with anon and ustas

Originally disclosed on Code4rena

Submitted by OffsideLabs, also found by anon and ustas

Lines of code

https://github.com/code-423n4/2023-10-zksync/blob/72f5f16ed4ba94c7689fe38fcb0b7d27d2a3f135/code/system-contracts/contracts/libraries/TransactionHelper.sol#L183-L187 https://github.com/code-423n4/2023-10-zksync/blob/72f5f16ed4ba94c7689fe38fcb0b7d27d2a3f135/code/system-contracts/contracts/DefaultAccount.sol#L78-L107

Vulnerability details

The L2 DefaultAccount.validateTransaction function and transaction encoding process in the bootloader do not enforce EIP-155. If the reserved[0] of the legacy tx is zero, the EIP-155 will be disabled. The chainId will not be included in the transaction signature.

        bytes memory encodedChainId;
        if (_transaction.reserved[0] != 0) {
            encodedChainId = bytes.concat(RLPEncoder.encodeUint256(block.chainid), hex"80_80");
        }

Impact

There are two potential exploitation scenarios:

  1. A malicious attacker can replay transactions from the mainnet or other networks not protected by EIP-155. While there are very few EVM networks currently supporting transactions without EIP-155, attackers still have an opportunity to profit by replaying early transactions from other networks. For example, if an early ETH user A sent a legacy tx to user B before EIP-155 enabled, and now user A deposited some ETH into the zkSync era network, then user B could replay the early transaction from user A to steal his funds on the zkSync network.
  2. Operators can replay early user transactions from eth/other EVM networks to collect gas fees or even profit directly.

Proof of Concept

EIP-155 will be disabled when the following two conditions are met:

  1. Transaction type is legacy tx, which tx_type=0.
  2. tx.reserved[0] == 0.

The value of the reserved field cannot be set arbitrarily, but if the user inputs a transaction with tx_type=0 and the v in the signature is 27 or 28, then reserved[0] will be set to 0.

Code here.

                let should_check_chain_id = if matches!(
                    common_data.transaction_type,
                    TransactionType::LegacyTransaction
                ) && common_data.extract_chain_id().is_some()
                {
                    U256([1, 0, 0, 0])
                } else {
                    U256::zero()
                };
    pub fn extract_chain_id(&self) -> Option<u64> {
        let bytes = self.input_data()?;
        let chain_id = match bytes.first() {
            Some(x) if *x >= 0x80 => {
                let rlp = Rlp::new(bytes);
                let v = rlp.val_at(6).ok()?;
                PackedEthSignature::unpack_v(v).ok()?.1?
            }

Recommended Mitigation Steps

Enforce EIP-155 signature verification in the contract DefaultAccount.validateTransaction.

miladpiri (zkSync) confirmed, but disagreed with severity and commented:

This is a design decision. So, QA.

Alex the Entreprenerd (judge) decreased severity to QA and commented:

This is an option, not the default.

Alex the Entreprenerd (judge) increased severity to Medium and commented:

I have spent time investigating this issues impact and why this is considered “acceptable”. I believe that a clear divide between Developers and Security Researchers can be seen in how the severity is interpreted for this issue.

Any “EVM Developer” will look at this finding as trivial, and obvious, “it’s the user fault” for having a wallet that is pre EIP-155 and the usage of this signature scheme are keyless deployments. Any security researcher will look at this as a means to DOS users, and potentially steal their funds.

I have spoken with a lot of different actors in the security space and have heard every possible severity for this type of findings, from known to high severity.

After talking with 4 different judges, am going to set the finding as Medium severity. As zkSync is not uniquely subjected to this finding, I believe the finding to be a danger to end users which should be publicly disclosed to them.

Note: For full discussion, see here.


The original report as published on Code4rena, by OffsideLabs. 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 transaction validation and encoding logic did not require EIP-155, so legacy transactions with a zero reserved field were accepted without a chain ID in the signature.

Impact

An attacker could replay old transactions to steal funds from users who deposited into zkSync, and operators could replay transactions to collect gas fees or profit.

What the attacker needed

Victim has a pre-EIP-155 transaction; victim deposits funds to zkSync; attacker can submit transactions

The fix

EIP-155 signature verification should be enforced in the DefaultAccount.validateTransaction function.

How it was found

  1. A user sends a legacy transaction on mainnet before EIP-155 was enabled.
  2. The same user deposits ETH into the zkSync Era network.
  3. An attacker replays the old transaction on zkSync.
  4. The replayed transaction executes and moves the user's funds to the attacker.

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.

EIP-155 is a rule that ties a transaction to one blockchain by including the chain ID in the signature. Without it, a transaction signed for one chain can be copied and submitted to another chain. Here, zkSync accepted such transactions, so someone could copy an old transaction and have it executed again on zkSync.

What is Smart contracts?

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

More from zkSync Era

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.