Skip to content

Commit 82c51a7

Browse files
committed
Enhance summary specification file generation for balance opcode
- Add function to replace LHS function with assignment in summary-balance specs - Modify account ID representation in balance summary files - Update regex transformation to simplify account ID constraints
1 parent 9c1fc90 commit 82c51a7

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/summaries/summary-balance-normal-1-spec.k

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ imports BUF
3939
<network>
4040
<accounts>
4141
<account>
42-
<acctID>
43-
ACCTID
44-
</acctID>
42+
<acctID> ACCTID_CELL_CELL </acctID>
4543
<balance>
4644
BALANCE_CELL:Int
4745
</balance>
@@ -54,8 +52,8 @@ imports BUF
5452
</ethereum>
5553
...
5654
</kevm>
57-
requires ACCTID ==Int W0:Int modInt pow160
5855

59-
[priority(20), label(BASIC-BLOCK-1-TO-3)]
56+
requires ACCTID_CELL_CELL ==Int W0:Int modInt pow160
57+
[priority(20), label(BASIC-BLOCK-1-TO-3)]
6058

6159
endmodule

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/summaries/summary-balance-owise-1-spec.k

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ imports BUF
3939
<network>
4040
<accounts>
4141
<account>
42-
<acctID>
43-
( W0:Int modInt pow160 )
44-
</acctID>
42+
<acctID> ACCTID_CELL_CELL </acctID>
4543
<balance>
4644
BALANCE_CELL:Int
4745
</balance>
@@ -55,6 +53,7 @@ imports BUF
5553
...
5654
</kevm>
5755

58-
[priority(20), label(BASIC-BLOCK-1-TO-3)]
56+
requires ACCTID_CELL_CELL ==Int W0:Int modInt pow160
57+
[priority(20), label(BASIC-BLOCK-1-TO-3)]
5958

6059
endmodule

kevm-pyk/src/kevm_pyk/summarizer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,18 @@ def _use_legal_remainder(res_line: str) -> str:
608608
res_line_tmp = re.sub(r'(\()\s*andBool\s*([\s\S]*?)\s*(\))', r'\1\2\3', res_line_tmp)
609609
res_line_tmp = re.sub(r'andBool\s*\(\s*\)', r'', res_line_tmp)
610610
return res_line_tmp
611+
612+
def replace_lhs_function_by_assignment(res_line: str) -> str:
613+
# just for summary-balance
614+
if not 'SUMMARY-BALANCE' in res_line:
615+
return res_line
616+
pattern = r'<acctID>\s*(\(\s*W0:Int modInt pow160\s*\))\s*</acctID>'
617+
if re.search(pattern, res_line):
618+
# 找到这个pattern的位置
619+
replace_pattern = r'<acctID> ACCTID_CELL_CELL </acctID>'
620+
res_line = re.sub(pattern, replace_pattern, res_line)
621+
res_line = re.sub(r'(</kevm>\s*)', r'\1requires ACCTID_CELL_CELL ==Int W0:Int modInt pow160\n', res_line)
622+
return res_line
611623

612624
spec_name = f'summary-{proof.id.replace("_", "-").lower()}.k'
613625
with open(self.save_directory / spec_name, 'w') as f:
@@ -617,6 +629,7 @@ def _use_legal_remainder(res_line: str) -> str:
617629
res_line = _remove_inf_gas(res_line)
618630
res_line = _remove_dash_from_var(res_line)
619631
res_line = _use_legal_remainder(res_line)
632+
res_line = replace_lhs_function_by_assignment(res_line)
620633
f.write('requires "../evm.md"\n')
621634
f.write('requires "../buf.md"\n\n')
622635
lines = res_line.split('\n')

0 commit comments

Comments
 (0)