Skip to content
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

driver: get access list for balance calculation #3300

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

m-lord-renkse
Copy link
Contributor

Description

From the task:
This order was filled sub-optimally in 2 partial fills.
It contains a pre-hook that claims rewards to provide the full sell token balance to the owner. The driver already computes the available balances for an order based on the outcome of the pre-hooks (if there are any). But in this case the balance simulation didn't show that the owner would get all the necessary sell tokens from the hook so it reported the available balance to be whatever the owner currently has without the hook.
A solver picked up this order and executed it. In the actual settlement the hook got executed and unlocked the remaining sell tokens which led to another partial fill that then fulfilled the order completely.

When simulating the hook on its own it exceeds its gas limit and therefor reverts. This explains why no balance change happens in the simulation. However, in the actual settlement the balance change happened.
When comparing the hook simulation with the onchain settlement simulation it became apparent that executing the hook as part of the actual settlement was a lot cheaper.

The reason seems to be that the storage loads are a lot cheaper in the real settlement. That is likely caused by the fact that we use access lists for the real solution but not during the balance simulation.

Changes

  • Get the access list before simulating the balance

How to test

  1. Regression tests

Related Issues

Fixes #3252

@m-lord-renkse m-lord-renkse marked this pull request as ready for review February 28, 2025 14:19
@m-lord-renkse m-lord-renkse requested a review from a team as a code owner February 28, 2025 14:19
Copy link
Contributor

@mstrug mstrug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to run simulation with access lists in Tenderly to compare the gas usage?

@@ -70,6 +74,26 @@ struct Inner {
current_block: CurrentBlockWatcher,
}

pub struct Tx {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced we need this intermediary type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have this type, then from the tx builder we would need to unwrap before calling the function just so in the function it is done a: Some(a). I am open to suggestions!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like unwrapping would be the better choice than introducing more identically named types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end, unwrapping is not an option because it is not the same to be None and to be the default value. I left this struct, but I am open to other solution like creating a new function for creating access list for the balance call.

@squadgazzz
Copy link
Contributor

If this is still WIP, please convert it to draft.

@m-lord-renkse
Copy link
Contributor Author

If this is still WIP, please convert it to draft.

technically it is not WIP, I received comments which need to be reworked 🤔 but the more eyes and reviews I get the better.

Copy link
Contributor

@squadgazzz squadgazzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assuming there is a plan for ensuring the change works properly.

@@ -70,6 +74,26 @@ struct Inner {
current_block: CurrentBlockWatcher,
}

pub struct Tx {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like unwrapping would be the better choice than introducing more identically named types.

method.tx.data.clone().unwrap(),
);
// Create the access list for the balance simulation
let access_list_tx = Tx {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it and it returns Some(AccessList {...})

let access_list_tx = Tx {
from: access_list_call.from.unwrap_or_default(),
to: access_list_call.to,
value: Some(0.into()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being None (which seems to be always None) or 0 does not affect the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: driver does not use access lists when simulating pre-hooks while computing balances
4 participants