Closed code423n4 closed 1 year ago
All addresses fit in u160, that said am flagging this specific one to see if this hits an edge case
This is how the EVM calculate extcodesize
/extcodehash
/codesize
/codehash
. The low bits are just ignored. It is intended features, not a bug.
miladpiri marked the issue as sponsor disputed
Agree with the sponsor per this line from the spec:
If EXTCODEHASH of A is X, then EXTCODEHASH of A + 2**160 is X.
GalloDaSballo marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2023-03-zksync//blob/main/contracts/AccountCodeStorage.sol#L74-L123
Vulnerability details
Impact
In
AccountCodeStorage.sol
we have function getCodeHash() and getCodeSize Due to an insecure cast, it is possible to get an integer overflow. Solidity version >0.8.0 provide SafeMath, but casting operations are not safe and can overflow.Proof of Concept
As can be seen from the code snippet below,
getCodeHash
intake_input
which is uint256. This input is used on line 77 and 78 and as seen below we have unsafe cast from uint160 to uint256.Absolutely the same applies to the function
getCodeSize()
in the same contract. You need to make sure that the values fit in the variables you are trying to assign them to when casting variables.Tools Used
Manual Review
Recommended Mitigation Steps
Consider using OpenZeppelin's SafeCast library to prevent unexpected overflows when casting.