diff --git a/Changelog.md b/Changelog.md index 251144b37..362be6d1f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,6 +21,7 @@ Compiler Features: * SMTChecker: Make ``z3`` the default solver for the BMC and CHC engines instead of all solvers. * Parser: More detailed error messages about invalid version pragmas. * Removed support for the ``solidity-upgrade`` tool. + * TypeChecker: Warn when using deprecated builtin ``selfdestruct``. Bugfixes: diff --git a/docs/contracts/function-modifiers.rst b/docs/contracts/function-modifiers.rst index f23119544..bbdec1e48 100644 --- a/docs/contracts/function-modifiers.rst +++ b/docs/contracts/function-modifiers.rst @@ -19,6 +19,7 @@ if they are marked ``virtual``. For details, please see // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.1 <0.9.0; + // This will report a warning due to deprecated selfdestruct contract owned { constructor() { owner = payable(msg.sender); } diff --git a/docs/contracts/inheritance.rst b/docs/contracts/inheritance.rst index a33a36d27..4f310bd40 100644 --- a/docs/contracts/inheritance.rst +++ b/docs/contracts/inheritance.rst @@ -40,7 +40,7 @@ Details are given in the following example. // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; - + // This will report a warning due to deprecated selfdestruct contract Owned { constructor() { owner = payable(msg.sender); } @@ -130,6 +130,7 @@ seen in the following example: // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; + // This will report a warning due to deprecated selfdestruct contract owned { constructor() { owner = payable(msg.sender); } @@ -162,6 +163,7 @@ explicitly in the final override, but this function will bypass // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; + // This will report a warning due to deprecated selfdestruct contract owned { constructor() { owner = payable(msg.sender); } diff --git a/docs/examples/micropayment.rst b/docs/examples/micropayment.rst index 7ade92657..f5037e6f7 100644 --- a/docs/examples/micropayment.rst +++ b/docs/examples/micropayment.rst @@ -144,6 +144,7 @@ The full contract // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; + // This will report a warning due to deprecated selfdestruct contract ReceiverPays { address owner = msg.sender; @@ -341,6 +342,7 @@ The full contract // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; + // This will report a warning due to deprecated selfdestruct contract SimplePaymentChannel { address payable public sender; // The account sending payments. address payable public recipient; // The account receiving the payments. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index ac00ab7fe..4e390931f 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -3657,6 +3657,14 @@ bool TypeChecker::visit(Identifier const& _identifier) _identifier.location(), "\"suicide\" has been deprecated in favour of \"selfdestruct\"." ); + else if (_identifier.name() == "selfdestruct" && fType->kind() == FunctionType::Kind::Selfdestruct) + m_errorReporter.warning( + 5159_error, + _identifier.location(), + "\"selfdestruct\" has been deprecated. " + "The underlying opcode will eventually undergo breaking changes, " + "and its use is not recommended." + ); } if ( diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 4c9abdadd..3ca84da71 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -311,6 +311,14 @@ vector AsmAnalyzer::operator()(FunctionCall const& _funCall) if (BuiltinFunction const* f = m_dialect.builtin(_funCall.functionName.name)) { + if (_funCall.functionName.name.str() == "selfdestruct") + m_errorReporter.warning( + 1699_error, + nativeLocationOf(_funCall.functionName), + "\"selfdestruct\" has been deprecated. " + "The underlying opcode will eventually undergo breaking changes, " + "and its use is not recommended." + ); parameterTypes = &f->parameters; returnTypes = &f->returns; if (!f->literalArguments.empty()) diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/430_bare_selfdestruct.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/430_bare_selfdestruct.sol index b770b6044..6662d7b29 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/430_bare_selfdestruct.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/430_bare_selfdestruct.sol @@ -2,4 +2,5 @@ contract C { function f() pure public { selfdestruct; } } // ---- +// Warning 5159: (44-56): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. // Warning 6133: (44-56): Statement has no effect. diff --git a/test/libsolidity/syntaxTests/types/address/address_nonpayable_selfdestruct.sol b/test/libsolidity/syntaxTests/types/address/address_nonpayable_selfdestruct.sol index 812258711..9122d2a89 100644 --- a/test/libsolidity/syntaxTests/types/address/address_nonpayable_selfdestruct.sol +++ b/test/libsolidity/syntaxTests/types/address/address_nonpayable_selfdestruct.sol @@ -4,4 +4,5 @@ contract C { } } // ---- +// Warning 5159: (56-68): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. // TypeError 9553: (69-70): Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested. diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_selfdestruct.sol b/test/libsolidity/syntaxTests/types/address/address_payable_selfdestruct.sol index 62eadeca5..bd1aff795 100644 --- a/test/libsolidity/syntaxTests/types/address/address_payable_selfdestruct.sol +++ b/test/libsolidity/syntaxTests/types/address/address_payable_selfdestruct.sol @@ -4,3 +4,4 @@ contract C { } } // ---- +// Warning 5159: (64-76): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol index b381b3130..3ee940679 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol @@ -19,3 +19,4 @@ contract C { receive() payable external {} } // ---- +// Warning 5159: (122-134): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol index 76a05d8be..f458aaad5 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol @@ -20,6 +20,7 @@ contract C { } } // ---- +// Warning 5159: (201-213): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. // TypeError 8961: (52-77): Function cannot be declared as view because this expression (potentially) modifies the state. // TypeError 8961: (132-153): Function cannot be declared as view because this expression (potentially) modifies the state. // TypeError 8961: (201-228): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed.sol b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed.sol index 2b9e5ae5f..b3753706c 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_allowed.sol @@ -85,6 +85,7 @@ contract C { // ==== // EVMVersion: >=paris // ---- +// Warning 1699: (1754-1766): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. // Warning 5740: (89-1716): Unreachable code. // Warning 5740: (1729-1741): Unreachable code. // Warning 5740: (1754-1769): Unreachable code. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure.sol b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure.sol index 9b3806f4d..be84b801f 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_pure.sol @@ -35,6 +35,7 @@ contract C { } } // ---- +// Warning 1699: (498-510): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. // Warning 5740: (526-853): Unreachable code. // TypeError 2527: (79-87): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view". // TypeError 8961: (101-113): Function cannot be declared as pure because this expression (potentially) modifies the state. diff --git a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_view.sol b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_view.sol index 5daf91742..cd69bed79 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_view.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/inline_assembly_instructions_disallowed_view.sol @@ -23,6 +23,7 @@ contract C { // ==== // EVMVersion: >=london // ---- +// Warning 1699: (308-320): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. // Warning 5740: (336-468): Unreachable code. // TypeError 8961: (75-87): Function cannot be declared as view because this expression (potentially) modifies the state. // TypeError 8961: (104-119): Function cannot be declared as view because this expression (potentially) modifies the state. diff --git a/test/libyul/yulSyntaxTests/selfdestruct.yul b/test/libyul/yulSyntaxTests/selfdestruct.yul index 70d76c73b..745fdc5c5 100644 --- a/test/libyul/yulSyntaxTests/selfdestruct.yul +++ b/test/libyul/yulSyntaxTests/selfdestruct.yul @@ -2,3 +2,4 @@ selfdestruct(0x02) } // ---- +// Warning 1699: (3-15): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended.