Skip to content

Commit a27baba

Browse files
committed
CSE: assume cheatcodes' expected calldepth is less than the current one
1 parent 2310dd7 commit a27baba

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/kontrol/kdist/cheatcodes.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,21 +581,25 @@ WThe `#checkRevert` will be used to compare the status code of the execution and
581581
<callDepth> CD </callDepth>
582582
<wordStack> _ : _ : _ : _ : _ : RETSTART : RETWIDTH : _WS </wordStack>
583583
<expectedRevert>
584-
<isRevertExpected> true </isRevertExpected>
585-
<expectedDepth> CD </expectedDepth>
584+
<isRevertExpected> ISREVERTEXPECTED_CELL </isRevertExpected>
585+
<expectedDepth> EXPECTEDDEPTH_CELL </expectedDepth>
586586
...
587587
</expectedRevert>
588+
requires ISREVERTEXPECTED_CELL
589+
andBool EXPECTEDDEPTH_CELL==Int CD
588590
[priority(32)]
589591
590592
rule [foundry.set.expectrevert.2]:
591593
<k> #next [ _OP:CallSixOp ] ~> (.K => #checkRevert ~> #updateRevertOutput RETSTART RETWIDTH) ~> #execute ... </k>
592594
<callDepth> CD </callDepth>
593595
<wordStack> _ : _ : _ : _ : RETSTART : RETWIDTH : _WS </wordStack>
594596
<expectedRevert>
595-
<isRevertExpected> true </isRevertExpected>
596-
<expectedDepth> CD </expectedDepth>
597+
<isRevertExpected> ISREVERTEXPECTED_CELL </isRevertExpected>
598+
<expectedDepth> EXPECTEDDEPTH_CELL </expectedDepth>
597599
...
598600
</expectedRevert>
601+
requires ISREVERTEXPECTED_CELL
602+
andBool EXPECTEDDEPTH_CELL==Int CD
599603
[priority(32)]
600604
601605
rule [foundry.set.expectrevert.3]:
@@ -763,14 +767,16 @@ The last point is required in order to prevent overwriting the caller for subcal
763767
<wordStack> _ : ACCTTO : _WS </wordStack>
764768
<id> ACCT </id>
765769
<prank>
766-
<active> true </active>
770+
<active> ACTIVE_CELL </active>
767771
<newCaller> NCL </newCaller>
768-
<depth> CD </depth>
772+
<depth> ACTIVECALLDEPTH_CELL </depth>
769773
...
770774
</prank>
771775
requires ACCT =/=K NCL
772776
andBool ACCTTO =/=K #address(FoundryCheat)
773777
andBool (OP ==K CALL orBool OP ==K CALLCODE orBool OP ==K STATICCALL orBool OP ==K CREATE orBool OP ==K CREATE2)
778+
andBool ACTIVE_CELL
779+
andBool ACTIVECALLDEPTH_CELL ==Int CD
774780
[priority(34)]
775781
```
776782

src/kontrol/prove.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def _init_cterm(
950950
'TRACEDATA_CELL': KApply('.List'),
951951
}
952952

953-
storage_constraints: list[KApply] = []
953+
cse_constraints: list[KApply] = []
954954

955955
if config_type == ConfigType.TEST_CONFIG or active_simbolik:
956956
init_account_list = (
@@ -991,7 +991,7 @@ def _init_cterm(
991991
accounts.append(Foundry.symbolic_account(contract_account_name, contract_code))
992992
else:
993993
# Symbolic accounts of all relevant contracts
994-
accounts, storage_constraints = _create_cse_accounts(
994+
accounts, cse_constraints = _create_cse_accounts(
995995
foundry, storage_fields, contract_account_name, contract_code
996996
)
997997

@@ -1006,6 +1006,23 @@ def _init_cterm(
10061006
if not isinstance(method, Contract.Constructor) and not (method.view or method.pure):
10071007
init_subst['STATIC_CELL'] = FALSE
10081008

1009+
# Summarization applies to external calls, at least one level deeper than the test call where an `expectRevert` or `prank` is expected
1010+
expectrevert_depth_constraint = mlEqualsTrue(
1011+
KApply(
1012+
'_>Int_',
1013+
[KVariable('CALLDEPTH_CELL', sort=KSort('Int')), KVariable('EXPECTEDDEPTH_CELL', sort=KSort('Int'))],
1014+
)
1015+
)
1016+
prank_depth_constraint = mlEqualsTrue(
1017+
KApply(
1018+
'_>Int_', [KVariable('CALLDEPTH_CELL', sort=KSort('Int')), KVariable('DEPTH_CELL', sort=KSort('Int'))]
1019+
)
1020+
)
1021+
cse_constraints += [
1022+
expectrevert_depth_constraint,
1023+
prank_depth_constraint,
1024+
]
1025+
10091026
if calldata is not None:
10101027
init_subst['CALLDATA_CELL'] = calldata
10111028

@@ -1030,7 +1047,7 @@ def _init_cterm(
10301047
if preconditions is not None:
10311048
for precondition in preconditions:
10321049
init_cterm = init_cterm.add_constraint(mlEqualsTrue(precondition))
1033-
for constraint in storage_constraints:
1050+
for constraint in cse_constraints:
10341051
init_cterm = init_cterm.add_constraint(constraint)
10351052

10361053
non_cheatcode_contract_ids = []

0 commit comments

Comments
 (0)