-
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
Introduce Component for Balance Overrides #3125
base: main
Are you sure you want to change the base?
Conversation
This PR is the first in a stack to add a system for overriding balances so that more quotes can be verified. One issue with the current system, is that it requires that the account creating the quote has the balance available to the account (or available to the account after a pre-hook is executed) in order for the quote to be properly verified. This isn't always possible for all flows (and notably flows at Safe, where transactions to prepare the balance happens at the same time as the `setPreSignature` transaction executes and after the quote). The overall solution I would propose (hopefully a pragmatic one that isn't TOO hacky) would be enable special handling for the most commonly traded tokens, by configuring for each token how the storage slot is computed for the token balance. This way, you could maintain a file that contains a `token => computation_strategy` map for the most popular tokens allowing trades to be verified even for quotes from users without the balance available. If this strategy is accepted, in a follow up PRs I would: 1. Add the component to the trade verifier and use it to fund the trader when simulating quotes 2. Pipe configuration to the trade verifier and balance overrides component
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
@MartinquaXD is on vacation and will be back mid next week to take a look |
This PR is a follow up to cowprotocol#3125 and uses the component introduced in the aforementioned PR for setting up a simulated token balance using state overrides in order for quote verification to work even when the trader does not have sufficient balance. The way it works is by configuring known mapping slots for the `mapping(address => uint256) balances` in ERC20 token contract implementations and using this to compute the slot for overriding the **solver's** token balance for the simulation. The solver can then use this balance to top up the trader's account if needed (in the case were we allow mocking preconditions in the simulation - currently this is determined by whether or not the quote has hooks). We intentionally do not override the trader's balance in order to not interfere with hook execution in verified quotes. Note that the type of the state override changed slightly. This is because it was wrong to begin with. Node implementations I tested with (Geth and Anvil) expect both the slot and the value for state overrides to be exactly 32-bytes long (so `H256`). I guess this feature of the state override in the `ethrpc` crate was not used in the past and therefore no one noticed 🤷. ### Test Plan Added an E2E test that uses the new token balance override feature in order to produce a verified quote for a trader with no balances. Note that commenting out the API arguments causes the test to fail as expected.
Note that I finished the follow up PR with a working E2E test 🎉. I created the PR to my fork (since I don't know how to create PR stacks when forking a repo). |
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
Description
This PR is the first in a stack to add a system for overriding balances so that more quotes can be verified.
One limitation with the current quote verification system, is that it requires that the
from
account in the quote has the sell token balance available (or available after a pre-hook is executed) in order for the quote to be properly verified. This isn't always possible for all flows (and notably flows at Safe, where transactions to prepare the balance happens at the same time as thesetPreSignature
transaction executes, so after the quote).The overall solution I would propose (hopefully a pragmatic one that isn't considered too hacky) would be enable special handling for the most commonly traded tokens, by configuring for each token how the storage slot is computed for the token balance. This way, you could maintain a file that contains a
token => computation_strategy
map for the most popular tokens allowing trades to be verified even for quotes from users without the balance available.This PR is the first piece for this overall solution, which introduces a component for computing storage slots needed for overriding balances for
eth_call
simulations. If this strategy is accepted, in a follow up PRs I would:Solver
simulation entrypoint, which would top up theTrader
balance if needed; this way the missing balance can be reported as part of the simulation and logged).Changes
BalanceOverriding
componentHow to test
Added unit tests verifying logic.