Open amaron14 opened 3 months ago
Factory
Contract: Insufficient Validation on Contract DeploymentThe Factory
contract contains a vulnerability in its deployVault()
function that allows an attacker to prevent the deployment of a Vault
contract by manipulating the state of the target address. This vulnerability is due to an insufficient check when determining whether a contract has already been deployed at a given address.
In the current implementation, the deployVault()
function checks whether a Vault
contract has already been deployed at the computed address using the following condition:
if (vaultAddress.codehash != bytes32(0)) { revert AlreadyDeployed(); }
However, this check is insufficient because, according to EIP-1052, an address with a non-zero balance but no code will not return bytes32(0)
for its codehash
. Instead, it will return the hash of an empty string, keccak256("")
.
An attacker can:
Vault
contract will be deployed.codehash
to become keccak256("")
.deployVault()
, the vaultAddress.codehash != bytes32(0)
check will pass incorrectly, causing the transaction to revert with the AlreadyDeployed()
error.This vulnerability can be exploited to perform a denial-of-service (DoS) attack, preventing legitimate users from deploying their Vault
contract by preemptively sending a small amount of ETH to the target address.
You are correct!
Gj @amaron14.
Insufficient Check for Existing Code: The check vaultAddress.codehash != bytes32(0) is used to determine if a Vault contract has already been deployed at the computed address. However, this check is insufficient because, as per EIP-1052, an address with a non-zero balance but no code will not return bytes32(0) for its codehash. Instead, it will return the hash of an empty string, keccak256("").
Potential Attack Vector: An attacker can compute the address where the Vault contract will be deployed), then transfer a small amount of ETH (like 1 wei) to this address. This would cause the codehash at the address to be keccak256(""), not bytes32(0). Consequently, the condition vaultAddress.codehash != bytes32(0) would incorrectly pass, and the deployVault() function would revert with AlreadyDeployed(), preventing the legitimate deployment of the Vault contract.
This could result in a denial-of-service (DoS) attack, where the attacker can prevent a user from deploying their
Vault
contract by preemptively sending a small amount of ETH to the address where the contract would be deployed.