Skip to content

Commit

Permalink
fix: off by one error ripemd-160 (#187)
Browse files Browse the repository at this point in the history
Closes #146

Off by one error

Note to reviewer: this is a fix imported from C4 mitigation, ensure the
fix was correctly ported by looking at the corresponding issue and PR.
  • Loading branch information
obatirou authored Dec 3, 2024
1 parent e9fe89d commit ca1660d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cairo/src/precompiles/ripemd160.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func finish{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}(
let len_8 = mswlen * 8;
let (val_15) = uint32_or(factor, len_8);

let next_block = is_nn_le(55, len);
let next_block = is_nn_le(56, len);
if (next_block == FALSE) {
dict_write{dict_ptr=x}(14, val);
dict_write{dict_ptr=x}(15, val_15);
Expand Down
4 changes: 2 additions & 2 deletions cairo/tests/src/precompiles/test_ripemd160.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from Crypto.Hash import RIPEMD160
from hypothesis import given, settings
from hypothesis import example, given
from hypothesis.strategies import binary

from tests.utils.errors import cairo_error
Expand All @@ -10,7 +10,7 @@
@pytest.mark.slow
class TestRIPEMD160:
@given(msg_bytes=binary(min_size=1, max_size=200))
@settings(max_examples=3)
@example(msg_bytes=b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmomnopnopq")
def test_ripemd160_should_return_correct_hash(self, cairo_run, msg_bytes):
precompile_hash = cairo_run("test__ripemd160", msg=list(msg_bytes))

Expand Down

0 comments on commit ca1660d

Please sign in to comment.