diff --git a/.circleci/config.yml b/.circleci/config.yml index 91ba3a4e0..7dfbedaa7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,14 +107,17 @@ defaults: - run_soltest: &run_soltest name: soltest + no_output_timeout: 30m command: ./.circleci/soltest.sh - run_soltest_all: &run_soltest_all name: soltest_all + no_output_timeout: 30m command: ./.circleci/soltest_all.sh - run_cmdline_tests: &run_cmdline_tests name: command line tests + no_output_timeout: 30m command: ./test/cmdlineTests.sh - run_docs_pragma_min_version: &run_docs_pragma_min_version @@ -163,7 +166,6 @@ defaults: at: build - run: <<: *run_soltest - no_output_timeout: 30m - store_test_results: *store_test_results - store_artifacts: *artifacts_test_results @@ -175,7 +177,6 @@ defaults: at: build - run: <<: *run_soltest - no_output_timeout: 30m - store_test_results: *store_test_results - store_artifacts: *artifacts_test_results @@ -709,7 +710,6 @@ jobs: at: build - run: <<: *run_cmdline_tests - no_output_timeout: 30m - store_test_results: *store_test_results - store_artifacts: *artifacts_test_results @@ -745,6 +745,7 @@ jobs: apt-get install -qqy --no-install-recommends nodejs npm cvc4 - run: name: Test solcjs + no_output_timeout: 30m command: | node --version npm --version diff --git a/Changelog.md b/Changelog.md index 000b23945..74440bd57 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,7 +12,8 @@ Compiler Features: * Yul Optimizer: Prune unused parameters in functions. Bugfixes: - + * Type Checker: Disallow ``virtual`` for modifiers in libraries. + * ViewPureChecker: Prevent visibility check on constructors. ### 0.7.1 (2020-09-02) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 990192d68..2f9768d9a 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -320,6 +320,15 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance) void TypeChecker::endVisit(ModifierDefinition const& _modifier) { + if (_modifier.virtualSemantics()) + if (auto const* contractDef = dynamic_cast(_modifier.scope())) + if (contractDef->isLibrary()) + m_errorReporter.typeError( + 3275_error, + _modifier.location(), + "Modifiers in a library cannot be virtual." + ); + if (!_modifier.isImplemented() && !_modifier.virtualSemantics()) m_errorReporter.typeError(8063_error, _modifier.location(), "Modifiers without implementation must be marked virtual."); } diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index b75b4a240..f684bc289 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -261,21 +261,24 @@ void ViewPureChecker::reportMutability( { // We do not warn for library functions because they cannot be payable anyway. // Also internal functions should be allowed to use `msg.value`. - if (m_currentFunction->isPublic() && !m_currentFunction->libraryFunction()) + if ((m_currentFunction->isConstructor() || m_currentFunction->isPublic()) && !m_currentFunction->libraryFunction()) { if (_nestedLocation) m_errorReporter.typeError( 4006_error, _location, SecondarySourceLocation().append("\"msg.value\" or \"callvalue()\" appear here inside the modifier.", *_nestedLocation), - "This modifier uses \"msg.value\" or \"callvalue()\" and thus the function has to be payable or internal." + m_currentFunction->isConstructor() ? + "This modifier uses \"msg.value\" or \"callvalue()\" and thus the constructor has to be payable." + : "This modifier uses \"msg.value\" or \"callvalue()\" and thus the function has to be payable or internal." ); else m_errorReporter.typeError( 5887_error, _location, - "\"msg.value\" and \"callvalue()\" can only be used in payable public functions. Make the function " - "\"payable\" or use an internal function to avoid this error." + m_currentFunction->isConstructor() ? + "\"msg.value\" and \"callvalue()\" can only be used in payable constructors. Make the constructor \"payable\" to avoid this error." + : "\"msg.value\" and \"callvalue()\" can only be used in payable public functions. Make the function \"payable\" or use an internal function to avoid this error." ); m_errors = true; } diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index 40cfe375f..0ddcf1703 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -193,7 +193,7 @@ private: void visitStatements(std::vector const& _statements); /// Pops all variables declared in the block and checks that the stack height is equal - /// to @a _blackStartStackHeight. + /// to @a _blockStartStackHeight. void finalizeBlock(Block const& _block, int _blockStartStackHeight); void generateMultiAssignment(std::vector const& _variableNames); diff --git a/libyul/optimiser/FunctionGrouper.h b/libyul/optimiser/FunctionGrouper.h index 0bfbb2f06..ead0ddc11 100644 --- a/libyul/optimiser/FunctionGrouper.h +++ b/libyul/optimiser/FunctionGrouper.h @@ -16,7 +16,7 @@ */ // SPDX-License-Identifier: GPL-3.0 /** - * Optimiser component that changes the code of a black so that all non-function definition + * Optimiser component that changes the code of a block so that all non-function definition * instructions are moved to a block of their own followed by all function definitions. */ diff --git a/test/libsolidity/syntaxTests/constructor/msg_value_non_payable.sol b/test/libsolidity/syntaxTests/constructor/msg_value_non_payable.sol new file mode 100644 index 000000000..8392cdf63 --- /dev/null +++ b/test/libsolidity/syntaxTests/constructor/msg_value_non_payable.sol @@ -0,0 +1,8 @@ +contract C { + uint256 value; + constructor() { + value = msg.value; + } +} +// ---- +// TypeError 5887: (68-77): "msg.value" and "callvalue()" can only be used in payable constructors. Make the constructor "payable" to avoid this error. diff --git a/test/libsolidity/syntaxTests/functionCalls/msg_value_non_payable.sol b/test/libsolidity/syntaxTests/functionCalls/msg_value_non_payable.sol new file mode 100644 index 000000000..281e74882 --- /dev/null +++ b/test/libsolidity/syntaxTests/functionCalls/msg_value_non_payable.sol @@ -0,0 +1,7 @@ +contract C { + function get() public view returns(uint256) { + return msg.value; + } +} +// ---- +// TypeError 5887: (78-87): "msg.value" and "callvalue()" can only be used in payable public functions. Make the function "payable" or use an internal function to avoid this error. diff --git a/test/libsolidity/syntaxTests/inheritance/virtual/modifier_virtual_err.sol b/test/libsolidity/syntaxTests/inheritance/virtual/modifier_virtual_err.sol new file mode 100644 index 000000000..85824c86b --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/virtual/modifier_virtual_err.sol @@ -0,0 +1,7 @@ +library test { + modifier m virtual; + function f() m public { + } +} +// ---- +// TypeError 3275: (19-38): Modifiers in a library cannot be virtual.