Rebase and fee-on-transfer tokens
There are various tokens with custom implementations of how user balances are updated over time. The most common of these are fee-on-transfer and rebase tokens. Due to the complexity and cost of persistent accounting we don't intend to support these tokens.
If the protocol uses non-fee-on-transfer tokens (e.g. USDC) but someday these tokens upgrade to fee-on-transfer tokens, transactions may fail and the protocol will lose tokens to compensate users for the execution.
Another scenario is, if Alice creates a long call option and Bob takes it by calling fillOrder, then the token is upgraded to fee-on-transfer token. In this case, Alice can call exercise to put order.strike amount into the protocol, but Bob may be unable to call withdraw to get order.strike amount due to the fee-on-transfer token.
Proof of Concept
The protocol will receive tokens in fillOrder, it should record amounts as afterAmount - beforeAmount rather than order.strike directly.
Lines of code
https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L268 https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L436
Vulnerability details
Impact
Though the document says:
If the protocol uses non-fee-on-transfer tokens (e.g. USDC) but someday these tokens upgrade to fee-on-transfer tokens, transactions may fail and the protocol will lose tokens to compensate users for the execution.
Another scenario is, if Alice creates a long call option and Bob takes it by calling
fillOrder
, then the token is upgraded to fee-on-transfer token. In this case, Alice can callexercise
to putorder.strike
amount into the protocol, but Bob may be unable to callwithdraw
to getorder.strike
amount due to the fee-on-transfer token.Proof of Concept
The protocol will receive tokens in
fillOrder
, it should record amounts asafterAmount - beforeAmount
rather thanorder.strike
directly.Another scenario is, if Alice creates a long call option and Bob takes it by calling
fillOrder
, then the token is upgraded to fee-on-transfer token. Now Alice can callexercise
to putorder.strike
amount into the protocol: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L436But Bob may be unable to call
withdraw
to getorder.strike
amount, or the protocol will lose a part offeeAmount
: https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#L503Tools Used
None
Recommended Mitigation Steps
Token Transfer Calculation Accuracy in this article: https://blog.chain.link/defi-security-best-practices/