Forceful deployment is meant to upgrade only specific addresses as also mentioned in comments
"
/// @notice This method is to be used only during an upgrade to set bytecodes on specific addresses.
/// @dev We do not require onlySystemCall here, since the method is accessible only
/// by FORCE_DEPLOYER.
function forceDeployOnAddresses(ForceDeployment[] calldata _deployments) external payable {
"
Although it seems that this function fails to check if _deployment.newAddress is one of those specific address only. This means FORCE_DEPLOYER can give any other contract address and that contract bytecode will get upgraded
Proof of Concept
Observe the forceDeployOnAddress function (called by forceDeployOnAddresses)
Lines of code
https://github.com/code-423n4/2023-03-zksync//blob/main/contracts/ContractDeployer.sol#L214
Vulnerability details
Impact
Forceful deployment is meant to upgrade only specific addresses as also mentioned in comments
" /// @notice This method is to be used only during an upgrade to set bytecodes on specific addresses. /// @dev We do not require
onlySystemCall
here, since the method is accessible only /// byFORCE_DEPLOYER
. function forceDeployOnAddresses(ForceDeployment[] calldata _deployments) external payable { "Although it seems that this function fails to check if
_deployment.newAddress
is one of those specific address only. This meansFORCE_DEPLOYER
can give any other contract address and that contract bytecode will get upgradedProof of Concept
forceDeployOnAddress
function (called byforceDeployOnAddresses
)Observe there is no check to validate that
_deployment.newAddress
is from a whitelisted set of addressSo if this function is called on a random existing contract then that contract will get overwritten with the provided bytecodes
Note: Random bytecode cannot be placed and only whitelisted bytecode can be placed. But existing contract code could get overwritten
Recommended Mitigation Steps
ForceDeployment should only work on whitelisted set of contracts and should not be allowed to upgrade any random address