Closed nlordell closed 1 month ago
It looks like the equation used by the naive solver may suffer from rounding errors, that cause an "off-by-one" in certain cases. This leads to failed settlements for tokens that don't have any buffer in the settlement contract:
The computed input and output amounts from the tenderly link from https://logs.gnosis.io/app/kibana#/discover/doc/63bc0b10-5f93-11e9-bf17-fbe383fc7c9c/logstash-2021.04.27?id=4kE6FXkBDHKb0ncgiERY (Apr 27, 2021 @ 23:27:02.000)
"input":{ "amountIn":"147240147441114393" "reserveIn":"490350406561504850302" "reserveOut":"334129741725736" } "output":{ "amountOut":"99999999999" }
In this log document, we see the batch call that does the getReserves call https://logs.gnosis.io/app/kibana#/discover/doc/63bc0b10-5f93-11e9-bf17-fbe383fc7c9c/logstash-2021.04.27?id=00E6FXkBDHKb0ncgiERY (Apr 27, 2021 @ 23:27:01.417):
getReserves
{"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0x0902f1ac","to":"0x3d2d3c4446e8a82445418523b9b5b376765e55a8"},"latest"],"id":56931}
Matching it to the response from the log https://logs.gnosis.io/app/kibana#/discover/doc/63bc0b10-5f93-11e9-bf17-fbe383fc7c9c/logstash-2021.04.27?id=1EE6FXkBDHKb0ncgiERY (Apr 27, 2021 @ 23:27:01.519):
[id:56931]: "0x00000000000000000000000000000000000000000000000000012fe3a490802800000000000000000000000000000000000000000000001a94fa98c7a6de717e000000000000000000000000000000000000000000000000000000006088814b"
ABI decoding this:
> const ethers = require("ethers"); > ethers.utils.defaultAbiCoder.decode(["uint112","uint112","uint96"], "0x00000000000000000000000000000000000000000000000000012fe3a490802800000000000000000000000000000000000000000000001a94fa98c7a6de717e000000000000000000000000000000000000000000000000000000006088814b").map(x => x.toString()) [ '334129741725736', '490350406561504850302', '1619558731' ]
So, in this particular simulation, we see that the naive solver and the actual computed swap amounts differ despite having the same reserve values.
Original issue https://github.com/gnosis/gp-v2-services/issues/524 by @nlordell
This issue has been marked as stale because it has been inactive a while. Please update this issue or it will be automatically closed.
It looks like the equation used by the naive solver may suffer from rounding errors, that cause an "off-by-one" in certain cases. This leads to failed settlements for tokens that don't have any buffer in the settlement contract:
The computed input and output amounts from the tenderly link from https://logs.gnosis.io/app/kibana#/discover/doc/63bc0b10-5f93-11e9-bf17-fbe383fc7c9c/logstash-2021.04.27?id=4kE6FXkBDHKb0ncgiERY (Apr 27, 2021 @ 23:27:02.000)
In this log document, we see the batch call that does the
getReserves
call https://logs.gnosis.io/app/kibana#/discover/doc/63bc0b10-5f93-11e9-bf17-fbe383fc7c9c/logstash-2021.04.27?id=00E6FXkBDHKb0ncgiERY (Apr 27, 2021 @ 23:27:01.417):Matching it to the response from the log https://logs.gnosis.io/app/kibana#/discover/doc/63bc0b10-5f93-11e9-bf17-fbe383fc7c9c/logstash-2021.04.27?id=1EE6FXkBDHKb0ncgiERY (Apr 27, 2021 @ 23:27:01.519):
ABI decoding this:
So, in this particular simulation, we see that the naive solver and the actual computed swap amounts differ despite having the same reserve values.