Submitted by Rhaydden, also found by Tigerfrake
reverse_simulate_swap_operations function incorrectly uses query_simulation instead of query_reverse_simulation when calculating multi-hop trades in reverse. As a result, users will get incorrect price calculations when they attempt to determine how many input tokens they need for a desired output amount.
In summary:
/contracts/pool-manager/src/queries.rs#L275
The bug is in the reverse_simulate_swap_operations function:
According to the docs and the example given in it:
We have a QUERY:
And a RESPONSE (ReverseSimulationResponse):
The doc also clearly states that offer_amount in the response is The amount of the offer asset needed to get the ask amount.
Now, lets compare again with the implementation:
The bug is clear because its using query_simulation instead of query_reverse_simulation.
Also consider a multi-hop trade A -> B -> C where a user wants 100 C tokens:
It shoould actually be:
The contract already has a correct query_reverse_simulation function that handles proper price calculation for reverse operations, but its not being used.
jvr0x (MANTRA) disputed and commented:
3docSec (judge) commented:
