Skip to content
Business logic Audit finding Intermediate

Time-sensitive contracts deployed on zkSync

On zkSync, block intervals are not fixed like on Ethereum, so contracts that use block.number to measure time will experience unpredictable delays. Additionally, the timestamp can be frozen across multiple blocks, breaking time assumptions.

HE1M Follow with minaminao, rvierdiiev and 1 other

Originally disclosed on Code4rena

Submitted by HE1M, also found by minaminao, rvierdiiev, and 0x73696d616f

Time-sensitive contracts will be impacted if deployed on zkSync.

Proof of Concept

Many contracts use block.number to measure the time as the miners were able to manipulate the timestamp (the timestamp could be easily gamed over short intervals). So, it was assumed that block.number is a safer and more accurate source of measuring time than timestamp.

For instance, if a defi project sets 144000 block interval to release the interest, it means approximately 144000 * 12 = 20 days. Please note that each block in Ethereum takes almost 12 second.

If the same defi project is deployed on zkSync, it will not operate as expected. Because there is no time-bound for the blocks in zkSync (the interval may be 30 seconds or 1 week). So, the time to release the interest can be between 50 days to 2762 days.

Since, it is assumed that zkSync is Ethereum compatible, any deployed contracts on Ethereum may deploy their contract in zkSync without noting such big difference.

Even if the contracts use timestamp to measure the time, there will be another issue. In the contract SystemContext.sol, it is possible to set new block with the same timestamp as previous block, but with incremented block number. https://github.com/code-423n4/2023-03-zksync/blob/21d9a364a4a75adfa6f1e038232d8c0f39858a64/contracts/SystemContext.sol#L116

In other words, new blocks are created but their time is frozen. Please note that freezing time can not be lasted for a long time, because when committing block their timestamp will be validated against a defined boundary.

Recommended Mitigation Steps

It should be explicitly mentioned that block intervals in zkSync are not compatible with Ethereum. So, time-sensitive contracts will be noted.

Moreover, the equal sign should be removed in the following line: https://github.com/code-423n4/2023-03-zksync/blob/21d9a364a4a75adfa6f1e038232d8c0f39858a64/contracts/SystemContext.sol#L116

miladpiri (zkSync) confirmed and commented:

Two issues are stated:

  1. Block timestamp issue (which is duplicate of some other reports). dup #31 (Low)
  2. Block creation rate is not consistent with Ethereum. (not duplicate) (Medium)

The judges can decide better how to distinguish them.

Alex the Entreprenerd (judge) commented:

The warden has shown how the zkEVM could differ from the EVM in how block timing is enforced, because blocks can happen at inconsistent times, protocols contract could have their time assumptions broken.

Because this is a finding that has been addressed by other L2s, and causes inconsistent behaviour vs the EVM, I agree with Medium Severity.


The original report as published on Code4rena, by HE1M. 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, zkSync does not enforce a consistent block time and allows blocks with the same timestamp, unlike Ethereum where block time is roughly constant and timestamps increase.

Impact

Time-sensitive contracts deployed on zkSync may release funds or perform actions much later or earlier than intended, potentially locking funds for extended periods or causing financial loss.

What the attacker needed

Contract deployed on zkSync; contract uses block.number or timestamp for time

The fix

The report recommends explicitly documenting that block intervals on zkSync are not compatible with Ethereum and removing the equal sign in the timestamp validation to prevent blocks with identical timestamps.

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.

Smart contracts often use the number of blocks mined to measure time, assuming each block takes about 12 seconds as on Ethereum. On zkSync, blocks can be produced at very different rates, so time-based logic in contracts may not work as expected. Also, the timestamp of a new block can be the same as the previous one, which can further confuse time calculations.

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 HE1M

View all

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