Submitted by hrkrshnn, also found by jonah1005 and walker
The above function is designed to expect the token at the end of calldata, but a malicious user can inject extra values at the end of calldata and fake return values.
The following contract demonstrates an example:
This example can be used to exploit the protocol:
State token Token1. Lets say there is a more expensive token
Token2.
Heres an example exploit:
All the calculations on ps would be done on Token2, but at the end, because of, _token.safeTransfer(_receiver, amount);, Token2 would be transferred. Assuming that Token2 is more expensive than Token1, the attacker makes a profit.
Similarly, the same technique can be used at a lot of other places. Even if this exploit is not profitable, the fact that the computations can be done on two different tokens is buggy.
There are several other places where the same pattern is used. All of them needs to be fixed. Ive not written an exhaustive list.
Evert0x (Sherlock) confirmed
