Validate value types in decoder of ABIEncoderV2.

This commit is contained in:
Alex Beregszaszi
2019-04-03 11:32:02 +02:00
committed by chriseth
parent e9ffbefb05
commit 43008dd08e
5 changed files with 135 additions and 55 deletions
+19 -2
View File
@@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(cleanup)
ABI_CHECK(
callContractFunction(
"f(uint16,int16,address,bytes3,bool)",
u256(0xffffff), u256(0x1ffff), u256(-1), string("abcd"), u256(4)
u256(0xffffff), u256(0x1ffff), u256(-1), string("abcd"), u256(1)
),
encodeArgs(u256(0xffff), u256(-1), (u256(1) << 160) - 1, string("abc"), true)
);
@@ -759,7 +759,6 @@ BOOST_AUTO_TEST_CASE(complex_struct)
)
}
BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_simple)
{
if (m_evmVersion == langutil::EVMVersion::homestead())
@@ -844,6 +843,24 @@ BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_out_of_range)
)
}
BOOST_AUTO_TEST_CASE(out_of_bounds_bool_value)
{
string sourceCode = R"(
contract C {
function f(bool b) public pure returns (bool) { return b; }
}
)";
bool newDecoder = false;
BOTH_ENCODERS(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f(bool)", true), encodeArgs(true));
ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(false));
ABI_CHECK(callContractFunctionNoEncoding("f(bool)", bytes(32, 0)), encodeArgs(0));
ABI_CHECK(callContractFunctionNoEncoding("f(bool)", bytes(32, 0xff)), newDecoder ? encodeArgs() : encodeArgs(1));
newDecoder = true;
)
}
BOOST_AUTO_TEST_SUITE_END()
}