In the _markBytecodeAsPublished function, the contract does not check whether a particular hash has already been added to the storage.
The contract only checks the current marker value of the hash, which is set to 0 by default, and if the value is still 0, the hash is saved to the storage, and the contract emits an event MarkedAsKnown. This means that an attacker can replay a transaction with the same bytecode hash, and the contract will add the same hash again to the storage, resulting in duplicate code.
Lines of code
https://github.com/code-423n4/2023-03-zksync/blob/21d9a364a4a75adfa6f1e038232d8c0f39858a64/contracts/KnownCodesStorage.sol#L73-L75
Vulnerability details
Impact
Injection of duplicate code.
Proof of Concept
In the
_markBytecodeAsPublished
function, the contract does not check whether a particular hash has already been added to the storage.The contract only checks the current marker value of the hash, which is set to
0
by default, and if the value is still0
, the hash is saved to the storage, and the contract emits an eventMarkedAsKnown
. This means that an attacker can replay a transaction with the same bytecode hash, and the contract will add the same hash again to the storage, resulting in duplicate code.Vulnerable code: https://github.com/code-423n4/2023-03-zksync/blob/21d9a364a4a75adfa6f1e038232d8c0f39858a64/contracts/KnownCodesStorage.sol#L59-L79
Tools Used
Manual audit
Recommended Mitigation Steps
The contract should first check whether the hash has already been added to the storage before saving it again.
Updated code: