diff --git a/solidity_contracts/src/PlainOpcodes/PlainOpcodes.sol b/solidity_contracts/src/PlainOpcodes/PlainOpcodes.sol index cd49b0f16..30d4925e6 100644 --- a/solidity_contracts/src/PlainOpcodes/PlainOpcodes.sol +++ b/solidity_contracts/src/PlainOpcodes/PlainOpcodes.sol @@ -207,6 +207,14 @@ contract PlainOpcodes { return hash; } + function loopProfiling(uint256 max) public pure returns (uint256) { + uint256 val = 0; + for (uint256 i = 0; i < max; i++) { + val += i; + } + return val; + } + receive() external payable {} fallback() external payable {} } diff --git a/tests/fixtures/starknet.py b/tests/fixtures/starknet.py index 25cfdf0e3..385741613 100644 --- a/tests/fixtures/starknet.py +++ b/tests/fixtures/starknet.py @@ -179,7 +179,7 @@ def _factory(entrypoint, **kwargs) -> list: static_locals={"debug_info": debug_info(program)}, vm_class=VmWithCoverage, ) - run_resources = RunResources(n_steps=4_000_000) + run_resources = RunResources(n_steps=10_000_000) try: runner.run_until_pc(end, run_resources) except Exception as e: diff --git a/tests/src/kakarot/test_kakarot.py b/tests/src/kakarot/test_kakarot.py index f6e7db151..1348eb69e 100644 --- a/tests/src/kakarot/test_kakarot.py +++ b/tests/src/kakarot/test_kakarot.py @@ -385,3 +385,22 @@ async def test_failing_contract(self, cairo_run): data="0xADD_DATA", ) assert not evm["reverted"] + + class TestLoopProfiling: + @pytest.mark.slow + @pytest.mark.NoCI + @pytest.mark.parametrize("steps", [10, 50, 100, 200]) + @SyscallHandler.patch("IAccount.is_valid_jumpdest", lambda addr, data: [1]) + def test_loop_profiling(self, get_contract, steps): + plain_opcodes = get_contract("PlainOpcodes", "PlainOpcodes") + initial_state = { + CONTRACT_ADDRESS: { + "code": list(plain_opcodes.bytecode_runtime), + "storage": {}, + "balance": 0, + "nonce": 0, + } + } + with SyscallHandler.patch_state(parse_state(initial_state)): + res = plain_opcodes.loopProfiling(steps) + assert res == sum(x for x in range(steps))