Skip to content

CFG visualization and progress saving #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Nov 11, 2022
Merged

Conversation

ehildenb
Copy link
Member

@ehildenb ehildenb commented Nov 3, 2022

This PR is the simpler components pull out of #1443.

In particular, it has:

This brings in a decent amount of functionality needed for making progress incremental on Foundry proofs:

  • Adds KEVM.add_invariant, and makes sure that the initial LHS states used for proofs are in the language invariant.
  • The kevm foundry-prove command will now save the final counterexample state in the CFG on disk, so progress can be resumed from there.
  • Adds kevm foundry-show OUT_DIR Contract.Test for displaying current CFG. Has options:
    • --[no-]minimize: minimize the configuration output.
    • --node NODE_ID: also display the selected node's configuration and constraints (respects --[no-]minimize, repetition allowed).
    • --node-delta NODE_ID_1,NODE_ID_2: display the configuration delta between the given nodes (respects --[no-]minimie, repetition allowed).
  • Adds kevm foundry-list OUT_DIR for listing the current CFGs, and their progress towards being proved. Has options:
    • --[no-]details: show the details about progress to being proved for each CFG, instead of just their passed/failed state.

If you do something ilke kevm foundry-prove --depth 100 ..., the proof will fail at depth 100, and that state will be saved in the KCFG. Then you can continue progress from there with kevm foundry-prove ... again, and it will start from the 100th state the next time (you can add the --lemma argument the second call, for example). You can add the --reinit option to foundry-prove to start the proof over.

@ehildenb ehildenb marked this pull request as ready for review November 4, 2022 02:05
@ehildenb
Copy link
Member Author

ehildenb commented Nov 4, 2022

@lucasmt and @qian-hu if you could test that the new functionality (list, show, and proof resuming) are working as expected, taht would be good.

qian-hu
qian-hu previously requested changes Nov 4, 2022
Copy link
Contributor

@qian-hu qian-hu left a comment

Choose a reason for hiding this comment

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

Proof resuming doesn't work well in my cases. When I run kevm foundry-prove the second time without adding --reinit, I'm getting a parsing error. The new claim file includes several unexpected _. But otherwise okay.

@qian-hu qian-hu self-requested a review November 4, 2022 19:43
@anvacaru anvacaru requested a review from tothtamas28 November 4, 2022 20:13
@ehildenb
Copy link
Member Author

ehildenb commented Nov 5, 2022

@qian-hu if everything else is working you should not press "Request Changes", because then I need to actually take some action to address your changes. See our GitHub Guidelines. As it is, you haven't actually given me anything actionable to do, I need to see the state that is not working for parsing, and ideally to see the entire input you are trying to run.

Also, it's a known issue that it cannot handle proof resuming from inside calls. I will be able to fix that too, but it will take me a couple weeks, it's not as straightforward as it sounds.

@lucasmt
Copy link
Contributor

lucasmt commented Nov 5, 2022

I've pushed a commit adding parenthesis when printing the up/Int operator, since it was causing a parser error when running kevm foundry-prove. Some constraints written to spec.k for the test I was trying to run contained expressions of the form #sizeByteArray(X) up/Int 32 *Int 32, and the parser considers them ambiguous without parentheses.

@lucasmt
Copy link
Contributor

lucasmt commented Nov 5, 2022

Now I am also getting the same error that @qian-hu mentioned when I try to run kevm foundry-prove the second time. For me the error looks like this:

[Error] Inner Parser: Parse error: unexpected token '_EXITCODE_CELL' following
token '_'.
	Source(/home/lucasmt/lsp-smart-contracts-verification/out/specs/erc725ytest-testsetdata1-spec.k)
	Location(40,19,40,33)
	40 |	               ( __EXITCODE_CELL => ?_EXIT_CODE_CELL_c89e25d9 )
	   .	                  ^~~~~~~~~~~~~~

It looks like there is an extra underscore being added to the variable names.

@qian-hu qian-hu dismissed their stale review November 5, 2022 19:41

Everything else is working.

@qian-hu
Copy link
Contributor

qian-hu commented Nov 5, 2022

@ehildenb I see. Here is an example of the inputs and the error state. I do Kevm foundry-prove OUT_DIR --test Contract.Test --depth 100 --verbose after kevm foundry-kompile OUT_DIR --verbose, then run kevm foundry-prove OUT_DIR --test Contract.Test --verbose with/without --lemma argument. And I get a rewritten claim containing the following:

         <k>
           #halt
           ~> ( __CONTINUATION => ?_CONTINUATION )
         </k>
         <exit-code>
           ( __EXITCODE_CELL => ?_EXIT_CODE_CELL_c89e25d9 )
         </exit-code>
             <interimStates>
               ( __INTERIMSTATES_CELL => ?_INTERIMSTATES_CELL_c89e25d9 )
             </interimStates>
             <touchedAccounts>
               ( __TOUCHEDACCOUNTS_CELL => ?_TOUCHEDACCOUNTS_CELL_c89e25d9
             </touchedAccounts>

There are some unexpected token '_'. And the error is the same as @lucasmt provided.

New commit and everything else LGTM.

Comment on lines +411 to +417
definition_dir = foundry_out / 'kompiled'
use_directory = foundry_out / 'specs'
use_directory.mkdir(parents=True, exist_ok=True)
kcfgs_dir = foundry_out / 'kcfgs'
foundry = Foundry(definition_dir, profile=profile, use_directory=use_directory)
kcfg_file = kcfgs_dir / f'{test}.json'
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting definition_dir, use_dir, kcfg_dir, kcfg_file as functions of a new module config.py, e.g.

def kcfg_file(out_dir: Path, test_name: str) -> Path:
    return kcfg_dir(out_dir) / f'{test_name}.json'

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean as helpers so we're not re-computing them over and again? Maybe they could be fields in the KEVM class so they're jsut set at function init?

Copy link
Member Author

Choose a reason for hiding this comment

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

I took a quick look at this, and seems like more trouble than it's worth at the moment. Will consider it in my local tree, see if I can find a solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

You mean as helpers so we're not re-computing them over and again

Re-computing the values is fine. The point is to have a single definition of these expressions so that e.g. the folder layout can be easily reconfigured.

@@ -49,3 +103,35 @@ def abstract_cell_vars(cterm: KInner, keep_vars: Collection[KVariable] = ()) ->
if type(subst[s]) is KVariable and not is_anon_var(subst[s]) and subst[s] not in keep_vars:
subst[s] = abstract_term_safely(KVariable('_'), base_name=s)
return substitute(config, subst)


def sanitize_config(defn: KDefinition, init_term: KInner) -> KInner:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create an issue to mark that there is duplicated functionality between kevm_pyk and ksummarize that eventually should be factored out.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this duplicated functionality will be long-lived. Plan to remove calls to sanitize_config once we have execute endpoint working (in my local branch, but not pushed up yet).

@ehildenb ehildenb force-pushed the save-progress-visualize branch from 3aa4504 to ed00d8e Compare November 7, 2022 20:04
@ehildenb
Copy link
Member Author

ehildenb commented Nov 7, 2022

@qian-hu thanks for the more detail. I've added a test that this does not happen, and fixed this bug you found in the state saving.

@ehildenb ehildenb force-pushed the save-progress-visualize branch from 77cf27f to b3349b0 Compare November 9, 2022 01:54
@ehildenb ehildenb force-pushed the save-progress-visualize branch from 908997a to 32978ab Compare November 9, 2022 20:46
@ehildenb ehildenb force-pushed the save-progress-visualize branch from 32978ab to 5a54cd5 Compare November 9, 2022 21:36
@ehildenb ehildenb self-assigned this Nov 11, 2022
@rv-jenkins rv-jenkins merged commit 9abc842 into master Nov 11, 2022
@rv-jenkins rv-jenkins deleted the save-progress-visualize branch November 11, 2022 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants