Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: loop profiling #1256

Merged
merged 5 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions solidity_contracts/src/PlainOpcodes/PlainOpcodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
20 changes: 20 additions & 0 deletions tests/src/kakarot/test_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,23 @@ async def test_failing_contract(self, cairo_run):
data="0xADD_DATA",
)
assert not evm["reverted"]

class TestLoopProfiling:
@pytest.mark.slow
@SyscallHandler.patch(
"IAccount.is_valid_jumpdest",
lambda addr, data: [1],
)
obatirou marked this conversation as resolved.
Show resolved Hide resolved
def test_loop_profiling(self, get_contract):
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(10)
assert res == 45
Loading