runtimeverification / runtimeverification/evm-semantics

Implement vm.record cheat code

Open
#1,787 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
KCL
Stars
591
Forks
156
Avg merge
2h 19m
Merged PRs (30d)
1

Description

When testing an ercx test with the kevm foundry integration, the proof ended because it reached an unimplemented cheat code vm.record. The documentation for record can be found here.

As a suggestion, you can try this implementation:

  1. extending the configuration in foundry.md to add these cells:
        <recordAccess>
          <recordActive> false </recordActive>
           <records>
             <record multiplicity="*" type="Map">
               <recordKey> 0 </recordKey>
               <reads> .List </reads>
               <writes> .List </writes>
             </record>
           </records>
        </recordAccess>
  1. add a #call_foundry rule that intercepts the call of the cheat code
   rule [foundry.call.record]:
        <k> #call_foundry SELECTOR _ => #enableRecord ... </k>
     requires SELECTOR ==Int selector ( "record()" )

Here, #enableRecord will start recording the storage operations.

    rule <k> #enableRecord => . ... </k>
         <recordAccess>
            <recordActive> _ => true </recordActive>
            ...
         </recordAccess>
  1. overwrite rules for SLOAD and SSTORE to write in the records cells while recordActive is true.
   rule [foundry.recordSLOAD]:
        <k> SLOAD INDEX => #recordRead INDEX ~> #pauseRecord ~> SLOAD INDEX ~> #resumeRecord ... </k>
        <recordAccess> <recordActive> true </recordActive> ... </recordAccess>
     [priority(39)]

   rule [foundry.recordSSTORE]:
        <k> SSTORE INDEX NEW => #recordRead INDEX ~> #recordWrite INDEX ~> #pauseRecord ~> SSTORE INDEX NEW ~> #resumeRecord ... </k>
        <recordAccess> <recordActive> true </recordActive> ... </recordAccess>
     [priority(39)]

Here, #pauseRecord and #unpauseRecord could be used to allow the original SLOAD/SSTORE rules from evm.md to be executed by disabling/reenabling the recording.

    rule <k> #resumeRecord => . ... </k>
         <recordAccess> <recordActive> _ => true </recordActive> ... </recordAccess>

    rule <k> #pauseRecord => . ... </k>
         <recordAccess> <recordActive> _ => false </recordActive> ... </recordAccess>

And #recordRead and #recordWrite can record the operations.

    rule <k> #recordRead V => . </k>
         <id> KEY </id>
         <recordAccess>
           <record>
             <recordKey> KEY </recordKey>
             <reads> R => R ListItem(#buf(32, V)) </reads>
             ...
           </record>
           ...
         </recordAccess>

    rule <k> #recordRead V => . </k>
         <id> KEY </id>
         <recordAccess>
            <records>
               ( .Bag
               => <record>
                   <recordKey> KEY </recordKey>
                   <reads> ListItem(#buf(32, V)) </reads>
                   ...
                 </record>
               )
            </records>
            ...
         </recordAccess> [owise]

    rule <k> #recordWrite V => . </k>
         <id> KEY </id>
         <recordAccess>
           <record>
             <recordKey> KEY </recordKey>
             <writes> R => R ListItem(#buf(32, V)) </writes>
             ...
           </record>
           ...
         </recordAccess>

This cheat code goes hand in hand with vm.accesses, so probably this needs to be implemented as well.

Contributor guide

No contributing guide indexed for this repository

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

Start with foundry.md and the existing EVM rules in evm.md, then compare the linked Foundry documentation for vm.record and vm.accesses. Implement the record state, cheat-code interception, and SLOAD/SSTORE recording described in the issue; done means the ercx Foundry integration no longer stops at vm.record and the related access data is captured.

Written by the indexing model from the issue text.

Assessment

Domain
blockchain
Issue type
Feature
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.