matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment
Apache License 2.0
299 stars 130 forks source link

Investigate zkEVM traces not being on the right place of the call stack #644

Open Jrigada opened 2 weeks ago

Jrigada commented 2 weeks ago

I have this simple example (just deploying a Counter contract and calling increment()) where the traces of my call are not congruent with the actual call stack that should happen. If I look at the result traces from the contract call, I see a single trace that's a call to the account code storage to get the system context code hash:

type Call(Normal)
from 0x0000…8001
to 0x0000…8002
input:
4de2e468000000000000000000000000000000000000000000000000000000000000800b // (getRawCodeHash(0x0...800b))
ouput:
010001b3f2c3a6bdd5ad00ae29a7cbbb32dca3c31fb608b5cd52f8f3056a3847

I mapped this happening inside this call https://github.com/matter-labs/era-contracts/blob/bce4b2d0f34bd87f1aaadd291772935afb1c3bd6/system-contracts/bootloader/bootloader.yul#L4021 from the bootloader. now that trace has lots of subcalls (which makes no sense as getRawCodeHash is a cast + an sload) and those subcalls belong to the rest of the execution (for example the validateTransaction and executeTransaction made from the bootloader to the sender are made there)