diff options
author | chriseth <c@ethdev.com> | 2016-08-08 01:46:11 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-08-17 17:30:40 +0800 |
commit | 774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8 (patch) | |
tree | d2ba2c8f7f79c5e9d2db46a4ec748844c9968a20 /libsolidity/codegen/ExpressionCompiler.cpp | |
parent | e7683f4722791d39ca63913ec98feb1ea9f5164d (diff) | |
download | dexon-solidity-774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8.tar.gz dexon-solidity-774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8.tar.zst dexon-solidity-774bb8ab3baa9d7b5e6368dcd0f887b13ff26ae8.zip |
Make function calls throw if target does not have code.
Low-level calls still just execute and will actually report "success".
This allows `x.call.value(y)()` for x being a non-contract account.
Diffstat (limited to 'libsolidity/codegen/ExpressionCompiler.cpp')
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 1f93cf8c..e8350931 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1517,6 +1517,13 @@ void ExpressionCompiler::appendExternalFunctionCall( m_context << u256(0); m_context << dupInstruction(m_context.baseToCurrentStackOffset(contractStackPos)); + // Check the the target contract exists (has code) for non-low-level calls. + if (funKind == FunctionKind::External || funKind == FunctionKind::CallCode || funKind == FunctionKind::DelegateCall) + { + m_context << Instruction::DUP1 << Instruction::EXTCODESIZE << Instruction::ISZERO; + m_context.appendConditionalJumpTo(m_context.errorTag()); + } + if (_functionType.gasSet()) m_context << dupInstruction(m_context.baseToCurrentStackOffset(gasStackPos)); else |