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

Make settlement indexing compatible with smart contract solvers #3177

Open
MartinquaXD opened this issue Dec 20, 2024 · 0 comments
Open

Make settlement indexing compatible with smart contract solvers #3177

MartinquaXD opened this issue Dec 20, 2024 · 0 comments
Labels
track:maintenance maintenance track

Comments

@MartinquaXD
Copy link
Contributor

Background

The autopilot indexes transactions with Settlement events coming from the settlement contract. It decodes the call data for the call and extracts some relevant information from it.
This code splits the entire calldata of the tx into data (settle() call) and metadata (auction_id added at the end). The data later gets parsed here.

That logic only works if an EOA directly called settle(). If instead there was a smart contract solver (or some other helper contract for that matter) the calldata of the transaction would not contain the call to the settle() function but rather to some other contract. This is a completely different function call which would cause the current decoding logic to fail.

To accommodate these new use cases we'd have to make use of trace_call functionality. That way we could resimulate the entire transaction, step through the individual traces and find the trace for the actual settle() call (target address is settlement contract and function selector is 0x13d79a0b).

Details

The suggested course of action looks like this:

1. trace_call support

First of all we need a convenient way to resimulate a tx and get trace calls out of it. For that an extension trait could be implemented in the ethrpc crate. It would manage calling trace_call, serializing function arguments and deserializing the traces in the response.
To implement this you can orient yourself by the extension trait logic for multicalls.

Here is a raw example trace call to show how it can be constructed and what the result will look like:

example call
curl https://ovh.nodes.cow.fi/mainnet \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"trace_call","params":[{"from":"0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f","to":"0x9008D19f58AAbD9eD0D60971565AA8510560ab41","data":"0x13d79a0b0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000004000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000def1ca1fb7fbcdc777520aa7f396b4e015f497ab000000000000000000000000def1ca1fb7fbcdc777520aa7f396b4e015f497ab000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000001b08896e315d35ca027000000000000000000000000000000000000000000000000000000015899a830000000000000000000000000000000000000000000000000000000015899a8300000000000000000000000000000000000000000000001b1ae4d6e2ef50000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a6eb9349e3d73ec5b7a6b6e34cafc777ee80e30b0000000000000000000000000000000000000000000001b1ae4d6e2ef50000000000000000000000000000000000000000000000000000000000000151fdfd9300000000000000000000000000000000000000000000000000000000675bfcdaed295371d642bc2549c6d0562a8d9dbfde0717d7abf963443043cb57ba85a275000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000001b1ae4d6e2ef500000000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000014a6eb9349e3d73ec5b7a6b6e34cafc777ee80e30b000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000460000000000000000000000000de8c195aa41c11a0c4787372defbbddaa31306d200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002438e9922e00000000000000000000000000000000000000000000000000071afd498d000000000000000000000000000000000000000000000000000000000000000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001c452bbbe2900000000000000000000000000000000000000000000000000000000000000e00000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab41000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014815821514ae1da8000000000000000000000000000000000000000000000000000000000000000de8c195aa41c11a0c4787372defbbddaa31306d20002000000000000000001810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000def1ca1fb7fbcdc777520aa7f396b4e015f497ab000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000001b1ae4d6e2ef500000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de8c195aa41c11a0c4787372defbbddaa31306d200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002438e9922e000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000bbbbbbb520d69a9775e85b458c58c648259fad5f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002644dcebcba00000000000000000000000000000000000000000000000000000000675bf65b0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab4100000000000000000000000051c72848c68a965f66fa7a88855f9f7784502a7f000000000000000000000000000000000000000000000000000003264b40b134000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000014a548c0bbd645a8000000000000000000000000000000000000000000000000000000015983a8a00000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab4100000000000000000000000000000000000000000000000000000000000000002ced0f7ff5bc3ac2b19f9bce6f76d83c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004177165438c6b54c4fd5a48a27c2d58ec324a0cdbab708c72814d4dfb342af5b2e4c248885d7c36da5f1cc4b5d5db55e145214593de1e65729f202338d30d7e3eb1b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096690d"},["trace"], "0x1466c88"],"id":1,"jsonrpc":"2.0"}'
2. implement actual change

The next step is to use the new ability to simulate transactions with trace_call in the settlement event indexing logic.
After getting the simulation traces for a settlement tx you'd have to parse the correct gas_used, calldata and the solver that actually initiated the call.

To identify the actual settle() call find the trace where action.to == 0x9008d19f58aabd9ed0d60971565aa8510560ab41 and action.input.starts_with(0x13d79a0b).
For simplicity sake the initial implementation should assume that whatever address called settle() should be the solver address (instead of tx.from as it is right now).

3. e2e test

Ultimately this change should be tested by an e2e test. Examples can be found here. For the CI to correctly pick up the new test it should be flagged with #[ignore] and the name should start with local_node (to indicate that it should be run with anvil).
Here is how the CI will run the tests. To run the tests yourself you can run the same command locally. Just make sure to also run the necessary DB docker containers too (run docker compose up -d in the root directory).

The biggest hurdle will likely be setting up a smart contract solver for the e2e test. The problem is that this feature is not supported out of the box by the reference driver. So in order to test this you'll likely have to create a mock driver you can run in the e2e test. For inspiration take a lock at the existing mock solver.

Acceptance criteria

Ultimately the e2e test should assert that the data indexed in the DB is correct.

  • solver address is the smart contract instead of the EOA that initiated the transaction
  • settlement could be parsed because the calldata was extracted correctly from the simulation traces
@MartinquaXD MartinquaXD added the track:maintenance maintenance track label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
track:maintenance maintenance track
Projects
None yet
Development

No branches or pull requests

1 participant