The Escrow::_withdrawFromEscrow
function is designed to allow a user withdraw tokens they deposited into the escrow. However, this function only checks if the token to be withdrawn was deposited in the escrow without checking if the user attempting to withdraw the token is the owner of the token or not. Hence, just anyone can withdraw token from escrow.
The vulnerability of the Escrow::_withdrawFromEscrow
function lies here
The above code snippet can further be verified at https://github.com/Cyfrin/2024-07-ark-project/blob/273b7b94986d3914d5ee737c99a59ec8728b1517/apps/blockchain/ethereum/src/Escrow.sol#L63-L89
Notice that the _withdrawFromEscrow
calls _isEscrowed
which only checks if the token was deposited in the escrow as can be seen in the code snippet below
The above code snippet can further be verified at https://github.com/Cyfrin/2024-07-ark-project/blob/273b7b94986d3914d5ee737c99a59ec8728b1517/apps/blockchain/ethereum/src/Escrow.sol#L99-L108
Thus, just anyone can withdraw a token from escrow in so far as the token is in the escrow.
Because the Escrow::_withdrawFromEscrow
function does not check if the caller is the owner of the token in escrow or not, any user who is aware that a token has been deposited in escrow can withdraw that token leading to loss of user tokens and funds.
Manual Review
Foundry
Proof of Concept:
User A deposits their token in escrow
User B notices that a token has been deposited in escrow and withdraws the token from escrow
Now the token belongs to user B and user A losses their token and funds
Consider modifying the -withdrawFromEscrow
function to check if the caller is the owner of the token.
This will ensure that only the owner can withdraw a token from escrow thus, making the protocol safer for users and keeping user tokens safe.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.