runtimeverification / runtimeverification/kontrol

Custom view shows another contract and uses the wrong PC in the kcfg viewer

Open
#141 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
122
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Issue

When launching the kcfg-viewer, the custom view is not very useful because it rarely shows the correct executed part of the Solidity source.
There are two reasons of that:

  • Only the testing contract is passed to the source map (1)
  • Source maps are indexed by instruction index, but are fetched by PC (2)
(1)

When calling the exec_foundry_view_kcfg function

https://github.com/runtimeverification/evm-semantics/blob/master/kevm-pyk/src/kevm_pyk/__main__.py#L630

We get the name of the testing contract

https://github.com/runtimeverification/evm-semantics/blob/master/kevm-pyk/src/kevm_pyk/__main__.py#L633

And only this one is passed to the source mapping structure

https://github.com/runtimeverification/evm-semantics/blob/master/kevm-pyk/src/kevm_pyk/__main__.py#L641-L642

Then if any external contract is called, we will not see the executed part in the source code

(2)

The instr_to_pc is correctly implemented but not used here

https://github.com/runtimeverification/evm-semantics/blob/master/kevm-pyk/src/kevm_pyk/solc_to_k.py#L296

Here

https://github.com/runtimeverification/evm-semantics/blob/master/kevm-pyk/src/kevm_pyk/solc_to_k.py#L324

We should probably rewrite it as:

_srcmap[instr_to_pc[i]] = (s, l, f, j, m)

Ideas

There is no way to know which contract is executed from the PC information only, because it may overlap (it starts at PC = 0 when executing a new contract).

Then when calling back _custom_view(), we may want to pass the contract name.

So a solution would be to allow writing the name of the contract that is currently executed in the K cell although not very desirable probably.

A better solution would be to write the bytecode of the contract that is currently executed in the node and we could fetch the contract, but if two contracts have the same bytecode then it may display the wrong one and may confuse the user.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace exec_foundry_view_kcfg in kevm-pyk/src/kevm_pyk/main.py and the source-map construction in kevm-pyk/src/kevm_pyk/solc_to_k.py, including instr_to_pc. Determine how _custom_view receives execution context, then define and test a way for the custom view to select the correct contract and source span for external calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, solidity
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.