Skip to content
Business logic Audit finding Intermediate

Discrepancy in Default Account Behavior

The default account's fallback function reverts when called via delegatecall from a custom account, breaking the promised EOA-like behaviour. An attacker could exploit this discrepancy to cause unexpected failures in protocols that rely on consistent behaviour.

anon Follow with Audittens

Originally disclosed on Code4rena

Submitted by anon, also found by Audittens

Reverts in default account fallback function (when custom accounts delegate calls to a default account) may introduce security risks as protocols might not anticipate these reverts, resulting in vulnerabilities.

Proof of Concept

As stated in the documentation regarding the DefaultAccount:

The main purpose of this contract is to provide EOA-like experience for both wallet users and contracts that call it, i.e. it should not be distinguishable (apart of spent gas) from EOA accounts on Ethereum.

https://github.com/code-423n4/2023-10-zksync/blob/main/docs/Smart%20contract%20Section/System%20contracts%20bootloader%20description.md#defaultaccount

To achieve this EOA-like behavior, the fallback and receive functions of the DefaultAccount contract are designed in such a way that, when called or delegate-called, they mimic the actions of an EOA:

fallback() external payable {
    // The fallback function of the default account should never be called by the bootloader
    assert(msg.sender != BOOTLOADER_FORMAL_ADDRESS);

    // If the contract is called directly, it should behave like an EOA.
}

receive() external payable {
    // If the contract is called directly, it should behave like an EOA.
}

https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/DefaultAccount.sol#L222-L231

However, there’s an exception to this EOA-like behavior when a custom account delegate-calls a default account. Suppose the custom account execution function is implemented as follows:

function _execute(Transaction calldata _transaction) internal {
    address to = address(uint160(_transaction.to));
    (bool success,) = address(to).delegatecall("0x1234");
    require(success, "call was not successful");
}

In this scenario, if the to address is a default account, the fallback function of the default account will be invoked. Since the msg.sender is the bootloader address, it will trigger a revert due to assert(msg.sender != BOOTLOADER_FORMAL_ADDRESS) and success will be false. This is not the expected behavior, as to should act like an EOA and success should be true.

https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/DefaultAccount.sol#L224

This situation can potentially pose a significant issue for several reasons:

  1. Due to the unpredictability of custom account implementations, any assertion claiming that custom accounts will not delegate calls to a default account lacks a solid foundation.
  2. ZkSync Era has explicitly stated that default accounts should not be distinguishable (apart of spent gas) from EOA accounts on Ethereum. Protocols and custom accounts deployed on ZkSync Era are likely to rely on this statement, believing that they will observe consistent behavior. In practice, they might encounter different behavior, which could lead to unexpected consequences.

Recommended Mitigation Steps

One potential solution is to add modifier ignoreInDelegateCall to the fallback function as well:

    fallback() external payable ignoreInDelegateCall {
        assert(msg.sender != BOOTLOADER_FORMAL_ADDRESS);
    }

Assessed type

Context

miladpiri (zkSync) confirmed and commented:

It is showing that default account is not purely simulating EOA. So, medium is fair.

Alex the Entreprenerd (judge) commented:

The Warden has shown an edge case for Default Accounts, due to this being a discrepancy in intended behaviour, Medium Severity seems most appropriate.


The original report as published on Code4rena, by anon. 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 fallback function contains an assertion that reverts when the caller is the bootloader, which is triggered during delegatecall from a custom account.

Impact

Protocols relying on the default account's EOA-like behaviour could experience unexpected reverts, potentially leading to vulnerabilities.

What the attacker needed

Custom account delegates to default account

The fix

The fallback function should be modified to ignore delegatecalls, for example by adding an `ignoreInDelegateCall` modifier.

How it was found

  1. A custom account delegate-calls a default account.
  2. The default account's fallback function is invoked.
  3. The fallback function checks msg.sender and reverts because it is the bootloader address.
  4. The delegatecall returns false, causing the custom account's execution to fail.

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 default account is supposed to act like a normal wallet address, but when another smart contract tries to use it in a special way (delegatecall), it fails instead of behaving normally. This unexpected failure could break other contracts that assume it will always work.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by anon

View all

10 more disclosed reports, best first.

More from zkSync Era

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.