Function redeem(uint256 tokenId, uint256 amount_) public basically(it does a function call to internal fct)
Intended behavior.
The function should enable users to redeem matured bond tokens issued by Bond Protocol for the vested underlying tokens.
The function should burn the corresponding amount of
tokenIdtokens.And transfer to
msg.senderthe same amount ofpayoutToken.
Negative behavior.
Don’t redeem bonds that have not reached maturity:
if (block.timestamp < meta.expiry) revert Teller_TokenNotMatured(meta.expiry);Don’t redeem “counterfeit” bonds that aren’t issued by Bond Protocol:
_burnTokencalled only for local bonds tokensDo not give out too many or too few underlying tokens: it is possible to send only the amount of
payoutTokenthat is available on theBondbalance ofmsg.senderbalanceOf[msg.sender][tokenId] -= amount;otherwise, the transaction will be rejected on this lineDon’t give out the wrong payoutToken token:
payoutTokenaddress taken fromtokenMetadatafor correspondingtokenId. An attacker can add any address ofpayoutTokento thetokenMetadata, but because of the_burnTokenfunction call, they can only redeem their tokens.Don’t give or take tokens from the wrong user.
Preconditions.
The user has locked
payoutTokentokens with the teller and received bond tokens in return withtokenIdwhich connected with thispayoutTokenandexpiryvalue.The bonds have reached maturity.
Assumes that the
tokenidhas active metadata (it would fail otherwise anyway due to theburnTokenfunction, there’d be an underflow there)The bonds could have not been infinitely created; since the multiple
bondTokenscan be created for the samepayoutTokenthis means that there might be a way to drain the contract if there is a way to craft infinitely manybondTokens!
Postconditions.
The user has now more underlying tokens.
The user has now less bond tokens.
the protocol should still have some
underlyingtokens left to pay the other users.
Inputs.
tokenId_: controlled,
amount_: controlled,
Examine all function calls the function makes.
a. Call to
burnToken(msg.sender, tokenId*, amount_);What is controllable? (callee, params, return value):
msg.sender;tokenId- directly controlled; COULD BE USER TO burn arbitrary bond tokens, however, they would have to be minted viacreatein the first place;amount_- controlledIf 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? No problem
b. Call to
meta.payoutToken.safeTransfer(msg.sender, amount_)What is controllable? (callee, params, return value):
meta.payoutToken- controlled; could be used to drain arbitraryunderlyingtokens, however, the bondTokens issued for them would have to be burned in the first place, so no profit could really be made;msg.sender;amount_- controlledIf 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? No problem