Warn/enforce single bytes argument for certain builtins (hashing functions).

In 0.5.0 mode, only accept a single bytes argument for ``.call``,
``keccak256`` and others and do not pad when encoding.
This commit is contained in:
chriseth
2018-05-16 09:48:03 +02:00
parent 8b98ff470c
commit 894122c508
3 changed files with 44 additions and 0 deletions
+27
View File
@@ -1760,6 +1760,33 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
}
}
if (functionType->takesSinglePackedBytesParameter())
{
string generalMessage =
"This function only accepts a single \"bytes\" argument. Please use "
"\"abi.encodePacked(...)\" or a similar function to encode the data.";
if (arguments.size() > 1)
{
if (v050)
m_errorReporter.typeError(_functionCall.location(), generalMessage);
else
m_errorReporter.warning(_functionCall.location(), generalMessage);
}
else if (arguments.size() == 1 && !type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType(DataLocation::Memory)))
{
string msg =
generalMessage +
" The provided argument of type " +
type(*arguments.front())->toString() +
" is not implicitly convertible to expected type bytes memory.";
if (v050)
m_errorReporter.typeError(_functionCall.location(), msg);
else
m_errorReporter.warning(_functionCall.location(), msg);
}
}
if (functionType->takesArbitraryParameters() && arguments.size() < parameterTypes.size())
{
solAssert(_functionCall.annotation().kind == FunctionCallKind::FunctionCall, "");