Factory.create : Predictability of pool address creates multiple issues.
The address of a new PrivatePool was derived only from a user-supplied salt, so anyone watching the public mempool could front-run a create transaction with the same salt to deploy a pool at the expected address. This let an attacker capture a user's subsequent deposit or repeatedly block pool creation.
The Factory.create function is responsible for creating new PrivatePools. It does this using the LibClone.cloneDeterministic function.
function create(
...
bytes32 _salt,
...
) public payable returns (PrivatePool privatePool) {
if ((_baseToken == address(0) && msg.value != baseTokenAmount) || (_baseToken != address(0) && msg.value > 0)) {
revert PrivatePool.InvalidEthAmount();
}
// deploy a minimal proxy clone of the private pool implementation
privatePool = PrivatePool(payable(privatePoolImplementation.cloneDeterministic(_salt)));
// ...
}
The address of the new PrivatePool depends solely upon the _salt parameter provided by the user. Once the user’s create transaction is broadcasted, the _salt parameter can be viewed by anyone watching the public mempool.
This public readability of _salt parameter creates two issues:
Stealing of user’s deposit amount.
If a user intends to create new pool and deposit some funds in it then an attacker can frontrun the user’s txns and capture the deposit amounts. Here is how this can happen:
User broadcasts two txns, first one to create a pool with XXX as the salt and second one to deposit some ETH into the new pool.
The attacker views these pending txns and frontruns them to create a PrivatePool for himself with same XXX salt.
The new pool gets created for the attacker, the address of this pool will be same as what the user will be expecting for his pool.
The user’s create pool txn gets reverted but deposit txn gets executed successfully. Hence the user deposited ETH in attacker’s pool.
Being the owner of the pool the attacker simply withdraws the deposited ETH from the PrivatePool.
DoS for Factory.create.
If a user intends to create a PrivatePool, his create txn can be forcefully reverted by an attacker by deploying a pool for himself using the user’s salt. Here is how this can happen:
The user broadcasts the create pool txn with salt XXX.
The attacker frontruns the user’s txn and creates a pool for hiself using the same XXX salt.
The user’s original create txn gets reverted as attacker’s pool already exist on the predetermined address.
This attack can be repeated again and again resulting in DoS for the Factory.create function.
Proof of Concept
These test cases were added to test/PrivatePool/Withdraw.t.sol file and were ran using forge test --ffi --mp test/PrivatePool/Withdraw.t.sol --mt test_audit
The proposed fix is to include the msg.sender in the salt of the proxy deployment:
// deploy a minimal proxy clone of the private pool implementation
bytes32 salt = keccak256(abi.encode(msg.sender, _salt));
privatePool = PrivatePool(payable(privatePoolImplementation.cloneDeterministic(salt)));
The original report as published on Code4rena, by AkshaySrivastav. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
An attacker could steal a user's deposit or cause a denial of service against pool creation, though the judge noted the DoS can be sidestepped by using a new salt and downgraded severity to Medium.
What the attacker needed
Attacker can watch the public mempool; attacker can front-run transactions
The fix
The fix was to include the sender's address in the salt used for deterministic deployment, and it was confirmed mitigated.
How it was found
User broadcasts a transaction to create a pool with a chosen salt.
Attacker sees the pending transaction and front-runs it, creating a pool with the same salt.
The attacker's pool occupies the address the user expected.
The user's create transaction reverts, but a subsequent deposit transaction succeeds into the attacker's pool.
The attacker, as pool owner, withdraws the deposited funds.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When you create a pool, its address is calculated from a number you choose called a salt. Because that number is visible before your transaction is confirmed, someone else can use the same salt first and take the address you expected. Then your deposit goes into their pool, or your creation fails.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.