mirror of https://github.com/ConsenSys/mythril
commit
c453aa6c78
@ -0,0 +1,27 @@ |
||||
from mock import patch |
||||
from eth_utils import decode_hex |
||||
from mythril.laser.ethereum.natives import ec_add |
||||
from py_ecc.optimized_bn128 import FQ |
||||
|
||||
VECTOR_A = decode_hex( |
||||
"0000000000000000000000000000000000000000000000000000000000000001" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"03" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" |
||||
) |
||||
|
||||
|
||||
def test_ec_add_sanity(): |
||||
assert ec_add(VECTOR_A) == [] |
||||
|
||||
|
||||
@patch("mythril.laser.ethereum.natives.validate_point", return_value=1) |
||||
@patch("mythril.laser.ethereum.natives.bn128.add", return_value=1) |
||||
@patch("mythril.laser.ethereum.natives.bn128.normalize") |
||||
def test_ec_add(f1, f2, f3): |
||||
FQ.fielf_modulus = 128 |
||||
a = FQ(val=1) |
||||
f1.return_value = (a, a) |
||||
assert ec_add(VECTOR_A) == ([0] * 31 + [1]) * 2 |
@ -0,0 +1,35 @@ |
||||
from mock import patch |
||||
from mythril.laser.ethereum.natives import ec_pair |
||||
from py_ecc.optimized_bn128 import FQ |
||||
|
||||
|
||||
def test_ec_pair_192_check(): |
||||
vec_c = [0] * 100 |
||||
assert ec_pair(vec_c) == [] |
||||
|
||||
|
||||
@patch("mythril.laser.ethereum.natives.validate_point", return_value=1) |
||||
@patch("mythril.laser.ethereum.natives.bn128.is_on_curve", return_value=True) |
||||
@patch("mythril.laser.ethereum.natives.bn128.pairing", return_value=1) |
||||
@patch("mythril.laser.ethereum.natives.bn128.normalize") |
||||
def test_ec_pair(f1, f2, f3, f4): |
||||
FQ.fielf_modulus = 100 |
||||
a = FQ(val=1) |
||||
f1.return_value = (a, a) |
||||
vec_c = [0] * 192 |
||||
assert ec_pair(vec_c) == [0] * 31 + [1] |
||||
|
||||
|
||||
@patch("mythril.laser.ethereum.natives.validate_point", return_value=False) |
||||
def test_ec_pair_point_validation_failure(f1): |
||||
vec_c = [0] * 192 |
||||
assert ec_pair(vec_c) == [] |
||||
|
||||
|
||||
@patch("mythril.laser.ethereum.natives.validate_point", return_value=1) |
||||
def test_ec_pair_field_exceed_mod(f1): |
||||
FQ.fielf_modulus = 100 |
||||
a = FQ(val=1) |
||||
f1.return_value = (a, a) |
||||
vec_c = [10] * 192 |
||||
assert ec_pair(vec_c) == [] |
@ -0,0 +1,27 @@ |
||||
from mock import patch |
||||
from eth_utils import decode_hex |
||||
from mythril.laser.ethereum.natives import ec_mul |
||||
from py_ecc.optimized_bn128 import FQ |
||||
|
||||
VECTOR_A = decode_hex( |
||||
"0000000000000000000000000000000000000000000000000000000000000001" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"03" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" |
||||
) |
||||
|
||||
|
||||
@patch("mythril.laser.ethereum.natives.validate_point", return_value=1) |
||||
@patch("mythril.laser.ethereum.natives.bn128.multiply", return_value=1) |
||||
@patch("mythril.laser.ethereum.natives.bn128.normalize") |
||||
def test_ec_mul(f1, f2, f3): |
||||
FQ.fielf_modulus = 128 |
||||
a = FQ(val=1) |
||||
f1.return_value = (a, a) |
||||
assert ec_mul(VECTOR_A) == ([0] * 31 + [1]) * 2 |
||||
|
||||
|
||||
def test_ec_mul_validation_failure(): |
||||
assert ec_mul(VECTOR_A) == [] |
@ -0,0 +1,61 @@ |
||||
import pytest |
||||
from eth_utils import decode_hex |
||||
from mythril.laser.ethereum.natives import mod_exp |
||||
from ethereum.utils import big_endian_to_int |
||||
|
||||
|
||||
EIP198_VECTOR_A = decode_hex( |
||||
"0000000000000000000000000000000000000000000000000000000000000001" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"03" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" |
||||
) |
||||
|
||||
EIP198_VECTOR_B = decode_hex( |
||||
"0000000000000000000000000000000000000000000000000000000000000000" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" |
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" |
||||
) |
||||
|
||||
EIP198_VECTOR_C = decode_hex( |
||||
"0000000000000000000000000000000000000000000000000000000000000001" |
||||
"0000000000000000000000000000000000000000000000000000000000000002" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"03" |
||||
"ffff" |
||||
"8000000000000000000000000000000000000000000000000000000000000000" |
||||
"07" |
||||
) |
||||
|
||||
EIP198_VECTOR_D = decode_hex( |
||||
"0000000000000000000000000000000000000000000000000000000000000001" |
||||
"0000000000000000000000000000000000000000000000000000000000000002" |
||||
"0000000000000000000000000000000000000000000000000000000000000020" |
||||
"03" |
||||
"ffff" |
||||
"80" |
||||
) |
||||
|
||||
|
||||
@pytest.mark.parametrize( |
||||
"data,expected", |
||||
( |
||||
(EIP198_VECTOR_A, 1), |
||||
(EIP198_VECTOR_B, 0), |
||||
( |
||||
EIP198_VECTOR_C, |
||||
26689440342447178617115869845918039756797228267049433585260346420242739014315, |
||||
), |
||||
( |
||||
EIP198_VECTOR_D, |
||||
26689440342447178617115869845918039756797228267049433585260346420242739014315, |
||||
), |
||||
), |
||||
) |
||||
def test_modexp_result(data, expected): |
||||
actual = mod_exp(data) |
||||
assert big_endian_to_int(actual) == expected |
Loading…
Reference in new issue