mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #13884 from ethereum/deprecation-warning-for-selfdestruct
Issue warning when using deprecated SELFDESTRUCT
This commit is contained in:
		
						commit
						019d13d3b6
					
				| @ -21,6 +21,7 @@ Compiler Features: | |||||||
|  * SMTChecker: Make ``z3`` the default solver for the BMC and CHC engines instead of all solvers. |  * 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. |  * Parser: More detailed error messages about invalid version pragmas. | ||||||
|  * Removed support for the ``solidity-upgrade`` tool. |  * Removed support for the ``solidity-upgrade`` tool. | ||||||
|  |  * TypeChecker: Warn when using deprecated builtin ``selfdestruct``. | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Bugfixes: | Bugfixes: | ||||||
|  | |||||||
| @ -19,6 +19,7 @@ if they are marked ``virtual``. For details, please see | |||||||
| 
 | 
 | ||||||
|     // SPDX-License-Identifier: GPL-3.0 |     // SPDX-License-Identifier: GPL-3.0 | ||||||
|     pragma solidity >=0.7.1 <0.9.0; |     pragma solidity >=0.7.1 <0.9.0; | ||||||
|  |     // This will report a warning due to deprecated selfdestruct | ||||||
| 
 | 
 | ||||||
|     contract owned { |     contract owned { | ||||||
|         constructor() { owner = payable(msg.sender); } |         constructor() { owner = payable(msg.sender); } | ||||||
|  | |||||||
| @ -40,7 +40,7 @@ Details are given in the following example. | |||||||
| 
 | 
 | ||||||
|     // SPDX-License-Identifier: GPL-3.0 |     // SPDX-License-Identifier: GPL-3.0 | ||||||
|     pragma solidity >=0.7.0 <0.9.0; |     pragma solidity >=0.7.0 <0.9.0; | ||||||
| 
 |     // This will report a warning due to deprecated selfdestruct | ||||||
| 
 | 
 | ||||||
|     contract Owned { |     contract Owned { | ||||||
|         constructor() { owner = payable(msg.sender); } |         constructor() { owner = payable(msg.sender); } | ||||||
| @ -130,6 +130,7 @@ seen in the following example: | |||||||
| 
 | 
 | ||||||
|     // SPDX-License-Identifier: GPL-3.0 |     // SPDX-License-Identifier: GPL-3.0 | ||||||
|     pragma solidity >=0.7.0 <0.9.0; |     pragma solidity >=0.7.0 <0.9.0; | ||||||
|  |     // This will report a warning due to deprecated selfdestruct | ||||||
| 
 | 
 | ||||||
|     contract owned { |     contract owned { | ||||||
|         constructor() { owner = payable(msg.sender); } |         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 |     // SPDX-License-Identifier: GPL-3.0 | ||||||
|     pragma solidity >=0.7.0 <0.9.0; |     pragma solidity >=0.7.0 <0.9.0; | ||||||
|  |     // This will report a warning due to deprecated selfdestruct | ||||||
| 
 | 
 | ||||||
|     contract owned { |     contract owned { | ||||||
|         constructor() { owner = payable(msg.sender); } |         constructor() { owner = payable(msg.sender); } | ||||||
|  | |||||||
| @ -144,6 +144,7 @@ The full contract | |||||||
| 
 | 
 | ||||||
|     // SPDX-License-Identifier: GPL-3.0 |     // SPDX-License-Identifier: GPL-3.0 | ||||||
|     pragma solidity >=0.7.0 <0.9.0; |     pragma solidity >=0.7.0 <0.9.0; | ||||||
|  |     // This will report a warning due to deprecated selfdestruct | ||||||
|     contract ReceiverPays { |     contract ReceiverPays { | ||||||
|         address owner = msg.sender; |         address owner = msg.sender; | ||||||
| 
 | 
 | ||||||
| @ -341,6 +342,7 @@ The full contract | |||||||
| 
 | 
 | ||||||
|     // SPDX-License-Identifier: GPL-3.0 |     // SPDX-License-Identifier: GPL-3.0 | ||||||
|     pragma solidity >=0.7.0 <0.9.0; |     pragma solidity >=0.7.0 <0.9.0; | ||||||
|  |     // This will report a warning due to deprecated selfdestruct | ||||||
|     contract SimplePaymentChannel { |     contract SimplePaymentChannel { | ||||||
|         address payable public sender;      // The account sending payments. |         address payable public sender;      // The account sending payments. | ||||||
|         address payable public recipient;   // The account receiving the payments. |         address payable public recipient;   // The account receiving the payments. | ||||||
|  | |||||||
| @ -562,6 +562,11 @@ is removed from the state. Removing the contract in theory sounds like a good | |||||||
| idea, but it is potentially dangerous, as if someone sends Ether to removed | idea, but it is potentially dangerous, as if someone sends Ether to removed | ||||||
| contracts, the Ether is forever lost. | contracts, the Ether is forever lost. | ||||||
| 
 | 
 | ||||||
|  | .. warning:: | ||||||
|  |     From version 0.8.18 and up, the use of ``selfdestruct`` in both Solidity and Yul will trigger a | ||||||
|  |     deprecation warning, since the ``SELFDESTRUCT`` opcode will eventually undergo breaking changes in behaviour | ||||||
|  |     as stated in `EIP-6049 <https://eips.ethereum.org/EIPS/eip-6049>`_. | ||||||
|  | 
 | ||||||
| .. warning:: | .. warning:: | ||||||
|     Even if a contract is removed by ``selfdestruct``, it is still part of the |     Even if a contract is removed by ``selfdestruct``, it is still part of the | ||||||
|     history of the blockchain and probably retained by most Ethereum nodes. |     history of the blockchain and probably retained by most Ethereum nodes. | ||||||
|  | |||||||
| @ -327,11 +327,13 @@ Contract Related | |||||||
|     - the receiving contract's receive function is not executed. |     - the receiving contract's receive function is not executed. | ||||||
|     - the contract is only really destroyed at the end of the transaction and ``revert`` s might "undo" the destruction. |     - the contract is only really destroyed at the end of the transaction and ``revert`` s might "undo" the destruction. | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| Furthermore, all functions of the current contract are callable directly including the current function. | Furthermore, all functions of the current contract are callable directly including the current function. | ||||||
| 
 | 
 | ||||||
|  | .. warning:: | ||||||
|  |     From version 0.8.18 and up, the use of ``selfdestruct`` in both Solidity and Yul will trigger a | ||||||
|  |     deprecation warning, since the ``SELFDESTRUCT`` opcode will eventually undergo breaking changes in behaviour | ||||||
|  |     as stated in `EIP-6049 <https://eips.ethereum.org/EIPS/eip-6049>`_. | ||||||
|  | 
 | ||||||
| .. note:: | .. note:: | ||||||
|     Prior to version 0.5.0, there was a function called ``suicide`` with the same |     Prior to version 0.5.0, there was a function called ``suicide`` with the same | ||||||
|     semantics as ``selfdestruct``. |     semantics as ``selfdestruct``. | ||||||
|  | |||||||
| @ -899,6 +899,7 @@ the ``dup`` and ``swap`` instructions as well as ``jump`` instructions, labels a | |||||||
| | revert(p, s)            | `-` | B | end execution, revert state changes, return data mem[p...(p+s)) | | | revert(p, s)            | `-` | B | end execution, revert state changes, return data mem[p...(p+s)) | | ||||||
| +-------------------------+-----+---+-----------------------------------------------------------------+ | +-------------------------+-----+---+-----------------------------------------------------------------+ | ||||||
| | selfdestruct(a)         | `-` | F | end execution, destroy current contract and send funds to a     | | | selfdestruct(a)         | `-` | F | end execution, destroy current contract and send funds to a     | | ||||||
|  | |                         |     |   | (deprecated)                                                    | | ||||||
| +-------------------------+-----+---+-----------------------------------------------------------------+ | +-------------------------+-----+---+-----------------------------------------------------------------+ | ||||||
| | invalid()               | `-` | F | end execution with invalid instruction                          | | | invalid()               | `-` | F | end execution with invalid instruction                          | | ||||||
| +-------------------------+-----+---+-----------------------------------------------------------------+ | +-------------------------+-----+---+-----------------------------------------------------------------+ | ||||||
| @ -956,6 +957,11 @@ the ``dup`` and ``swap`` instructions as well as ``jump`` instructions, labels a | |||||||
|   Please note that irrelevant to which EVM version is selected in the compiler, the semantics of |   Please note that irrelevant to which EVM version is selected in the compiler, the semantics of | ||||||
|   instructions depend on the final chain of deployment. |   instructions depend on the final chain of deployment. | ||||||
| 
 | 
 | ||||||
|  | .. warning:: | ||||||
|  |     From version 0.8.18 and up, the use of ``selfdestruct`` in both Solidity and Yul will trigger a | ||||||
|  |     deprecation warning, since the ``SELFDESTRUCT`` opcode will eventually undergo breaking changes in behaviour | ||||||
|  |     as stated in `EIP-6049 <https://eips.ethereum.org/EIPS/eip-6049>`_. | ||||||
|  | 
 | ||||||
| In some internal dialects, there are additional functions: | In some internal dialects, there are additional functions: | ||||||
| 
 | 
 | ||||||
| datasize, dataoffset, datacopy | datasize, dataoffset, datacopy | ||||||
|  | |||||||
| @ -3657,6 +3657,14 @@ bool TypeChecker::visit(Identifier const& _identifier) | |||||||
| 				_identifier.location(), | 				_identifier.location(), | ||||||
| 				"\"suicide\" has been deprecated in favour of \"selfdestruct\"." | 				"\"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 ( | 	if ( | ||||||
|  | |||||||
| @ -311,6 +311,14 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall) | |||||||
| 
 | 
 | ||||||
| 	if (BuiltinFunction const* f = m_dialect.builtin(_funCall.functionName.name)) | 	if (BuiltinFunction const* f = m_dialect.builtin(_funCall.functionName.name)) | ||||||
| 	{ | 	{ | ||||||
|  | 		if (_funCall.functionName.name == "selfdestruct"_yulstring) | ||||||
|  | 			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; | 		parameterTypes = &f->parameters; | ||||||
| 		returnTypes = &f->returns; | 		returnTypes = &f->returns; | ||||||
| 		if (!f->literalArguments.empty()) | 		if (!f->literalArguments.empty()) | ||||||
|  | |||||||
| @ -2,4 +2,5 @@ contract C { | |||||||
|     function f() pure public { selfdestruct; } |     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. | // Warning 6133: (44-56): Statement has no effect. | ||||||
|  | |||||||
| @ -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. | // TypeError 9553: (69-70): Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested. | ||||||
|  | |||||||
| @ -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. | ||||||
|  | |||||||
| @ -19,3 +19,4 @@ contract C { | |||||||
|     receive() payable external {} |     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. | ||||||
|  | |||||||
| @ -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: (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: (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. | // TypeError 8961: (201-228): Function cannot be declared as view because this expression (potentially) modifies the state. | ||||||
|  | |||||||
| @ -85,6 +85,7 @@ contract C { | |||||||
| // ==== | // ==== | ||||||
| // EVMVersion: >=paris | // 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: (89-1716): Unreachable code. | ||||||
| // Warning 5740: (1729-1741): Unreachable code. | // Warning 5740: (1729-1741): Unreachable code. | ||||||
| // Warning 5740: (1754-1769): Unreachable code. | // Warning 5740: (1754-1769): Unreachable code. | ||||||
|  | |||||||
| @ -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. | // 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 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. | // TypeError 8961: (101-113): Function cannot be declared as pure because this expression (potentially) modifies the state. | ||||||
|  | |||||||
| @ -23,6 +23,7 @@ contract C { | |||||||
| // ==== | // ==== | ||||||
| // EVMVersion: >=london | // 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. | // 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: (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. | // TypeError 8961: (104-119): Function cannot be declared as view because this expression (potentially) modifies the state. | ||||||
|  | |||||||
| @ -2,3 +2,4 @@ | |||||||
| 	selfdestruct(0x02) | 	selfdestruct(0x02) | ||||||
| } | } | ||||||
| // ---- | // ---- | ||||||
|  | // Warning 1699: (3-15): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended. | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user