Skip to content

Commit 2abe4ef

Browse files
committed
from #594: compute jumpdests using the Python custom_step
1 parent 9317415 commit 2abe4ef

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/kontrol/prove.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from subprocess import CalledProcessError
88
from typing import TYPE_CHECKING, Any, ContextManager, NamedTuple
99

10-
from kevm_pyk.kevm import KEVM, KEVMSemantics
10+
from kevm_pyk.kevm import KEVM, KEVMSemantics, _process_jumpdests
1111
from kevm_pyk.utils import KDefinition__expand_macros, abstract_cell_vars, run_prover
1212
from pathos.pools import ProcessPool # type: ignore
1313
from pyk.cterm import CTerm, CTermSymbolic
@@ -16,7 +16,7 @@
1616
from pyk.kcfg import KCFG, KCFGExplore
1717
from pyk.kore.rpc import KoreClient, TransportType, kore_server
1818
from pyk.prelude.bytes import bytesToken
19-
from pyk.prelude.collections import list_empty, map_empty, map_of, set_empty
19+
from pyk.prelude.collections import list_empty, map_empty, map_of, set_empty, set_of
2020
from pyk.prelude.k import GENERATED_TOP_CELL
2121
from pyk.prelude.kbool import FALSE, TRUE, notBool
2222
from pyk.prelude.kint import intToken
@@ -556,9 +556,9 @@ def _method_to_cfg(
556556
calldata = None
557557
callvalue = None
558558

559-
contract_code = KEVM.bin_runtime(KApply(f'contract_{contract.name_with_path}'))
559+
contract_code = bytes.fromhex(contract.deployed_bytecode)
560560
if isinstance(method, Contract.Constructor):
561-
program = KEVM.init_bytecode(KApply(f'contract_{contract.name_with_path}'))
561+
program = bytes.fromhex(contract.bytecode)
562562
callvalue = method.callvalue_cell
563563

564564
elif isinstance(method, Contract.Method):
@@ -569,7 +569,7 @@ def _method_to_cfg(
569569
init_cterm = _init_cterm(
570570
empty_config,
571571
program=program,
572-
contract_code=contract_code,
572+
contract_code=bytesToken(contract_code),
573573
use_gas=use_gas,
574574
deployment_state_entries=deployment_state_entries,
575575
calldata=calldata,
@@ -609,7 +609,7 @@ def _method_to_cfg(
609609
)
610610

611611
for final_node in final_states:
612-
new_init_cterm = _update_cterm_from_node(init_cterm, final_node, contract.name_with_path, config_type)
612+
new_init_cterm = _update_cterm_from_node(init_cterm, final_node, config_type)
613613
new_node = cfg.create_node(new_init_cterm)
614614
if graft_setup_proof:
615615
cfg.create_edge(final_node.id, new_node.id, depth=1)
@@ -626,7 +626,7 @@ def _method_to_cfg(
626626

627627
final_cterm = _final_cterm(
628628
empty_config,
629-
program=contract_code,
629+
program=bytesToken(contract_code),
630630
failing=method.is_testfail,
631631
config_type=config_type,
632632
is_test=method.is_test,
@@ -637,7 +637,7 @@ def _method_to_cfg(
637637
return cfg, new_node_ids, init_node_id, target_node.id
638638

639639

640-
def _update_cterm_from_node(cterm: CTerm, node: KCFG.Node, contract_name: str, config_type: ConfigType) -> CTerm:
640+
def _update_cterm_from_node(cterm: CTerm, node: KCFG.Node, config_type: ConfigType) -> CTerm:
641641
new_accounts_cell = node.cterm.cell('ACCOUNTS_CELL')
642642
number_cell = node.cterm.cell('NUMBER_CELL')
643643
timestamp_cell = node.cterm.cell('TIMESTAMP_CELL')
@@ -760,7 +760,7 @@ def _init_account(address: int) -> None:
760760

761761
def _init_cterm(
762762
empty_config: KInner,
763-
program: KInner,
763+
program: bytes,
764764
contract_code: KInner,
765765
use_gas: bool,
766766
config_type: ConfigType,
@@ -777,13 +777,14 @@ def _init_cterm(
777777
if not trace_options:
778778
trace_options = TraceOptions({})
779779

780+
jumpdests = set_of(_process_jumpdests(bytecode=program, offset=0))
780781
init_subst = {
781782
'MODE_CELL': KApply('NORMAL'),
782783
'USEGAS_CELL': TRUE if use_gas else FALSE,
783784
'SCHEDULE_CELL': schedule,
784785
'STATUSCODE_CELL': KVariable('STATUSCODE'),
785-
'PROGRAM_CELL': program,
786-
'JUMPDESTS_CELL': KEVM.compute_valid_jumpdests(program),
786+
'PROGRAM_CELL': bytesToken(program),
787+
'JUMPDESTS_CELL': jumpdests,
787788
'ID_CELL': KVariable(Foundry.symbolic_contract_id(), sort=KSort('Int')),
788789
'ORIGIN_CELL': KVariable('ORIGIN_ID', sort=KSort('Int')),
789790
'CALLER_CELL': KVariable('CALLER_ID', sort=KSort('Int')),

src/kontrol/solc_to_k.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ def method_sentences(self) -> list[KSentence]:
962962

963963
@property
964964
def sentences(self) -> list[KSentence]:
965-
return [self.subsort, self.production, self.macro_bin_runtime, self.macro_init_bytecode] + self.method_sentences
965+
return [self.subsort, self.production] + self.method_sentences
966966

967967
@property
968968
def method_by_name(self) -> dict[str, Contract.Method]:

0 commit comments

Comments
 (0)