diff options
author | chriseth <chris@ethereum.org> | 2018-05-08 04:34:31 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-05-16 15:48:03 +0800 |
commit | 894122c508c4de07553c7e2908ae36821e812a9f (patch) | |
tree | 694d7cccbe796d33f63bfca3c25eecb9021cb1a4 /libsolidity/analysis | |
parent | 8b98ff470ccb11fbe0e7c1729db5958355c2f84a (diff) | |
download | dexon-solidity-894122c508c4de07553c7e2908ae36821e812a9f.tar dexon-solidity-894122c508c4de07553c7e2908ae36821e812a9f.tar.gz dexon-solidity-894122c508c4de07553c7e2908ae36821e812a9f.tar.bz2 dexon-solidity-894122c508c4de07553c7e2908ae36821e812a9f.tar.lz dexon-solidity-894122c508c4de07553c7e2908ae36821e812a9f.tar.xz dexon-solidity-894122c508c4de07553c7e2908ae36821e812a9f.tar.zst dexon-solidity-894122c508c4de07553c7e2908ae36821e812a9f.zip |
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.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index e8694e88..f77cc60c 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -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, ""); |