Make addmod and mulmod revert if the last argument is zero.

This commit is contained in:
chriseth
2018-02-15 13:52:17 +01:00
parent 5746e2d7d8
commit 2b5a5a8669
5 changed files with 37 additions and 5 deletions
+27
View File
@@ -7459,6 +7459,33 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod)
ABI_CHECK(callContractFunction("test()"), encodeArgs(u256(0)));
}
BOOST_AUTO_TEST_CASE(addmod_mulmod_zero)
{
char const* sourceCode = R"(
contract C {
function f() pure returns (uint) {
addmod(1, 2, 0);
return 2;
}
function g() pure returns (uint) {
mulmod(1, 2, 0);
return 2;
}
function h() pure returns (uint) {
mulmod(0, 1, 2);
mulmod(1, 0, 2);
addmod(0, 1, 2);
addmod(1, 0, 2);
return 2;
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f()"), encodeArgs());
ABI_CHECK(callContractFunction("g()"), encodeArgs());
ABI_CHECK(callContractFunction("h()"), encodeArgs(2));
}
BOOST_AUTO_TEST_CASE(divisiod_by_zero)
{
char const* sourceCode = R"(