Skip to content

Commit

Permalink
Issue warning when using deprecated SELFDESTRUCT
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-matic committed Jan 20, 2023
1 parent c195782 commit 698353a
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
8 changes: 8 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3642,6 +3642,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 be removed from the EVM, "
"and its use in new contracts is not recommended."
);
}

if (
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 be removed from the EVM, and its use in new contracts 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 be removed from the EVM, and its use in new contracts 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 be removed from the EVM, and its use in new contracts 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 be removed from the EVM, and its use in new contracts 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 be removed from the EVM, and its use in new contracts 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

0 comments on commit 698353a

Please sign in to comment.