Skip to content

Commit 367ce72

Browse files
anvacarurv-auditor
andauthored
Add helper methods for KAst terms (#2433)
* kevm.py: add helper methods for KAst terms * Set Version: 1.0.561 --------- Co-authored-by: devops <[email protected]>
1 parent 7b8e3b0 commit 367ce72

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

kevm-pyk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "kevm-pyk"
7-
version = "1.0.560"
7+
version = "1.0.561"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

kevm-pyk/src/kevm_pyk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
if TYPE_CHECKING:
66
from typing import Final
77

8-
VERSION: Final = '1.0.560'
8+
VERSION: Final = '1.0.561'

kevm-pyk/src/kevm_pyk/kevm.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from pyk.ktool.kprove import KProve
2525
from pyk.ktool.krun import KRun
2626
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
2829
from pyk.prelude.ml import mlEqualsFalse, mlEqualsTrue
2930
from pyk.prelude.string import stringToken
3031
from pyk.proof.reachability import APRProof
@@ -98,7 +99,7 @@ def same_loop(self, cterm1: CTerm, cterm2: CTerm) -> bool:
9899
return False
99100
# duplicate from KEVM.extract_branches
100101
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())
102103
branch_pattern = KSequence([jumpi_pattern, pc_next_pattern, KEVM.sharp_execute(), KVariable('###CONTINUATION')])
103104
subst1 = branch_pattern.match(cterm1.cell('K_CELL'))
104105
subst2 = branch_pattern.match(cterm2.cell('K_CELL'))
@@ -112,15 +113,15 @@ def same_loop(self, cterm1: CTerm, cterm2: CTerm) -> bool:
112113
def extract_branches(self, cterm: CTerm) -> list[KInner]:
113114
k_cell = cterm.cell('K_CELL')
114115
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())
116117
branch_pattern = KSequence([jumpi_pattern, pc_next_pattern, KEVM.sharp_execute(), KVariable('###CONTINUATION')])
117118
if subst := branch_pattern.match(k_cell):
118119
cond = subst['###COND']
119120
if cond_subst := KEVM.bool_2_word(KVariable('###BOOL_2_WORD')).match(cond):
120121
cond = cond_subst['###BOOL_2_WORD']
121122
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))]
124125
return []
125126

126127
def abstract_node(self, cterm: CTerm) -> CTerm:
@@ -385,6 +386,10 @@ def jumpi_applied(pc: KInner, cond: KInner) -> KApply:
385386
def jump_applied(pc: KInner) -> KApply:
386387
return KApply('___EVM_InternalOp_UnStackOp_Int', [KEVM.jump(), pc])
387388

389+
@staticmethod
390+
def pc_applied(op: KInner) -> KApply:
391+
return KApply('#pc[_]_EVM_InternalOp_OpCode', [op])
392+
388393
@staticmethod
389394
def pow128() -> KApply:
390395
return KApply('pow128_WORD_Int', [])
@@ -518,6 +523,10 @@ def account_cell(
518523
],
519524
)
520525

526+
@staticmethod
527+
def wordstack_empty() -> KApply:
528+
return KApply('.WordStack_EVM-TYPES_WordStack')
529+
521530
@staticmethod
522531
def wordstack_len(wordstack: KInner) -> int:
523532
return len(flatten_label('_:__EVM-TYPES_WordStack_Int_WordStack', wordstack))
@@ -530,6 +539,10 @@ def parse_bytestack(s: KInner) -> KApply:
530539
def bytes_empty() -> KApply:
531540
return KApply('.Bytes_BYTES-HOOKED_Bytes')
532541

542+
@staticmethod
543+
def buf(width: int, v: KInner) -> KApply:
544+
return KApply('#buf(_,_)_BUF-SYNTAX_Bytes_Int_Int', [intToken(width), v])
545+
533546
@staticmethod
534547
def intlist(ints: list[KInner]) -> KApply:
535548
res = KApply('.List{"___HASHED-LOCATIONS_IntList_Int_IntList"}_IntList')

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.560
1+
1.0.561

0 commit comments

Comments
 (0)