From 034d436933806c204b84b0500e2116938cb6a030 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sun, 7 Aug 2016 19:40:19 +0200 Subject: Make ecrecover throw for malformed input. --- test/libsolidity/SolidityEndToEndTest.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 1b7c5ea4..338a47da 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -6853,6 +6853,24 @@ BOOST_AUTO_TEST_CASE(create_dynamic_array_with_zero_length) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7))); } +BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input) +{ + // ecrecover should throw for malformed input + // (v should be 27 or 28, not 1) + // This is quite hard to test because the precompiled does NOT throw, instead it just + // does not write to its output area, we have to check that and currently do it + // by checking whether ecrecover "returns" zero. + char const* sourceCode = R"( + contract C { + function f() returns (address) { + return ecrecover(bytes32(uint(-1)), 1, 2, 3); + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs()); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From d731225d02c9b8d6dc9f2ba632923b765d0e111d Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 12 Aug 2016 15:54:17 +0200 Subject: Actually better to return zero on error. --- test/libsolidity/SolidityEndToEndTest.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 338a47da..345bac80 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -6855,11 +6855,9 @@ BOOST_AUTO_TEST_CASE(create_dynamic_array_with_zero_length) BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input) { - // ecrecover should throw for malformed input + // ecrecover should return zero for malformed input // (v should be 27 or 28, not 1) - // This is quite hard to test because the precompiled does NOT throw, instead it just - // does not write to its output area, we have to check that and currently do it - // by checking whether ecrecover "returns" zero. + // Note that the precompile does not return zero but returns nothing. char const* sourceCode = R"( contract C { function f() returns (address) { @@ -6868,7 +6866,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input) } )"; compileAndRun(sourceCode, 0, "C"); - BOOST_CHECK(callContractFunction("f()") == encodeArgs()); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0))); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3