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
tokenId
tokens.And transfer to
msg.sender
the 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:
_burnToken
called only for local bonds tokensDo not give out too many or too few underlying tokens: it is possible to send only the amount of
payoutToken
that is available on theBond
balance ofmsg.sender
balanceOf[msg.sender][tokenId] -= amount;
otherwise, the transaction will be rejected on this lineDon’t give out the wrong payoutToken token:
payoutToken
address taken fromtokenMetadata
for correspondingtokenId
. An attacker can add any address ofpayoutToken
to thetokenMetadata
, but because of the_burnToken
function call, they can only redeem their tokens.Don’t give or take tokens from the wrong user.
Preconditions.
The user has locked
payoutToken
tokens with the teller and received bond tokens in return withtokenId
which connected with thispayoutToken
andexpiry
value.The bonds have reached maturity.
Assumes that the
tokenid
has active metadata (it would fail otherwise anyway due to theburnToken
function, there’d be an underflow there)The bonds could have not been infinitely created; since the multiple
bondTokens
can be created for the samepayoutToken
this 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
underlying
tokens 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 viacreate
in 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 arbitraryunderlying
tokens, 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