aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-07-28 16:06:33 +0800
committerchriseth <chris@ethereum.org>2017-07-28 21:32:42 +0800
commit368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870 (patch)
treeefbc62ba30bf71cad8c076184a5035907f331658 /test
parent7e40def689db37658a03a53a6e02f3392823ed62 (diff)
downloaddexon-solidity-368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870.tar
dexon-solidity-368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870.tar.gz
dexon-solidity-368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870.tar.bz2
dexon-solidity-368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870.tar.lz
dexon-solidity-368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870.tar.xz
dexon-solidity-368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870.tar.zst
dexon-solidity-368a8a62c1c2c34cdcd1edb3b1ce1d5a2a3a2870.zip
Test case for invalid ecrecover call.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 5bcde441..057ec94b 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -8251,6 +8251,53 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
}
+BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (address) {
+ return recover(
+ 0x77e5189111eb6557e8a637b27ef8fbb15bc61d61c2f00cc48878f3a296e5e0ca,
+ 0, // invalid v value
+ 0x6944c77849b18048f6abe0db8084b0d0d0689cdddb53d2671c36967b58691ad4,
+ 0xef4f06ba4f78319baafd0424365777241af4dfd3da840471b4b4b087b7750d0d,
+ 0xca35b7d915458ef540ade6068dfe2f44e8fa733c,
+ 0xca35b7d915458ef540ade6068dfe2f44e8fa733c
+ );
+ }
+ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s, uint blockExpired, bytes32 salt)
+ returns (address)
+ {
+ require(hash == sha3(blockExpired, salt));
+ return ecrecover(hash, v, r, s);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
+}
+
+BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_asm)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() returns (address) {
+ assembly {
+ mstore(mload(0x40), 0xca35b7d915458ef540ade6068dfe2f44e8fa733c)
+ }
+ return ecrecover(
+ 0x77e5189111eb6557e8a637b27ef8fbb15bc61d61c2f00cc48878f3a296e5e0ca,
+ 0, // invalid v value
+ 0x6944c77849b18048f6abe0db8084b0d0d0689cdddb53d2671c36967b58691ad4,
+ 0xef4f06ba4f78319baafd0424365777241af4dfd3da840471b4b4b087b7750d0d
+ );
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
+}
+
BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws)
{
char const* sourceCode = R"(