Function _handleTransfers(uint256 id_, uint256 amount_, uint256 payout_, uint256 feePaid_) internal
INTERNAL FUNCTION
Intended behavior.
Handles transfer of funds from user and market owner/callback
Negative behavior.
Shouldn’t allow sending to an address different than market owner/ callback.
Shouldn’t allow users to transfer CRAFTED tokens (via a malicious market for example) and retrieve useful tokens.(
as payout). This could happen inmarketsfrom BondBaseSDA.
Preconditions.
msg.sendershould approve to transferamount_value of thequoteTokentokens to Teller contract.That the quote tokens supplied by the
msg.senderare perfectly fine, and they have been whitelisted/ accepted before, and that there is no way to supply dummy tokens in exchange for legitimate payout tokens.ownerof the market should approve transferringpayoutvalue of thepayoutTokentokens to Teller contract.
Postconditions.
The
quoteToken.balanceOf[msg.sender]should be depleted byamount, and thequoteToken.balanceOf[callback OR owner of market]should increase by amount after fees.The
payoutToken.balanceOf[callback OR owner of market]should be depleted bypayout_and thepayoutToken.balanceOf[address(this)]should increase bypayout_
Inputs.
uint256 id_ - controlled
uint256 amount_ - controlled, if caller approved not enough tokens transaction will be rejected.
uint256 payout_ - uncontrolled, if the market owner approves not enough tokens transaction will be rejected.
uint256 feePaid_ - uncontrolled
Examine all function calls the function makes.
a. Call to
aggregator.getAuctioneer(id).getMarketInfoForPurchase(id_);What is controllable? (callee, params, return value):
(address owner, address callbackAddr, ERC20 payoutToken, ERC20 quoteToken, , )- it's not really controllable since it’s supposedly whitelisted in thegetAuctioneerfunction from theaggregatorIf return value controllable, how is it used and how can it go wrong? uncontrolled
What happens if it reverts or tries to reenter? No problem
b. Call to
quoteBalance = quoteToken.balanceOf(address(this))What is controllable? (callee, params, return value): uncontrolled
If return value controllable, how is it used and how can it go wrong? even if the caller controls the token and can manipulate with return value, this doesn't affect any users. In the case of using legitimate token address caller cannot manipulate this value.
What happens if it reverts or tries to reenter? No problem
c. Call to
quoteToken.safeTransferFrom(msg.sender, address(this), amount_)What is controllable? (callee, params, return value): caller controls
amount_valueIf return value controllable, how is it used and how can it go wrong? There is no return value.
What happens if it reverts or tries to reenter? if the caller approved not enough tokens or the caller doesn’t have enough tokens, then the transaction will be rejected
d. Call to
IBondCallback(callbackAddr).callback(id_, amountLessFee, payout_);What is controllable? (callee, params, return value): it’s supposed to handle the
payoutTokensvia thecallbackfunction back to the caller(BondBaseTeller); theid_andpayout_params are directly controllable, being supplied through the_handleTransfersfunction.If return value controllable, how is it used and how can it go wrong? There is no return value.
What happens if it reverts or tries to reenter? if this reverts, there are no
payoutTokenstransferred from thecallback, and thus, the transaction itself fails.