24
24
from pyk .ktool .kprove import KProve
25
25
from pyk .ktool .krun import KRun
26
26
from pyk .prelude .bytes import BYTES , pretty_bytes
27
- from pyk .prelude .kint import INT , intToken , ltInt
27
+ from pyk .prelude .kbool import notBool
28
+ from pyk .prelude .kint import INT , eqInt , intToken , ltInt
28
29
from pyk .prelude .ml import mlEqualsFalse , mlEqualsTrue
29
30
from pyk .prelude .string import stringToken
30
31
from pyk .proof .reachability import APRProof
@@ -98,7 +99,7 @@ def same_loop(self, cterm1: CTerm, cterm2: CTerm) -> bool:
98
99
return False
99
100
# duplicate from KEVM.extract_branches
100
101
jumpi_pattern = KEVM .jumpi_applied (KVariable ('###PCOUNT' ), KVariable ('###COND' ))
101
- pc_next_pattern = KApply ( '#pc[_]_EVM_InternalOp_OpCode' , [ KEVM .jumpi ()] )
102
+ pc_next_pattern = KEVM . pc_applied ( KEVM .jumpi ())
102
103
branch_pattern = KSequence ([jumpi_pattern , pc_next_pattern , KEVM .sharp_execute (), KVariable ('###CONTINUATION' )])
103
104
subst1 = branch_pattern .match (cterm1 .cell ('K_CELL' ))
104
105
subst2 = branch_pattern .match (cterm2 .cell ('K_CELL' ))
@@ -112,15 +113,15 @@ def same_loop(self, cterm1: CTerm, cterm2: CTerm) -> bool:
112
113
def extract_branches (self , cterm : CTerm ) -> list [KInner ]:
113
114
k_cell = cterm .cell ('K_CELL' )
114
115
jumpi_pattern = KEVM .jumpi_applied (KVariable ('###PCOUNT' ), KVariable ('###COND' ))
115
- pc_next_pattern = KApply ( '#pc[_]_EVM_InternalOp_OpCode' , [ KEVM .jumpi ()] )
116
+ pc_next_pattern = KEVM . pc_applied ( KEVM .jumpi ())
116
117
branch_pattern = KSequence ([jumpi_pattern , pc_next_pattern , KEVM .sharp_execute (), KVariable ('###CONTINUATION' )])
117
118
if subst := branch_pattern .match (k_cell ):
118
119
cond = subst ['###COND' ]
119
120
if cond_subst := KEVM .bool_2_word (KVariable ('###BOOL_2_WORD' )).match (cond ):
120
121
cond = cond_subst ['###BOOL_2_WORD' ]
121
122
else :
122
- cond = KApply ( '_==Int_' , [ cond , intToken (0 )] )
123
- return [mlEqualsTrue (cond ), mlEqualsTrue (KApply ( 'notBool_' , [ cond ] ))]
123
+ cond = eqInt ( cond , intToken (0 ))
124
+ return [mlEqualsTrue (cond ), mlEqualsTrue (notBool ( cond ))]
124
125
return []
125
126
126
127
def abstract_node (self , cterm : CTerm ) -> CTerm :
@@ -385,6 +386,10 @@ def jumpi_applied(pc: KInner, cond: KInner) -> KApply:
385
386
def jump_applied (pc : KInner ) -> KApply :
386
387
return KApply ('___EVM_InternalOp_UnStackOp_Int' , [KEVM .jump (), pc ])
387
388
389
+ @staticmethod
390
+ def pc_applied (op : KInner ) -> KApply :
391
+ return KApply ('#pc[_]_EVM_InternalOp_OpCode' , [op ])
392
+
388
393
@staticmethod
389
394
def pow128 () -> KApply :
390
395
return KApply ('pow128_WORD_Int' , [])
@@ -518,6 +523,10 @@ def account_cell(
518
523
],
519
524
)
520
525
526
+ @staticmethod
527
+ def wordstack_empty () -> KApply :
528
+ return KApply ('.WordStack_EVM-TYPES_WordStack' )
529
+
521
530
@staticmethod
522
531
def wordstack_len (wordstack : KInner ) -> int :
523
532
return len (flatten_label ('_:__EVM-TYPES_WordStack_Int_WordStack' , wordstack ))
@@ -530,6 +539,10 @@ def parse_bytestack(s: KInner) -> KApply:
530
539
def bytes_empty () -> KApply :
531
540
return KApply ('.Bytes_BYTES-HOOKED_Bytes' )
532
541
542
+ @staticmethod
543
+ def buf (width : int , v : KInner ) -> KApply :
544
+ return KApply ('#buf(_,_)_BUF-SYNTAX_Bytes_Int_Int' , [intToken (width ), v ])
545
+
533
546
@staticmethod
534
547
def intlist (ints : list [KInner ]) -> KApply :
535
548
res = KApply ('.List{"___HASHED-LOCATIONS_IntList_Int_IntList"}_IntList' )
0 commit comments