Skip to content
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

Cheatcodes with ability to control generated K variable names #745

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8114b61
Add freshUInt variant that allows specifying generated var name
nwatson22 Aug 5, 2024
09c5194
Use superclass method in KontrolSemantics
nwatson22 Aug 5, 2024
ccddb49
Add selectors for other cheatcodes
nwatson22 Aug 6, 2024
a5fa764
Implement for symbolicStorage
nwatson22 Aug 6, 2024
3aa332d
Use newer kontrol-cheatcodes version, add rules for the new cheatcodes
nwatson22 Aug 6, 2024
61ff183
Add rest of cheatcodes (symbolicBytes not working yet)
nwatson22 Aug 7, 2024
9b1cc25
Merge branch 'master' into noah/custom-varnames-cheatcodes
PetarMax Aug 7, 2024
7c0d580
Allow custom var name cheatcode symbolic length in freshBytes and sym…
nwatson22 Aug 8, 2024
c903ed9
Merge branch 'master' into noah/custom-varnames-cheatcodes
nwatson22 Aug 8, 2024
3b49799
Enable some new tests
nwatson22 Aug 10, 2024
a3a1d83
Merge master into branch
nwatson22 Aug 14, 2024
f343982
Fix test
nwatson22 Aug 14, 2024
990854e
Merge branch 'master' into noah/custom-varnames-cheatcodes
nwatson22 Aug 14, 2024
32a2167
Update expected output
nwatson22 Aug 14, 2024
f06b827
Fix freshBool
nwatson22 Aug 16, 2024
839635b
Fix test disambiguation, update symbolic_bytes_custom_name expected
nwatson22 Aug 16, 2024
d441d58
Merge branch 'master' into noah/custom-varnames-cheatcodes
nwatson22 Aug 16, 2024
8b0cecf
Update expected output
nwatson22 Aug 16, 2024
087efad
Merge branch 'noah/custom-varnames-cheatcodes' of https://github.com/…
nwatson22 Aug 16, 2024
7e3604c
Update test_address_custom_name
nwatson22 Aug 16, 2024
eb05bab
Merge branch 'master' into noah/custom-varnames-cheatcodes
nwatson22 Aug 16, 2024
38496da
Update src/kontrol/solc_to_k.py
nwatson22 Aug 16, 2024
5ae8000
Merge branch 'master' into noah/custom-varnames-cheatcodes
nwatson22 Aug 19, 2024
eecdc05
Update src/tests/integration/conftest.py
nwatson22 Aug 19, 2024
aec4226
Fix indentation issue
nwatson22 Aug 19, 2024
09a3cfb
Merge branch 'master' into noah/custom-varnames-cheatcodes
PetarMax Aug 25, 2024
b8f1500
can_make_custom_step
PetarMax Aug 25, 2024
2e00656
expected outputs, custom step activation
PetarMax Aug 25, 2024
83f4683
more expected outputs
PetarMax Aug 25, 2024
6aa33c6
and even more expected outputs
PetarMax Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion src/kontrol/kdist/cheatcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ This rule then takes from the function call data the account using `#asWord(#ran

```
function symbolicStorage(address) external;
function symbolicStorage(address, string calldata) external;
```

`cheatcode.call.symbolicStorage` will match when the `symbolicStorage` cheat code function is called.
Expand All @@ -337,6 +338,24 @@ This rule then takes the address using `#asWord(#range(ARGS, 0, 32))` and makes
rule [cheatcode.call.symbolicStorage]:
<k> #cheatcode_call SELECTOR ARGS => #loadAccount #asWord(ARGS) ~> #setSymbolicStorage #asWord(ARGS) ... </k>
requires SELECTOR ==Int selector ( "symbolicStorage(address)" )

rule [cheatcode.call.symbolicStorageCustomVar]:
<k> #cheatcode_call SELECTOR ARGS => #loadAccount #asWord(ARGS) ~> #setSymbolicStorageCustomVar #asWord(#range(ARGS, 0, 32)) ARGS ... </k>
requires SELECTOR ==Int selector ( "symbolicStorage(address,string)" )
```

```k
syntax KItem ::= "#setSymbolicStorageCustomVar" Int Bytes [symbol(foundry_setSymbolicStorageCustomVar)]
```

```{.k .symbolic}
rule [cheatcode.set.symbolicStorageCustomVar]: <k> #setSymbolicStorageCustomVar ACCTID ARGS => .K ... </k>
<account>
<acctID> ACCTID </acctID>
<storage> _ => ?STORAGE </storage>
<origStorage> _ => ?STORAGE </origStorage>
...
</account>
```

#### `copyStorage` - Copies the storage of one account into another.
Expand All @@ -361,6 +380,7 @@ This rule then takes the two addresses using `#asWord(#range(ARGS, 0, 32))` and

```
function freshUInt(uint8) external returns (uint256);
function freshUInt(uint8, string calldata) external returns (uint256);
```

`cheatcode.call.freshUInt` will match when the `freshUInt` cheat code function is called.
Expand All @@ -374,12 +394,21 @@ This rule returns a symbolic integer of up to the bit width that was sent as an
andBool 0 <Int #asWord(ARGS) andBool #asWord(ARGS) <=Int 32
ensures 0 <=Int ?WORD andBool ?WORD <Int 2 ^Int (8 *Int #asWord(ARGS))
[preserves-definedness]

rule [cheatcode.call.freshUIntCustomVar]:
<k> #cheatcode_call SELECTOR ARGS => .K ... </k>
<output> _ => #buf(32, ?WORD) </output>
requires SELECTOR ==Int selector ( "freshUInt(uint8,string)" )
andBool 0 <Int #asWord(#range(ARGS, 0, 32)) andBool #asWord(#range(ARGS, 0, 32)) <=Int 32
ensures 0 <=Int ?WORD andBool ?WORD <Int 2 ^Int (8 *Int #asWord(#range(ARGS, 0, 32)))
[preserves-definedness]
```

#### `freshBool` - Returns a single symbolic boolean.

```
function freshBool() external returns (bool);
function freshBool(string calldata) external returns (uint256);
```

`cheatcode.call.freshBool` will match when the `freshBool` cheat code function is called.
Expand All @@ -392,12 +421,20 @@ This rule returns a symbolic boolean value being either 0 (false) or 1 (true).
requires SELECTOR ==Int selector ( "freshBool()" )
ensures #rangeBool(?WORD)
[preserves-definedness]

rule [cheatcode.call.freshBoolCustomVar]:
<k> #cheatcode_call SELECTOR _ => .K ... </k>
<output> _ => #buf(32, ?WORD) </output>
requires SELECTOR ==Int selector ( "freshBool(string)" )
ensures #rangeBool(?WORD)
[preserves-definedness]
```

#### `freshBytes` - Returns a fully symbolic byte array value of the given length.

```
function freshBytes(uint256) external returns (bytes memory);
function freshBytes(uint256, string calldata) external returns (bytes memory);
```

`cheatcode.call.freshBytes` will match when the `freshBytes` cheat code function is called.
Expand All @@ -413,12 +450,23 @@ This rule returns a fully symbolic byte array value of the given length.
requires SELECTOR ==Int selector ( "freshBytes(uint256)" )
ensures lengthBytes(?BYTES) ==Int #asWord(ARGS)
[preserves-definedness]

rule [cheatcode.call.freshBytesCustomVar]:
<k> #cheatcode_call SELECTOR ARGS => .K ... </k>
<output> _ =>
#buf(32, 32) +Bytes #buf(32, #asWord(#range(ARGS, 0, 32))) +Bytes ?BYTES
+Bytes #buf ( ( ( notMaxUInt5 &Int ( #asWord(#range(ARGS, 0, 32)) +Int maxUInt5 ) ) -Int #asWord(#range(ARGS, 0, 32)) ) , 0 )
</output>
requires SELECTOR ==Int selector ( "freshBytes(uint256,string)" )
ensures lengthBytes(?BYTES) ==Int #asWord(#range(ARGS, 0, 32))
[preserves-definedness]
```

#### `freshAddress` - Returns a single symbolic address.

```
function freshAddress() external returns (address);
function freshAddress(string calldata) external returns (address);
```

`foundry.call.freshAddress` will match when the `freshAddress` cheat code function is called.
Expand All @@ -431,6 +479,13 @@ This rule returns a symbolic address value.
requires SELECTOR ==Int selector ( "freshAddress()" )
ensures #rangeAddress(?WORD) andBool ?WORD =/=Int #address(FoundryTest) andBool ?WORD =/=Int #address(FoundryCheat)
[preserves-definedness]

rule [foundry.call.freshAddressCustomVar]:
<k> #cheatcode_call SELECTOR _ => .K ... </k>
<output> _ => #buf(32, ?WORD) </output>
requires SELECTOR ==Int selector ( "freshAddress(string)" )
ensures #rangeAddress(?WORD) andBool ?WORD =/=Int #address(FoundryTest) andBool ?WORD =/=Int #address(FoundryCheat)
[preserves-definedness]
```

Expecting the next call to revert
Expand Down Expand Up @@ -1125,7 +1180,7 @@ Utils
```

```{.k .symbolic}
rule <k> #setSymbolicStorage ACCTID => .K ... </k>
rule [cheatcode.set.symbolicStorage]: <k> #setSymbolicStorage ACCTID => .K ... </k>
<account>
<acctID> ACCTID </acctID>
<storage> _ => ?STORAGE </storage>
Expand Down Expand Up @@ -1585,10 +1640,15 @@ If the flag is false, it skips comparison, assuming success; otherwise, it compa
rule ( selector ( "expectEmit(bool,bool,bool,bool,address)" ) => 2176505587 )
rule ( selector ( "sign(uint256,bytes32)" ) => 3812747940 )
rule ( selector ( "symbolicStorage(address)" ) => 769677742 )
rule ( selector ( "symbolicStorage(address,string)" ) => 745143816 )
rule ( selector ( "freshUInt(uint8)" ) => 625253732 )
rule ( selector ( "freshUInt(uint8,string)" ) => 1530912521 )
rule ( selector ( "freshBool()" ) => 2935720297 )
rule ( selector ( "freshBool(string)" ) => 525694724 )
rule ( selector ( "freshBytes(uint256)" ) => 1389402351 )
rule ( selector ( "freshBytes(uint256,string)" ) => 390682600 )
rule ( selector ( "freshAddress()" ) => 2363359817 )
rule ( selector ( "freshAddress(string)" ) => 1202084987 )
rule ( selector ( "prank(address)" ) => 3395723175 )
rule ( selector ( "prank(address,address)" ) => 1206193358 )
rule ( selector ( "allowCallsToAddress(address)" ) => 1850795572 )
Expand Down
Loading
Loading