Skip to content
Access control Audit finding Advanced

User transactions can call system contracts directly

User transactions that send ETH to a non-ContractDeployer contract are routed through the MsgValueSimulator system contract, which sets the isSystemCall flag and forwards it to the destination, allowing the user to call system contracts directly. This bypasses the intended restriction that users cannot invoke potentially dangerous system operations.

Jeiwan Follow with ronnyx2017

Originally disclosed on Code4rena

Submitted by Jeiwan, also found by ronnyx2017

User transaction can call system contracts directly, which shouldn’t be allowed to not invoke potentially dangerous operations.

Proof of Concept

The DefaultAccount.executeTransaction executes a user transaction after it was validated. The function calls _execute under the hood. The _execute function makes two different calls depending on the destination address of a transaction:

  1. if the ContractDeployer is called, it’ll pass the call to the contract via the system call (ContractDeployer is a system contract and can be executed only via system calls);
  2. if any other contract is called, it’ll execute the call via EfficientCall.rawCall.

EfficientCall.rawCall in its turn also makes two different calls:

  1. If msg.value of the transaction is 0, it’ll make a regular call.
  2. If there’s some ETH sent with the transaction (i.e. msg.value is positive), it’ll pass the call to the MsgValueSimulator contract. MsgValueSimulator is a system contract, thus the isSystem flag will be set in the far call ABI (notice the true in the last argument of _loadFarCallABIIntoActivePtr). However, it’ll also set the forward mask to 1 (the value of MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT). MsgValueSimulator will extract the mask and will set the isSystemCall flag to true–it’ll then pass the isSystemCall flag to the subsequent call, making the call a system one.

To sum it up, if a transaction calls a contract that’s not ContractDeployer and sends ETH, the call will be a system one, which will let it call the system contracts. However, users shouldn’t be allowed to call system contracts directly to not invoke potentially dangerous operations. As per the documentation:

Some of the system contracts can act on behalf of the user or have a very important impact on the behavior of the account. That’s why we wanted to make it clear that users can not invoke potentially dangerous operations by doing a simple EVM-like call. Whenever a user wants to invoke some of the operations which we considered dangerous, they must explicitly provide isSystem flag with them.

However, since most system contracts are harmless, there’s no direct high severity impact on the system, thus I think the issue is a medium severity.

Recommended Mitigation Steps

In the EfficientCall.rawCall function, consider setting the forward mask to 0. The behaviour of the function is similar to that of the msgValueSimulatorMimicCall function from the bootloader:

  1. since the MsgValueSimulator contract is called, the isSystemCall flag should be set only for this call;
  2. the isSystemCall flag should be forwarded by MsgValueSimulator only if the destination contract is ContractDeployer.

It looks that the second part of the EfficientCall.rawCall function was copied from the SystemContractsCaller.systemCall function, which is intended to call system contracts and which sets the forward mask to 1 when calling MsgValueSimulator. However, rawCall shouldn’t forward the isSystemCall flag.

miladpiri (zkSync) confirmed and commented:

It is an issue, though realisticially most of the methods are non-payable.

Alex the Entreprenerd (judge) commented:

The Warden has shown a way to bypass the security checks that would prevent a end user to be able to call system contracts.

In lack of a loss of deposits, I agree with Medium Severity.


The original report as published on Code4rena, by Jeiwan. 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 EfficientCall.rawCall function sets the forward mask to 1 when calling MsgValueSimulator, causing the isSystemCall flag to be forwarded to the destination contract even though rawCall should not forward it.

Impact

Users could invoke potentially dangerous system operations, but since most system contracts are harmless, there is no direct high severity impact; the report rates it medium.

What the attacker needed

User can send a transaction with ETH; destination is not ContractDeployer

The fix

The EfficientCall.rawCall function should set the forward mask to 0 so that the isSystemCall flag is not forwarded to the destination contract.

How it was found

  1. A user sends a transaction that calls a contract other than ContractDeployer and includes a positive msg.value.
  2. EfficientCall.rawCall passes the call to the MsgValueSimulator contract and sets the forward mask to 1.
  3. MsgValueSimulator extracts the mask and sets the isSystemCall flag to true.
  4. MsgValueSimulator forwards the isSystemCall flag to the subsequent call, making it a system call.
  5. The user's transaction can now call system contracts directly.

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.

In this blockchain system, some special contracts (called system contracts) are meant to be used only by the system itself, not by ordinary users, because they can perform powerful actions. The report shows that if a user sends a transaction with some ETH to a normal contract, the system mistakenly marks the call as a system call, so the user can then reach those special contracts. This breaks the intended safety rule, though the report notes most system contracts are harmless.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by Jeiwan

View all

69 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.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.