Skip to content

Commit 7f8ee84

Browse files
anvacaruPetar Maksimovicrv-auditorPetarMax
authored
Disable gas computations in Kontrol (#252)
* add suport for kevm nogas * hardcode use-gas for profiling * test * Set Version: 0.1.100 * Set Version: 0.1.101 * set kevm version tag * remove space * set use_gas to false by default * Revert "hardcode use-gas for profiling" This reverts commit 0ba7b82. * Set Version: 0.1.103 * remove duplicated substitution * update expected output * use gas for GasTests * Set Version: 0.1.104 * set init gas cells to 0 * update expected output for callData and refund cells --------- Co-authored-by: Petar Maksimovic <[email protected]> Co-authored-by: devops <[email protected]> Co-authored-by: Petar Maksimović <[email protected]>
1 parent 81217f8 commit 7f8ee84

17 files changed

+768
-574
lines changed

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.103
1+
0.1.104

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 = "kontrol"
7-
version = "0.1.103"
7+
version = "0.1.104"
88
description = "Foundry integration for KEVM"
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/kontrol/__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 = '0.1.103'
8+
VERSION: Final = '0.1.104'

src/kontrol/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def exec_prove(
229229
fail_fast: bool = False,
230230
port: int | None = None,
231231
maude_port: int | None = None,
232+
use_gas: bool = False,
232233
**kwargs: Any,
233234
) -> None:
234235
_ignore_arg(kwargs, 'main_module', f'--main-module: {kwargs["main_module"]}')
@@ -258,6 +259,7 @@ def exec_prove(
258259
max_iterations=max_iterations,
259260
run_constructor=run_constructor,
260261
fail_fast=fail_fast,
262+
use_gas=use_gas,
261263
)
262264

263265
rpc_options = RPCOptions(
@@ -724,6 +726,9 @@ def _parse_test_version_tuple(value: str) -> tuple[str, int | None]:
724726
action='store_true',
725727
help='Include the contract constructor in the test execution.',
726728
)
729+
prove_args.add_argument(
730+
'--use-gas', dest='use_gas', default=False, action='store_true', help='Enables gas computation in KEVM.'
731+
)
727732

728733
show_args = command_parser.add_parser(
729734
'show',

src/kontrol/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ProveOptions:
2424
run_constructor: bool
2525
fail_fast: bool
2626
reinit: bool
27+
use_gas: bool
2728

2829
def __init__(
2930
self,
@@ -41,6 +42,7 @@ def __init__(
4142
run_constructor: bool = False,
4243
fail_fast: bool = True,
4344
reinit: bool = False,
45+
use_gas: bool = False,
4446
) -> None:
4547
object.__setattr__(self, 'auto_abstract_gas', auto_abstract_gas)
4648
object.__setattr__(self, 'bug_report', bug_report)
@@ -55,6 +57,7 @@ def __init__(
5557
object.__setattr__(self, 'run_constructor', run_constructor)
5658
object.__setattr__(self, 'fail_fast', fail_fast)
5759
object.__setattr__(self, 'reinit', reinit)
60+
object.__setattr__(self, 'use_gas', use_gas)
5861

5962

6063
@dataclass(frozen=True)

src/kontrol/prove.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def init_and_run_proof(test: FoundryTest) -> Proof:
204204
kcfg_explore=kcfg_explore,
205205
bmc_depth=prove_options.bmc_depth,
206206
run_constructor=prove_options.run_constructor,
207+
use_gas=prove_options.use_gas,
207208
)
208209

209210
run_prover(
@@ -238,6 +239,7 @@ def method_to_apr_proof(
238239
kcfg_explore: KCFGExplore,
239240
bmc_depth: int | None = None,
240241
run_constructor: bool = False,
242+
use_gas: bool = False,
241243
) -> APRProof | APRBMCProof:
242244
if Proof.proof_data_exists(test.id, foundry.proofs_dir):
243245
apr_proof = foundry.get_apr_proof(test.id)
@@ -259,6 +261,7 @@ def method_to_apr_proof(
259261
test=test,
260262
kcfg_explore=kcfg_explore,
261263
setup_proof=setup_proof,
264+
use_gas=use_gas,
262265
)
263266

264267
if bmc_depth is not None:
@@ -299,6 +302,7 @@ def _method_to_initialized_cfg(
299302
kcfg_explore: KCFGExplore,
300303
*,
301304
setup_proof: APRProof | None = None,
305+
use_gas: bool = False,
302306
) -> tuple[KCFG, int, int]:
303307
_LOGGER.info(f'Initializing KCFG for test: {test.id}')
304308

@@ -308,6 +312,7 @@ def _method_to_initialized_cfg(
308312
test.contract,
309313
test.method,
310314
setup_proof,
315+
use_gas,
311316
)
312317

313318
for node_id in new_node_ids:
@@ -336,6 +341,7 @@ def _method_to_cfg(
336341
contract: Contract,
337342
method: Contract.Method | Contract.Constructor,
338343
setup_proof: APRProof | None,
344+
use_gas: bool,
339345
) -> tuple[KCFG, list[int], int, int]:
340346
calldata = None
341347
callvalue = None
@@ -356,6 +362,7 @@ def _method_to_cfg(
356362
program=program,
357363
calldata=calldata,
358364
callvalue=callvalue,
365+
use_gas=use_gas,
359366
)
360367
new_node_ids = []
361368

@@ -417,6 +424,7 @@ def _init_cterm(
417424
empty_config: KInner,
418425
contract_name: str,
419426
program: KInner,
427+
use_gas: bool,
420428
*,
421429
setup_cterm: CTerm | None = None,
422430
calldata: KInner | None = None,
@@ -432,8 +440,8 @@ def _init_cterm(
432440
)
433441
init_subst = {
434442
'MODE_CELL': KApply('NORMAL'),
443+
'USEGAS_CELL': TRUE if use_gas else FALSE,
435444
'SCHEDULE_CELL': KApply('SHANGHAI_EVM'),
436-
'USEGAS_CELL': TRUE,
437445
'STATUSCODE_CELL': KVariable('STATUSCODE'),
438446
'CALLSTACK_CELL': KApply('.List'),
439447
'CALLDEPTH_CELL': intToken(0),
@@ -487,6 +495,11 @@ def _init_cterm(
487495
if callvalue is not None:
488496
init_subst['CALLVALUE_CELL'] = callvalue
489497

498+
if not use_gas:
499+
init_subst['GAS_CELL'] = intToken(0)
500+
init_subst['CALLGAS_CELL'] = intToken(0)
501+
init_subst['REFUND_CELL'] = intToken(0)
502+
490503
init_term = Subst(init_subst)(empty_config)
491504
init_cterm = CTerm.from_kast(init_term)
492505
init_cterm = KEVM.add_invariant(init_cterm)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
GasTest.testInfiniteGas()
2+
GasTest.testSetGas()
3+
StoreTest.testGasLoadColdVM()
4+
StoreTest.testGasLoadWarmUp()
5+
StoreTest.testGasLoadWarmVM()
6+
StoreTest.testGasStoreColdVM()
7+
StoreTest.testGasStoreWarmUp()
8+
StoreTest.testGasStoreWarmVM()

0 commit comments

Comments
 (0)