Skip to content

Commit

Permalink
Merge pull request #30 from crytic/refactor-medusa-decoding
Browse files Browse the repository at this point in the history
Refactor decoding/parsing of Medusa call sequences
  • Loading branch information
tuturu-tech authored Mar 25, 2024
2 parents d2e9c8b + 8f4b565 commit 61a4a66
Show file tree
Hide file tree
Showing 7 changed files with 472 additions and 501 deletions.
313 changes: 137 additions & 176 deletions fuzz_utils/fuzzers/Medusa.py

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions fuzz_utils/utils/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ def octal_to_byte(match: re.Match) -> str:
def parse_medusa_byte_string(s: str) -> str:
"""Decode bytes* or string type from Medusa format to Solidity hex literal"""
return s.encode("utf-8").hex()


def byte_to_escape_sequence(byte_data: bytes) -> str:
"""Generates unicode escaped string from bytes"""
arr = []
for b in byte_data:
arr.append(f"\\u{b:04x}")
return "".join(arr)
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ requires-python = ">=3.10"
dependencies = [
"colorama>=0.4.0",
"slither_analyzer>=0.10.0",
"jinja2>=3.1.0"
"jinja2>=3.1.0",
"eth_abi>=5.0.1",
"eth_utils>=4.0.0"
]

[project.optional-dependencies]
Expand Down
12 changes: 6 additions & 6 deletions tests/test_data/test/BasicTypes_Medusa_Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ contract BasicTypes_Medusa_Test is Test {
vm.warp(block.timestamp + 565377);
vm.roll(block.number + 18560);
vm.prank(0x0000000000000000000000000000000000020000);
target.check_specific_string(string(hex""));
target.check_specific_string(unicode"\u0000");
}

function test_auto_check_bytes_2() public {
vm.warp(block.timestamp + 461663);
vm.roll(block.number + 0);
vm.prank(0x0000000000000000000000000000000000010000);
target.setBytes(bytes(hex"007e223600ad009f00000f00"));
target.setBytes(bytes(hex"281e5a7ea62236de170107c251ad3e7c9f54bc4db80f0795"));
vm.warp(block.timestamp + 7);
vm.roll(block.number + 6);
vm.prank(0x0000000000000000000000000000000000030000);
Expand All @@ -54,7 +54,7 @@ contract BasicTypes_Medusa_Test is Test {
vm.warp(block.timestamp + 2);
vm.roll(block.number + 1);
vm.prank(0x0000000000000000000000000000000000030000);
target.setInt256(3618502788666131106986593281521497120414687020801267626233049500247285301230);
target.setInt256(int256(-57896044618658097711785492504343953926634992332820282019728792003956564819968));

vm.prank(0x0000000000000000000000000000000000010000);
target.check_int256();
Expand All @@ -63,7 +63,7 @@ contract BasicTypes_Medusa_Test is Test {
function test_auto_check_string_5() public {

vm.prank(0x0000000000000000000000000000000000030000);
target.setString(string(hex"7b4b0400efbfbdefbfbdefbfbd2833efbfbdefbfbdefbfbd12efbfbdefbfbdefbfbdcab1efbfbd58efbfbd07efbfbdefbfbd2eefbfbd00efbfbd4e0059efbfbd0025001defbfbdefbfbd0fefbfbd7befbfbd14efbfbdefbfbdefbfbd05efbfbd07efbfbdefbfbd1351efbfbdefbfbd00efbfbdefbfbd112befbfbd2defbfbd00efbfbdefbfbde0a7b957efbfbd56efbfbd"));
target.setString(unicode"\u00ec\u007b\u004b\u0004\u0099\u00d6\u00d4\u0028\u0033\u00fc\u0081\u0012\u00a6\u00ec\u00ca\u00b1\u00e2\u0058\u00d8\u0007\u00fe\u008d\u002e\u00bc\u00e7\u00e1\u004e\u0066\u0059\u008e\u0072\u0025\u0097\u001d\u00b1\u0061\u00f2\u000f\u0084\u007b\u00b7\u0014\u00a9\u0013\u00a8\u00bf\u0005\u00b5\u0007\u009b\u00bf\u0013\u0051\u00d9\u00d2\u00c5\u00d5\u00d7\u0011\u002b\u00d7\u002d\u0084\u00b7\u009c\u00ad\u00e0\u00a7\u00b9\u0057\u00f6\u0056\u00f1");
vm.warp(block.timestamp + 577918);
vm.roll(block.number + 0);
vm.prank(0x0000000000000000000000000000000000020000);
Expand All @@ -74,7 +74,7 @@ contract BasicTypes_Medusa_Test is Test {
vm.warp(block.timestamp + 3);
vm.roll(block.number + 1);
vm.prank(0x0000000000000000000000000000000000010000);
target.setUint256(188449992507906245299936480734824334914025922450900329849489809685319227362);
target.setUint256(uint256(48243198082023998796783739068115029737990636147430484441469391279441722198374));
vm.warp(block.timestamp + 9289);
vm.roll(block.number + 2753);
vm.prank(0x0000000000000000000000000000000000020000);
Expand All @@ -85,7 +85,7 @@ contract BasicTypes_Medusa_Test is Test {
vm.warp(block.timestamp + 3);
vm.roll(block.number + 0);
vm.prank(0x0000000000000000000000000000000000020000);
target.setCombination(true, 3261438985741997669466759067183635175272827646950472566869970471061131803, -43445065089186984410186728518648022561024163127792198581349213918826074144270, 0x39129d34023aa5337331a35825efdDC3670A6e4b, string(hex"efbfbdefbfbd1f00efbfbdefbfbdefbfbd4838efbfbdefbfbdefbfbd00efbfbd001f003c5c04efbfbd0f00efbfbdefbfbdefbfbdefbfbdefbfbd00efbfbdefbfbd4e7e002910efbfbd7cefbfbdefbfbdefbfbdefbfbd550034"), bytes(hex"a55910b5b6cd490ff6320000c77d7900149e66e500ee907897c6009c394b7f0e0043008e005ceb6700020087a600be81c3525335dad4d448269f57bc89202f8a"));
target.setCombination(true, uint256(53435416342396889816543380556736678711670008167636542535597596197865583522144), int256(-23584384198052993379951759759418486833068931253234756149882793839258141998640), 0x39129d34023aa5337331a35825efdDC3670A6e4b, unicode"\u00b2\u001f\u0097\u00a3\u00a1\u0048\u0038\u00d5\u00a4\u00e0\u009f\u00f7\u001f\u00bd\u003c\u005c\u0004\u00e1\u000f\u001b\u00e4\u00af\u0069\u009f\u004e\u007e\u0017\u0038\u007b\u0029\u0010\u00bd\u007c\u00ab\u00a0\u0055\u00bf\u0034", bytes(hex"a55910b5b6cd490ff632e82a7484c77d7954149e66e51f3dee90a67897c6499c4d39ca4b7f0e5e43438e1b5c34eb674e71020787a639be81c3525335dad4d448269f57bc188920a72fb68a"));

vm.prank(0x0000000000000000000000000000000000030000);
target.check_combined_input();
Expand Down
Loading

0 comments on commit 61a4a66

Please sign in to comment.