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:
- if the
ContractDeployeris called, it’ll pass the call to the contract via the system call (ContractDeployeris a system contract and can be executed only via system calls); - if any other contract is called, it’ll execute the call via
EfficientCall.rawCall.
EfficientCall.rawCall in its turn also makes two different calls:
- If
msg.valueof the transaction is 0, it’ll make a regular call. - If there’s some ETH sent with the transaction (i.e.
msg.valueis positive), it’ll pass the call to theMsgValueSimulatorcontract.MsgValueSimulatoris a system contract, thus theisSystemflag will be set in the far call ABI (notice thetruein the last argument of_loadFarCallABIIntoActivePtr). However, it’ll also set the forward mask to 1 (the value of MSG_VALUE_SIMULATOR_IS_SYSTEM_BIT).MsgValueSimulatorwill extract the mask and will set theisSystemCallflag to true–it’ll then pass theisSystemCallflag 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:
- since the
MsgValueSimulatorcontract is called, theisSystemCallflag should be set only for this call; - the
isSystemCallflag should be forwarded byMsgValueSimulatoronly if the destination contract isContractDeployer.
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.
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
- A user sends a transaction that calls a contract other than ContractDeployer and includes a positive msg.value.
- EfficientCall.rawCall passes the call to the MsgValueSimulator contract and sets the forward mask to 1.
- MsgValueSimulator extracts the mask and sets the isSystemCall flag to true.
- MsgValueSimulator forwards the isSystemCall flag to the subsequent call, making it a system call.
- 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.