Skip to content

Conversation

@tamaralipows
Copy link
Contributor

@tamaralipows tamaralipows commented Sep 12, 2025

Main points:

  • Override executor code.
  • Override router (since we may want to simulate before it was deployed). Causing problem because of PUSH0 opcode.
  • Override storage slots containing approved executors. Slot calculation is thoroughly tested!
  • Override balances and approvals with BalanceSlotDetector and AllowanceSlotDetector
  • Simulates using debug_traceCall and prints traces if vm_traces is set to true.
  • The tracing logic is heavily clauded 😅 I ended up using foundry to get the method selectors but there are a few scam selectors there 🫠
  • Added a comparison between the executed amount out and the simulated amount out. If the difference is higher than 5% then the test fails

I am running the old-fashioned way using: cargo run -- --package ethereum-balancer-v2

TODO (not all necessarily in this PR):

  • I think we should just use an executor address that is already approved and mock the executor code to our current executor instead of checking if the current one is approved as well.
  • I just ran this only for test_weighted_pool_v4 and for the case of the biggest amount in, the swap fails - I dunno why yet.
  • Get tycho router bytecode at compile time.
  • Use tycho-common and tycho-client from simulation
  • Add skip_execution flag

Questions:

  • Should we add another flag to show the execution traces? I just reused the vm_traces but it's not really the same thing. And most likely the user will only want to see one or the other

Example logs:

2025-09-22T13:33:04.568550Z  INFO Encoded swap successfully
2025-09-22T13:33:04.568628Z  INFO Simulating swap at historical block 20128806
2025-09-22T13:33:04.569607Z  INFO Gas pricing: base_fee=7825138405, max_priority_fee_per_gas=2000000000, max_fee_per_gas=17650276810
2025-09-22T13:33:06.816760Z  INFO Starting balance slot detection for 1 tokens
2025-09-22T13:33:07.109528Z  INFO Balance slot detection completed. Found results for 1 tokens
2025-09-22T13:33:07.110282Z  INFO Starting allowance slot detection for 1 tokens
2025-09-22T13:33:07.410029Z  INFO Allowance slot detection completed. Found results for 1 tokens
Traces:
[178664] 0xfd0b31d2e955fa55e3fa641fe90e08b677188d35::0x5c4b639c (unknown)
  └─ ← [Return] 0x00000000000000000000000000000000000000000000000000c2682026631bb9
  ├─ [2655] 0x514910771af9ca656af840dff83e8264ecf986ca::balanceOf(address)
    └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000000
  ├─ [137561] 0xb5b8dc3f0a1be99685a0ded015af93bfbb55c411::swap(uint256,bytes)
    └─ ← [Return] 0x00000000000000000000000000000000000000000000000000c2682026631bb9
    ├─ [29498] 0x38c2a4a7330b22788374b8ff70bba513c8d848ca::transferFrom(address,address,uint256)
      └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001
    ├─ [24628] 0x38c2a4a7330b22788374b8ff70bba513c8d848ca::approve(address,uint256)
      └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001
    ├─ [74763] 0xba12222222228d8ba445958a75a0704d566bf2c8::0x52bbbe29 (unknown)
      └─ ← [Return] 0x00000000000000000000000000000000000000000000000000c2682026631bb9
      ├─ [8393] 0xe96a45f66bdda121b24f0a861372a72e8889523d::onSwap(tuple,uint256,uint256)
        └─ ← [Return] 0x00000000000000000000000000000000000000000000000000c2682026631bb9
      ├─ [8398] 0x38c2a4a7330b22788374b8ff70bba513c8d848ca::transferFrom(address,address,uint256)
        └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001
      ├─ [28445] 0x514910771af9ca656af840dff83e8264ecf986ca::transfer(address,uint256)
        └─ ← [Return] 0x0000000000000000000000000000000000000000000000000000000000000001
  ├─ [655] 0x514910771af9ca656af840dff83e8264ecf986ca::balanceOf(address)
    └─ ← [Return] 0x00000000000000000000000000000000000000000000000000c2682026631bb9
2025-09-22T13:33:07.712175Z  INFO Transaction successfully executed.
2025-09-22T13:33:07.712199Z  INFO Gas used: 178664
2025-09-22T13:33:07.712339Z  INFO Simulating execution passed with 3000000000000000000 TRUF -> 54720632774138809 LINK

@tamaralipows tamaralipows force-pushed the testing-sdk/tnl/ENG-4831-execute branch 2 times, most recently from ae5f009 to 2dce6e7 Compare September 12, 2025 23:59
@tamaralipows tamaralipows force-pushed the testing-sdk/tnl/ENG-4831-execute branch from 2dce6e7 to d967dcf Compare September 13, 2025 00:02
Copy link
Contributor

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

uau thank you @tamaralipows 🙏🏼 what a hard task!! I only did a general review and left some comments mostly for my understanding! When you start we can meet about this and run it together!

@dianacarvalho1 dianacarvalho1 force-pushed the testing-sdk/tnl/ENG-4831-execute branch from 71ab610 to a7f3234 Compare September 18, 2025 10:13
# Conflicts:
#	protocol-testing/Cargo.lock
#	protocol-testing/Cargo.toml
#	protocol-testing/entrypoint.sh
#	protocol-testing/src/encoding.rs
#	protocol-testing/src/test_runner.rs

#time 5h 45m
Decoded amount out from execution and compared with the one from simulation
Allow for printing the execution traces
Moved all execution methods into execution.rs
Created traces.rs (heavily clauded) that prints the traces nicely and gets the function selectors frm 4byte (I decided not to use EtherscanIdentifier from foundry because adding foundry as a dependency is really heavy and I expect problems because of it)

Temporary: hardcoded storage slots for test_weighted_pool_v4 to pass

#time 1h 55m
@dianacarvalho1 dianacarvalho1 changed the title feat: (WIP) Simulate txs against RPC feat: Simulate txs against RPC Sep 18, 2025
@dianacarvalho1 dianacarvalho1 marked this pull request as ready for review September 18, 2025 16:41
Copy link
Contributor Author

@tamaralipows tamaralipows left a comment

Choose a reason for hiding this comment

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

Thank you for all of this! I'm happy with this!

Regarding your comments:

I think we should just use an executor address that is already approved and mock the executor code to our current executor instead of checking if the current one is approved as well.

Isn't this more difficult and slightly disorganized, requiring us to overwrite the executor address in the execution repo? Not sure how you would do this in a clean way

I just ran this only for test_weighted_pool_v4 and for the case of the biggest amount in, the swap fails - I dunno why yet.

Oh please no not this issue again lol. I can help you debug this tomorrow

Should we add another flag to show the execution traces? I just reused the vm_traces but it's not really the same thing. And most likely the user will only want to see one or the other

I don't fully understand why the user would want to see vm_traces that are not execution related, without seeing the execution traces? Maybe we can just call this "traces"?

@dianacarvalho1
Copy link
Contributor

Thank you for the review @tamaralipows 🙏🏼 to answer your comments:

I think we should just use an executor address that is already approved and mock the executor code to our current executor instead of checking if the current one is approved as well.

Isn't this more difficult and slightly disorganized, requiring us to overwrite the executor address in the execution repo? Not sure how you would do this in a clean way

But then we rely on the executor being actually deployed on chain no? 🤔 and the integrators would like to run this test way before that 😬

Should we add another flag to show the execution traces? I just reused the vm_traces but it's not really the same thing. And most likely the user will only want to see one or the other

I don't fully understand why the user would want to see vm_traces that are not execution related, without seeing the execution traces? Maybe we can just call this "traces"?

Ah, originally the vm_traces flag was for the tycho-simulation traces (for get amount out and company)!

Also get tycho router bytecode at compile time

#time 22m
@tamaralipows
Copy link
Contributor Author

tamaralipows commented Sep 19, 2025

But then we rely on the executor being actually deployed on chain no? 🤔 and the integrators would like to run this test way before that 😬

@dianacarvalho1 No, why do you say that? I have added code to overwrite the executor code and also the executor approval on the tycho router 🤔

@dianacarvalho1 dianacarvalho1 force-pushed the testing-sdk/tnl/ENG-4831-execute branch from f1f6f86 to 9c3ee07 Compare September 22, 2025 12:12
Improved the format of the printed trace as well

#time 1h 7m
Copy link
Contributor

@adrianbenavides adrianbenavides left a comment

Choose a reason for hiding this comment

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

Craaazy piece of work! I did a superficial pass and I left some minor comments/questions. I want to do another pass tomorrow for my own good, but feel free to merge it when you see fit.

# Conflicts:
#	protocol-testing/src/test_runner.rs

#time 7m
Copy link
Contributor Author

@tamaralipows tamaralipows left a comment

Choose a reason for hiding this comment

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

Thank you! I can't approve because it's my PR but it all looks good, I only have really minor comments!

.join(",")
);

// Filter out scam/honeypot signatures
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whats a honeypot signature? I know you didn't just add this now but I'm curious now hahaha

Copy link
Contributor

Choose a reason for hiding this comment

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

"A honeypot is a trap designed to attract and catch someone or something, originally referring to using honey to catch bears or other animals."

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 know the term but I mean practically what does that mean in this context and why are we filtering it out xD don't we want to know if we are being scammed

Add trying to decode method's calldatas in tracing

#time 1m
# Conflicts:
#	protocol-testing/src/test_runner.rs

#time 2m
@dianacarvalho1 dianacarvalho1 merged commit eaca474 into main Sep 23, 2025
7 checks passed
@dianacarvalho1 dianacarvalho1 deleted the testing-sdk/tnl/ENG-4831-execute branch September 23, 2025 14:57
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.

4 participants