Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue warning when using deprecated SELFDESTRUCT #13884

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions docs/contracts/function-modifiers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
4 changes: 3 additions & 1 deletion docs/contracts/inheritance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -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); }
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/micropayment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions docs/introduction-to-smart-contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
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::
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.
Expand Down
8 changes: 5 additions & 3 deletions docs/units-and-global-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,13 @@ Contract Related
- 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.




Furthermore, all functions of the current contract are callable directly including the current function.
nikola-matic marked this conversation as resolved.
Show resolved Hide resolved

.. 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::
Prior to version 0.5.0, there was a function called ``suicide`` with the same
semantics as ``selfdestruct``.
Expand Down
6 changes: 6 additions & 0 deletions docs/yul.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)) |
+-------------------------+-----+---+-----------------------------------------------------------------+
| selfdestruct(a) | `-` | F | end execution, destroy current contract and send funds to a |
| | | | (deprecated) |
+-------------------------+-----+---+-----------------------------------------------------------------+
| invalid() | `-` | F | end execution with invalid instruction |
+-------------------------+-----+---+-----------------------------------------------------------------+
Expand Down Expand Up @@ -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
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:

datasize, dataoffset, datacopy
Expand Down
8 changes: 8 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 8 additions & 0 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)

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;
returnTypes = &f->returns;
if (!f->literalArguments.empty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/libyul/yulSyntaxTests/selfdestruct.yul
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
selfdestruct(0x02)
cameel marked this conversation as resolved.
Show resolved Hide resolved
}
// ----
// Warning 1699: (3-15): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended.