reilabs / starknet-replay

CLI tool to replay Starknet transactions and profile libfuncs usage.
0 stars 0 forks source link

Identify how to get the `pc` vector from transaction execution #4

Closed Eagle941 closed 5 months ago

Eagle941 commented 5 months ago

This issue concerns how to extract the Trace list object from inside the transaction execution in blockifier crate for consumption by the profiler object. The Trace list contains the series of pcs for each execution step in the virtual machine. Use pathfinder node.

Eagle941 commented 5 months ago

It should be possible to use the CachedState object because it has the field visited_pcs.

Eagle941 commented 5 months ago

Using CachedState is not possible because the visited_pcs is contained in a HashSet instead of a slice, therefore insertion order isn't guaranteed

Eagle941 commented 5 months ago

Converting visited_pcs to Vec ensures order. Running test suite on pathfinder and blockifier doesn't lead to any failure. This makes visited_pcs of type HashMap<ClassHash, Vec<usize>> where usize is the value of pc from TraceEntry.

The problem of this method is that when a contract is invoked, other contracts can be invoked. This implies that if the same contract is called multiple times in a transaction, the list of pcs is extended in the HashMap losing track of the pcs for each entry point call.

The new type of visited_pcs is HashMap<ClassHash, Vec<Vec<usize>>>.