-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relax trade verification checks for pre-interactions #3081
Conversation
// Warm the storage for sending ETH to smart contract addresses. | ||
// We allow this call to revert becaues it was either unnecessary in the first place | ||
// or failing to send `ETH` to the `receiver` will cause a revert in the settlement | ||
// contract. | ||
receiver.call{value: 0}(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it moved here just as a part of refactoring, or is it essential for the changes to work correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having to warm the storage for sending ETH to a smart contract wallet is a very annoying implementation detail the user shouldn't have to worry about. This part should always happen and should not lead to reverts for any reasonable smart contract receiver.
And since the prepareSwap()
step is now optional depending on the existence of pre-interactions I moved it out of there. Also the context of this doesn't matter (i.e. whether the trader or the solver sends it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Can't think of any pitfalls.
Description
Currently the trade verification does a few checks and actions on behalf of the user that requested the quote to make the verification possible.
For example if a user has ETH and no WETH but requests a quote for WETH we'd try wrap the necessary WETH before doing the fake settlement in the simulation.
We also do a check before the settlement to verify that the user has the required sell token balance. That way we can return a more helpful error message than when the settlement contract reverts due to the missing funds.
Both of these things could fail if the user provides pre-hooks that will only set up the necessary trade pre-conditions for the
from
address.Changes
Adjusted the simulation code such that we can control whether some reasonable pre-conditions will be set up as part of the simulation or not.
If a user provides pre-conditions we now assume that they are necessary to set things up and we don't do our set up to not interfere with that.
How to test
Added an e2e test that transfers the needed sell tokens from a safe to the trader address in a pre-hook. This test fails without the change introduced in this PR.
Edit: The test works locally but appears to cause issues in CI for whatever reason. :/
Edit2: It's actually an existing test that fails exactly because of the reason described 👇
While working on the test I learned about a niche edge case that currently can't be verified: If you try to get a quote for a
from
address that is a contract that will only be deployed in the pre-interaction.The reason is that before we do the simulation we check whether the
from
address is a contract. If it is a contract we use some state override magic to make our fake user during the simulation behave like the contract that was deployed at that address. But we can't know that thefrom
address will contain contract code if the contract will only be deployed in the pre-interaction.