Assessment reports>Bond Protocol>Threat Models>purchase

Function purchase( address recipient_, address referrer_, uint256 id_, uint256 amount_, uint256 minAmountOut_ ) external nonReentrant

  1. Intended behavior.

    • allows users to exchange the amount of quoteToken to payoutToken.

    • calculates the fee values for referrer_ if it exists and for Protocol if protocolFee was set.

    • calculate the payout value for auctioneer with passed id_ for amountLessFee value.

    • saves fee values for later withdrawal

    • transfer from the msg.sender the amount of the quoteToken token to contract address.

    • over callbackAddr address or directly transfer the payout value of the payoutToken from market owner to contract address.

    • to callbackAddr address or directly transfer the amountLessFee value of the quoteToken from contract address to owner of market.

    • transferring tokens directly to the recipient_ address if it is InstantSwap or mint for the recipient_ the payout amount of Bonds tokens which will be blocked for exchange to the payoutToken before the expiry time.

  2. Negative behavior.

    • msg.sender sent an insufficient number of the quoteToken tokens

    • payout less then minAmountOut_

    • the market for the id_ doesn't exist; assure that in getMarketInfoForPurchase from BondBaseSDA

    • the market owner doesn’t have enough payoutToken tokens

    • if it isn’t InstantSwap then recipient_ shouldn't receive payoutToken, but only Bonds tokens

    • if it is InstantSwap then recipient_ shouldn’t receive the Bonds tokens, but only payoutToken.

    • Shouldn’t allow transferring on behalf of other users.

  3. Preconditions.

    • The market for the corresponding id_ should be registered inside the _aggregator contract, to do this, the address of the Auctioneer which store the markets must be whitelisted inside _aggregator contract.

    • msg.sender should have enough quoteToken tokens ≥ amount

    • market owner should have enough payoutTokenpayout

  4. Postconditions.

    • if callbackAddr != address(0), then amountLessFee value of quoteToken tokens should be successfully sent to callbackAddr

    • msg.sender balance of quoteToken decreased by amount quantity of tokens

    • owner balance of payoutToken decreased by payout quantity of tokens

    • if InstantSwap then recipient_ should successfully receive the payout value of payoutToken

    • if it isn’t InstantSwap then recipient_ received the payout value of Bond tokens with the corresponding non-zero expiry time

    • rewards increased for non-zero referrer_ by toReferrer amount of quoteToken tokens

    • rewards increased for _protocol by non-zero toProtocol amount of quoteToken tokens

  5. Inputs.

    • address recipient_ - controlled. can be any address

    • address referrer_ - controlled. can be any address

    • uint256 id_ - controlled. used to select market

    • uint256 amount_ - controlled, amount of quoteToken which msg.sender should transfer to contract, there is a check inside the _handleTransfers function

    • uint256 minAmountOut* - controlled, min amount of payout tokens, which recipient*will receive, there is a check inside theauctioneer.purchaseBond function

  6. Examine all function calls the function makes.

    a. Call to IBondAuctioneer auctioneer = aggregator.getAuctioneer(id_)

    • What is controllable? (callee, params, return value): id_ - controlled, msg.sender can choose any created auctioneer by their id_ value. only a whitelisted contract can become an auctioneer.

    • If return value controllable, how is it used and how can it go wrong? if auctioneer for current id_ doesn’t exist, then getAuctioneer function will return address(0) otherwise will return auctioneer address which has created the market.

    • What happens if it reverts or tries to reenter? aggregator - is a trusted contract address, no problems here

    b. Call to auctioneer.getMarketInfoForPurchase(id_)

    • What is controllable? (callee, params, return value): id_ - controlled. it is unique market identification

    • If return value controllable, how is it used and how can it go wrong? address owner - market owner address can be any user. should transfer the necessary amount of payoutToken; address payoutToken - controlled, any user can create a market with any token address; address quoteToken - controlled, any user can create a market with any token address; uint48 vesting - controlled, any user can create a market with any vesting time. However, the values are controlled, the user must transfer the appropriate number of tokens for exchange. if these are dummy tokens, users will not exchange them.

    • What happens if it reverts or tries to reenter? No problem

    c. Call to auctioneer.purchaseBond(id_, amountLessFee, minAmountOut_)

    • What is controllable? (callee, params, return value): id_ - controlled; amountLessFee - partially controlled because it's an amount value minus the fee values; minAmountOut_ - controlled, if payout less than minAmountOut_, transaction should be rejected.

    • If return value controllable, how is it used and how can it go wrong? as a result of calculation errors, the user may receive more payout tokens than he should; if payout value is less than minAmountOut_, the transaction should be canceled.

    • What happens if it reverts or tries to reenter? Can revert in case if payout value is less than minAmountOut_, expected behavior.

    d. Call to handleTransfers(id, amount_, payout, toReferrer + toProtocol)

    • What is controllable? (callee, params, return value): id_ - controlled; amount_ - controlled, there is a check that msg.sender transfer no less than amount_ to contract address; payout - uncontrolled, there is a check that owner transfer no less than payout to contract address; toReferrer + toProtocol - uncontrolled

    • If return value controllable, how is it used and how can it go wrong?

    • What happens if it reverts or tries to reenter?

    f. Call to handlePayout(recipient, payout, payoutToken, vesting): full review in the description of BondFixedTermTeller.sol

Zellic © 2024Back to top ↑