The PreMarkets::createOffer()
function in the PreMarktes
contract is payable
which allows users to send Ether via the tillIn()
function which is called inside the PreMarkets::createOffer()
function, which basically forward msg.value
Sent towards TokenManager
Contract. problem arises when we pass a token address other than WETH (Wrapped Ether) to the PreMarkets::createOffer(CreateOfferParams calldata params)
and also Send ETH at same time when creating a offer. This can lead to the Ether being locked in the contract and user unable to withdraw full amount deposited when creating a offer after closing the offer`.
in this case if we pass any other address to CreateOfferParams.tokenAddress
than WETH
and also try to send ETH
at the same time, the user will pay more than required amount to create offer and also if user decides to close the offer and withdraw funds, user will receive less than expected amount.
For example, if we create an offer with 0.01 * 1e18
USDC and 1 ether
, we expect to withdraw slightly less than the deposited amount. However, the 1 ether
remains in the TokenManager
contract and is not retrievable after closing the offer. The user will only receive USDC back, even though the offer was created with both 1 ether
and 0.01 * 1e18
USDC.
User calls PreMarkets::createOffer()
function with CreateOfferParams.tokenAddress
set to a non-WETH token
address (in this example we use USDC
) and sends 1 ether
at the same
time.
The tillIn()
function inside the PreMarkets::createOffer()
function sends our ETH
and non-WETH token
to TokenManager
contract.
User decides to close the offer, so calls the PreMarkets::closeOffer()
function which then increases user TokenManagerStorage::userTokenBalanceMap
mapping value of the user, which
enables user to withdraw
.
then user calls TokenManager::withdraw()
function, to get his 1 ether
and USDC amount sent back when he created the offer.
User successfully receives the Correct USDC amount but User Does not receieve any ether
and the 1 ether
we sent to TokenManager
contract, will stay there and cannot do anything about it to get it back.
run the test with following command:
take a look at the Logs
:
Add a check to ensure Ether is only sent when the specified token address is WETH
.
This check ensures Ether is only sent with WETH
, preventing loss of funds due to incorrect token handling.
Invalid, these are by default, invalid based on codehawks [general guidelines](https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity#findings-that-may-be-invalid). The check implemented is simply a sufficiency check, it is users responsibility to only send an appropriate amount of native tokens where amount == msg.value when native token is intended to be used as collateral (which will subsequently be deposited as wrapped token). All excess ETH can be rescued using the `Rescuable.sol` contract. > Users sending ETH/native tokens > If contracts allow users to send tokens acc111identally.
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.