The token balance is incorrectly updated in the function settleAskTaker
. This leads to wrong calculation in the protocol, and stealing of fund.
Suppose a maker creates a bid offer, and a taker places an ask order against the maker's offer.
After the market update and TGE, the function settleAskTaker
is called to settle the trade. It is expected that the required amount of marketPlaceInfo.tokenAddress
be added to the balance of the maker. Note that the amount of marketPlaceInfo.tokenAddress
is equal to the multiplication of the promised points and token per point:
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/DeliveryPlace.sol#L373
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/DeliveryPlace.sol#L384
The issue is that the balance is updated with the address of makerInfo.tokenAddress
, instead of marketPlaceInfo.tokenAddress
.
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/DeliveryPlace.sol#L387
It means that, the maker balance was expected to be equal to userTokenBalanceMap[maker][marketPlaceInfo.tokenAddress][TokenBalanceType.PointToken] = settledPointTokenAmount
, but due to the mistake in the implementation, the maker balance is equal to userTokenBalanceMap[maker][makerInfo.tokenAddress][TokenBalanceType.PointToken] = settledPointTokenAmount
.
Note that makerInfo.tokenAddress
is the collateral, while marketPlaceInfo.tokenAddress
is the newly-generated token after TGE.
In this test, Alice (maker), creates a bid offer to buy 1_000_000 points for $1. Bob (taker) places an ask order against Alice's offer. After the market update and TGE, each point worths 1e18
of newly-generated token (here it is called mockPointToken
). It means that, after the settlement, Alice should have 1_000_000 * 1e18
of newly-generated token in her balance.
Due the bug explained, the balance of Alice would be userTokenBalanceMap[Alice][USDC][TokenBalanceType.PointToken] = 1_000_000 * 1e18
, instead of userTokenBalanceMap[Alice][mockPointToken][TokenBalanceType.PointToken] = 1_000_000 * 1e18
. It means that Alice is now able to withdraw almost $1M from the protocol.
An attacker can misuse this vulnerability and stealing fund without any honest maker or taker being involved.
The output is:
Wrong calculation in the protocol.
Stealing of fund.
The following is recommended:
https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/DeliveryPlace.sol#L387
Valid high severity, In `settleAskTaker/closeBidTaker`, by assigning collateral token to user balance instead of point token, if collateral token is worth more than point, this can cause stealing of other users collateral tokens within the CapitalPool contract, If the opposite occurs, user loses funds based on the points they are supposed to receive
Valid high severity, In `settleAskTaker/closeBidTaker`, by assigning collateral token to user balance instead of point token, if collateral token is worth more than point, this can cause stealing of other users collateral tokens within the CapitalPool contract, If the opposite occurs, user loses funds based on the points they are supposed to receive
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.