Skip to content

Conversation

@kayibal
Copy link
Collaborator

@kayibal kayibal commented Nov 17, 2025

Move away from depending on foundry for traces. Instead implement trace functionality within tycho-simulation using only publicly available crates.

Traces with etherscan api key look like this now:

Transaction successfully executed.
Gas used: 49151
Traces:
[0] 0xA2C5C98A892fD6656a7F39A2f63228C0Bc846270::0x8307c655(4626d81b3a1711beb79f4cecff2413886d4616770002000000000000000000110000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000ba100000625a3754423978a60c9317c58a424e3d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a7640000) [gas: 281345] ✓
  → 00000000000000000000000000000000000000000000000001e97e3a109c52830000000000000000000000000000000000000000000000000000000000020e9800000000000000000000000000000000000000000000000001e6989ff6d9bcda0000000000000000000000000000000000000000000000000de0b6b3a7640000
  [1] Dai[0x6B175474E89094C44Da98b954EedeAC495271d0F]::transferFrom(0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, 0xA2C5C98A892fD6656a7F39A2f63228C0Bc846270, 1000000000000000000) [gas: 61930] ✓
    → true
  [1] Dai[0x6B175474E89094C44Da98b954EedeAC495271d0F]::allowance(0xA2C5C98A892fD6656a7F39A2f63228C0Bc846270, 0xBA12222222228d8Ba445958a75a0704d566BF2C8) [gas: 3727] ✓
    → 0
    [2] 0x0000000000000000000000000000000000000000::allowance(0xA2C5C98A892fD6656a7F39A2f63228C0Bc846270, 0xBA12222222228d8Ba445958a75a0704d566BF2C8) [gas: 0] ✓
  [1] Dai[0x6B175474E89094C44Da98b954EedeAC495271d0F]::approve(0xBA12222222228d8Ba445958a75a0704d566BF2C8, 1000000000000000000) [gas: 44827] ✓
    → true
  [1] Vault[0xBA12222222228d8Ba445958a75a0704d566BF2C8]::swap(SingleSwap(0x4626d81b3a1711beb79f4cecff2413886d461677000200000000000000000011, 0, 0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xba100000625a3754423978a60c9317c58a424e3D, 1000000000000000000, []), FundManagement(0xA2C5C98A892fD6656a7F39A2f63228C0Bc846270, false, 0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, false), 0, 1000) [gas: 130789] ✓
    → 137780051463393923
    [2] WeightedPool2Tokens[0x4626d81b3a1711bEb79f4CEcFf2413886d461677]::onSwap(SwapRequest(0, 0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xba100000625a3754423978a60c9317c58a424e3D, 1000000000000000000, 0x4626d81b3a1711beb79f4cecff2413886d461677000200000000000000000011, 17031877, 0xA2C5C98A892fD6656a7F39A2f63228C0Bc846270, 0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, []), 334264980844547876118, 46658028802299958283) [gas: 28046] ✓
      → 137780051463393923
    [2] Dai[0x6B175474E89094C44Da98b954EedeAC495271d0F]::transferFrom(0xA2C5C98A892fD6656a7F39A2f63228C0Bc846270, 0xBA12222222228d8Ba445958a75a0704d566BF2C8, 1000000000000000000) [gas: 11260] ✓
      → true
    [2] BalancerGovernanceToken[0xba100000625a3754423978a60c9317c58a424e3D]::transfer(0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, 137780051463393923) [gas: 57346] ✓
      → true
  [1] Vault[0xBA12222222228d8Ba445958a75a0704d566BF2C8]::queryBatchSwap(0, [BatchSwapStep(0x4626d81b3a1711beb79f4cecff2413886d461677000200000000000000000011, 0, 1, 1000000000000000000, [])], [0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xba100000625a3754423978a60c9317c58a424e3D], FundManagement(0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, false, 0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, false)) [gas: 25711] ✓
    → [1000000000000000000, -136964651490065626]
    [2] Vault[0xBA12222222228d8Ba445958a75a0704d566BF2C8]::queryBatchSwap(0, [BatchSwapStep(0x4626d81b3a1711beb79f4cecff2413886d461677000200000000000000000011, 0, 1, 1000000000000000000, [])], [0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xba100000625a3754423978a60c9317c58a424e3D], FundManagement(0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, false, 0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, false)) [gas: 22322] ✗
      → fa61cc1200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000de0b6b3a7640000fffffffffffffffffffffffffffffffffffffffffffffffffe19676009264326
      [3] WeightedPool2Tokens[0x4626d81b3a1711bEb79f4CEcFf2413886d461677]::onSwap(SwapRequest(0, 0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xba100000625a3754423978a60c9317c58a424e3D, 1000000000000000000, 0x4626d81b3a1711beb79f4cecff2413886d461677000200000000000000000011, 18485417, 0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, 0xf847a638E44186F3287ee9F8cAF73FF4d4B80784, []), 335264980844547876118, 46520248750836564360) [gas: 8424] ✓
        → 136964651490065626

Move away from depending on foundry for traces. Instead implement trace functionality within tycho-simulation using only publicly available crates.
Remove the now unused decode_internal parameter and adjust call sites.
@kayibal kayibal force-pushed the ah/remove-foundry-deps branch from 126c61e to d55e269 Compare November 17, 2025 12:23
@kayibal
Copy link
Collaborator Author

kayibal commented Nov 17, 2025

Some test are currently failing due to this: foundry-rs/foundry#2696

This got lost in a previous update since it is now feature gated in revm.
Copy link
Collaborator

@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.

Thank you @kayibal ! This is amazing 🙏🏼 Only have small comments!

.map_err(|err| SimulationEngineError::TraceError(err.to_string()))
handle_traces(
trace_res,
env::var("ETHERSCAN_API_KEY").ok(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to mention this in the docs!

// Query 4byte.directory
let hex_selector = format!("0x{}", hex::encode(selector.as_slice()));
let url = format!(
"https://www.4byte.directory/api/v1/signatures/?hex_signature={}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've played with this before and got a loooot of weird values 😕 like sub2juniononyoutube and honeypot for very common selectors. Did you stumble on this too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm weird because foundry doesn't do anything fancy here so it should be pretty much the same logic...

Comment on lines +26 to +27
/// Handle traces with Etherscan identification and pretty printing
/// This is the main public function used by SimulationEngine
Copy link
Collaborator

Choose a reason for hiding this comment

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

and 4byte signature identification

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Tycho Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants