Open c4-submissions opened 1 year ago
bytes032 marked the issue as primary issue
bytes032 marked the issue as sufficient quality report
miladpiri (sponsor) confirmed
The Warden has demonstrated a lack of contraints that would allow, per their own words to:
manipulate the sorted queue to emit already reverted l1 logs and events.
This allows for undefined behaviour, which may lead to exploits, leading me to believe that High Severity is appropriate
GalloDaSballo marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/era-zkevm_circuits/src/log_sorter/mod.rs#L331-L456
Vulnerability details
Impact
Attacker can manipulate the sorted queue in log sorter, constraints are not strong enough and reverted l1 logs and events can still be emitted.
Proof of Concept
Let's see what we have enforced in this circuit. For a unique timestamp, either there is only a write log, we should add it to the queue; or there is a write log and a rollback log, which means revert took place, we should ignore it.
At first, we enforce the timestamps in the sorted queue are in ascending orders, which means write log and rollback log of the same timestamp should be adjacent.
Here, for two consecutive element A, B in the queue, if A is not rollback and B is rollback, we enforce that A, B shares the same timestamp.
Here, for two consecutive element A, B in the queue, if they share the same timestamp, we enforce that they have the same written value. (This is already guaranteed by the earlier circuits)
This is almost the same as the second one.
Finally, for two consecutive element A, B in the queue, if A is write and A, B are different, we add A to the result queue.
We use w to denote write and r to denote rollback, two adjacent letters share the same timestamp. An ideal sorted queue would be like wr wr w w w wr. The system worked well in this case. However, what if someone submit wr rw wr rw as the sorted queue? All the four logs here are reverted, so no log should be added to the result queue. However, this sorted queue satisfy all the constraints, and it will add the second and the fourth log to the result queue. (Try it yourself!)
To conclude, the constraints are not strong enough and attacker can manipulate the sorted queue to emit already reverted l1 logs and events.
Tools Used
Manual
Recommended Mitigation Steps
Enforce that the first popped element is write and there are no two consecutive rollbacks in the sorted queue.
Assessed type
Context