Skip to content
Business logic Audit finding Advanced

Operator can steal all gas provided by ANY user for L1→L2 transactions

The bootloader's gas refund calculation for L1→L2 transactions uses an unchecked addition, allowing a malicious operator to inflate the refund value and cause an overflow. This lets the operator steal all gas provided by any user.

erebus Follow with bin2chen and anon

Originally disclosed on Code4rena

Submitted by erebus, also found by bin2chen and anon

In bootloader, function processL1Tx, it is possible for a malicious operator to steal all the gas provided by ANY user who requests an L1⇒L2 transaction simply by returning an overinflated refundGas for the transaction execution.

Proof of concept

The refundGas the user will receive is the sum of:

Note: please see scenario in warden’s original submission.

With reservedGas being the excess of gas between what the user provided and what the operator is willing to use, and refundGas (not the final one) is the remaining gas left after preparing and executing the requested transaction.

As both quantities are added via the opcode add:

bootloader, line 921

                refundGas := add(refundGas, reservedGas)

The operator can return an over-inflated value so that it gets picked by the max() function and is added to reservedGas; overflowing the result as there are no checks for overflows in assembly:

bootloader, lines 921-927

                refundGas := add(refundGas, reservedGas) // overflow, refundGas = 0 while gasLimit != 0

                if gt(refundGas, gasLimit) { // correct, 0 < x for all x iff x != 0
                    assertionError("L1: refundGas > gasLimit")
                }

                // gasPrice * (gasLimit - refundGas) == gasPrice * (gasLimit - 0) == gasPrice * gasLimit
                let payToOperator := safeMul(gasPrice, safeSub(gasLimit, refundGas, "lpah"), "mnk")

As anyone will be able to be an operator once zkSync Era becomes decentralized, this issue becomes critical as it would be possible for ANY operator to “farm” the gas provided by ANY user.

Recommended Mitigation Steps

Just use safeAdd:

bootloader, line 921

-               refundGas := add(refundGas, reservedGas)
+               refundGas := safeAdd(refundGas, reservedGas, "The operator is being an asshole")

miladpiri (zkSync) confirmed via duplicate issue #187

Alex the Entreprenerd (judge) commented:

Best because of formula, clearest and shows the fix.


The original report as published on Code4rena, by erebus. 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

The bootloader uses an unchecked addition (add) instead of a safe addition (safeAdd) when summing refundGas and reservedGas, allowing an overflow.

Impact

A malicious operator could steal all gas provided by any user for L1→L2 transactions, but this becomes critical only once zkSync Era is decentralized and anyone can be an operator.

What the attacker needed

ZkSync Era is decentralized; attacker acts as operator

The fix

The code should use safeAdd instead of add to prevent overflow.

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.

When you send a transaction from Ethereum to zkSync, you pay for gas upfront. The operator (the party processing the transaction) calculates how much gas to refund. Because the code adds two numbers without checking for overflow, a dishonest operator can make the refund wrap around to zero, keeping all the gas money for themselves.

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 erebus

View all

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