Skip to content
Open
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 docs/050-breaking-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ New version:
// To increase clarity, we suggest the use of a library for
// the conversion (provided after the contract in this example).
address payable addr = unknownContract.makePayable();
// This will report a warning
require(addr.send(1 ether));

// Since uint32 (4 bytes) is smaller than bytes8 (8 bytes),
Expand Down
5 changes: 3 additions & 2 deletions docs/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ of Solidity, you can use a special comment to annotate an assembly block as memo
...
}

Note that we will disallow the annotation via comment in a future breaking release; so, if you are not concerned with
backward-compatibility with older compiler versions, prefer using the dialect string.
.. warning::
The ``memory-safe-assembly`` special comment will be deprecated in the next breaking version (0.9).
So, if you are not concerned with backward-compatibility with older compiler versions, prefer using the dialect string.

Advanced Safe Use of Memory
---------------------------
Expand Down
3 changes: 3 additions & 0 deletions docs/common-patterns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ you receive the funds of the person who is now the richest.
// Remember to zero the pending refund before
// sending to prevent reentrancy attacks
pendingWithdrawals[msg.sender] = 0;
// This will report a warning
payable(msg.sender).transfer(amount);
}
}
Expand Down Expand Up @@ -84,6 +85,7 @@ This is as opposed to the more intuitive sending pattern:
function becomeRichest() public payable {
if (msg.value <= mostSent) revert NotEnoughEther();
// This line can cause problems (explained below).
// This will report a warning
richest.transfer(msg.value);
richest = payable(msg.sender);
mostSent = msg.value;
Expand Down Expand Up @@ -211,6 +213,7 @@ restrictions highly readable.

_;
if (msg.value > amount)
// This will report a warning
payable(msg.sender).transfer(msg.value - amount);
}

Expand Down
2 changes: 2 additions & 0 deletions docs/contracts/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ will consume more gas than the 2300 gas stipend:
you have to implement a receive Ether function (using payable fallback functions for receiving Ether is
not recommended, since the fallback is invoked and would not fail for interface confusions
on the part of the sender).
Note that ``send`` and ``transfer`` are scheduled to be deprecated in the next breaking version (0.9).


.. warning::
Expand Down Expand Up @@ -440,6 +441,7 @@ operations as long as there is enough gas passed on to it.

// If someone sends Ether to that contract,
// the transfer will fail, i.e. this returns false here.
// This will report a warning
return testPayable.send(2 ether);
}

Expand Down
5 changes: 5 additions & 0 deletions docs/contracts/inheritance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ and the ``override`` keyword must be used in the overriding modifier:

contract Base
{
// This will report a warning
modifier foo() virtual {_;}
}

Expand All @@ -411,11 +412,13 @@ explicitly:

contract Base1
{
// This will report a warning
modifier foo() virtual {_;}
}

contract Base2
{
// This will report a warning
modifier foo() virtual {_;}
}

Expand All @@ -424,6 +427,8 @@ explicitly:
modifier foo() override(Base1, Base2) {_;}
}

.. warning::
virtual modifiers will be deprecated in the next breaking version (0.9).


.. index:: ! constructor
Expand Down
2 changes: 2 additions & 0 deletions docs/control-structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ and ``assert`` for internal error checking.
function sendHalf(address payable addr) public payable returns (uint balance) {
require(msg.value % 2 == 0, "Even value required.");
uint balanceBeforeTransfer = address(this).balance;
// This will report a warning
addr.transfer(msg.value / 2);
// Since transfer throws an exception on failure and
// cannot call back here, there should be no way for us to
Expand Down Expand Up @@ -775,6 +776,7 @@ together with ``revert`` and the equivalent ``require``:
if (msg.sender != owner)
revert Unauthorized();

// This will report a warning
payable(msg.sender).transfer(address(this).balance);
}
}
Expand Down
5 changes: 5 additions & 0 deletions docs/examples/blind-auction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ to receive their Ether - contracts cannot activate themselves.
// msg.sender is not of type `address payable` and must be
// explicitly converted using `payable(msg.sender)` in order
// use the member function `send()`.
// This will report a warning
if (!payable(msg.sender).send(amount)) {
// No need to call throw here, just reset the amount owing
pendingReturns[msg.sender] = amount;
Expand Down Expand Up @@ -160,6 +161,7 @@ to receive their Ether - contracts cannot activate themselves.
emit AuctionEnded(highestBidder, highestBid);

// 3. Interaction
// This will report a warning
beneficiary.transfer(highestBid);
}
}
Expand Down Expand Up @@ -310,6 +312,7 @@ invalid bids.
// the same deposit.
bidToCheck.blindedBid = bytes32(0);
}
// This will report a warning
payable(msg.sender).transfer(refund);
}

Expand All @@ -323,6 +326,7 @@ invalid bids.
// conditions -> effects -> interaction).
pendingReturns[msg.sender] = 0;

// This will report a warning
payable(msg.sender).transfer(amount);
}
}
Expand All @@ -336,6 +340,7 @@ invalid bids.
if (ended) revert AuctionEndAlreadyCalled();
emit AuctionEnded(highestBidder, highestBid);
ended = true;
// This will report a warning
beneficiary.transfer(highestBid);
}

Expand Down
5 changes: 5 additions & 0 deletions docs/examples/micropayment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ The full contract
// this recreates the message that was signed on the client
bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this)));
require(recoverSigner(message, signature) == owner);
// This will report a warning
payable(msg.sender).transfer(amount);
}

Expand All @@ -195,6 +196,7 @@ The full contract
{
require(msg.sender == owner);
freeze();
// This will report a warning
payable(msg.sender).transfer(address(this).balance);
}

Expand Down Expand Up @@ -406,8 +408,10 @@ The full contract
require(msg.sender == recipient);
require(isValidSignature(amount, signature));

// This will report a warning
recipient.transfer(amount);
freeze();
// This will report a warning
sender.transfer(address(this).balance);
}

Expand All @@ -430,6 +434,7 @@ The full contract
{
require(block.timestamp >= expiration);
freeze();
// This will report a warning
sender.transfer(address(this).balance);
}

Expand Down
3 changes: 3 additions & 0 deletions docs/examples/safe-remote.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ you can use state machine-like constructs inside a contract.
// reentrancy-safe, because it is the
// last call in this function and we
// already changed the state.
// This will report a warning.
seller.transfer(address(this).balance);
}

Expand Down Expand Up @@ -128,6 +129,7 @@ you can use state machine-like constructs inside a contract.
// can call in again here.
state = State.Release;

// This will report a warning
buyer.transfer(value);
}

Expand All @@ -144,6 +146,7 @@ you can use state machine-like constructs inside a contract.
// can call in again here.
state = State.Inactive;

// This will report a warning
seller.transfer(3 * value);
}
}
7 changes: 5 additions & 2 deletions docs/layout-of-source-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,13 @@ select between the two implementations of the ABI encoder and decoder.
The new ABI coder (v2) is able to encode and decode arbitrarily nested
arrays and structs. Apart from supporting more types, it involves more extensive
validation and safety checks, which may result in higher gas costs, but also heightened
security. It is considered
non-experimental as of Solidity 0.6.0 and it is enabled by default starting
security.
It is considered non-experimental as of Solidity 0.6.0 and it is enabled by default starting
with Solidity 0.8.0. The old ABI coder can still be selected using ``pragma abicoder v1;``.

.. warning::
The ABI coder v1 will be deprecated in the next breaking version (0.9).

The set of types supported by the new encoder is a strict superset of
the ones supported by the old one. Contracts that use it can interact with ones
that do not without limitations. The reverse is possible only as long as the
Expand Down
3 changes: 3 additions & 0 deletions docs/security-considerations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ To give an example, the following code contains a bug (it is just a snippet and
mapping(address => uint) shares;
/// Withdraw your share.
function withdraw() public {
// This will report a warning
if (payable(msg.sender).send(shares[msg.sender]))
shares[msg.sender] = 0;
}
Expand Down Expand Up @@ -109,6 +110,7 @@ To avoid reentrancy, you can use the Checks-Effects-Interactions pattern as demo
function withdraw() public {
uint share = shares[msg.sender];
shares[msg.sender] = 0;
// This will report a warning
payable(msg.sender).transfer(share);
}
}
Expand Down Expand Up @@ -255,6 +257,7 @@ Let's say you have a wallet contract like this:
function transferTo(address payable dest, uint amount) public {
// THE BUG IS RIGHT HERE, you must use msg.sender instead of tx.origin
require(tx.origin == owner);
// This will report a warning
dest.transfer(amount);
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/types/reference-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ shown in the following example:
return false;
uint amount = c.amount;
c.amount = 0;
// This will report a warning
c.beneficiary.transfer(amount);
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions docs/types/value-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ reverts on failure.
.. note::
If ``x`` is a contract address, its code (more specifically: its :ref:`receive-ether-function`, if present, or otherwise its :ref:`fallback-function`, if present) will be executed together with the ``transfer`` call (this is a feature of the EVM and cannot be prevented). If that execution runs out of gas or fails in any way, the Ether transfer will be reverted and the current contract will stop with an exception.

.. warning::
``transfer`` will be deprecated in the next breaking version (0.9).

* ``send``

``send`` is the low-level counterpart of ``transfer``. If the execution fails, the current contract will not stop with an exception, but ``send`` will return ``false``.
Expand All @@ -270,6 +273,7 @@ reverts on failure.
(this can always be forced by the caller) and it also fails if the recipient runs out of gas. So in order
to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better:
use a pattern where the recipient withdraws the Ether.
Please, be aware that ``send`` will be deprecated in the next breaking version (0.9).

* ``call``, ``delegatecall`` and ``staticcall``

Expand Down
5 changes: 5 additions & 0 deletions libsolidity/analysis/DocStringTagParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ bool DocStringTagParser::visit(InlineAssembly const& _assembly)
"otherwise only use the NatSpec tag."
);
_assembly.annotation().markedMemorySafe = true;
m_errorReporter.warning(
2424_error,
_assembly.location(),
"Natspec memory safe annotation for inline assembly will be deprecated in the next breaking version."
);
}
else
m_errorReporter.warning(
Expand Down
11 changes: 11 additions & 0 deletions libsolidity/analysis/SyntaxChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ bool SyntaxChecker::visit(PragmaDirective const& _pragma)
);
else
m_sourceUnit->annotation().useABICoderV2 = (_pragma.literals()[1] == "v2");

if (_pragma.literals().size() > 1 && _pragma.literals()[1] == "v1")
m_errorReporter.warning(
9511_error,
_pragma.location(),
"ABI coder v1 will be deprecated in the next breaking version."
);
}
else if (_pragma.literals()[0] == "solidity")
{
Expand Down Expand Up @@ -184,6 +191,10 @@ void SyntaxChecker::endVisit(ModifierDefinition const& _modifier)
{
if (_modifier.isImplemented() && !m_placeholderFound)
m_errorReporter.syntaxError(2883_error, _modifier.body().location(), "Modifier body does not contain '_'.");

if (_modifier.markedVirtual())
m_errorReporter.warning(8429_error, _modifier.location(), "Virtual modifiers will be deprecated in the next breaking version.");

m_placeholderFound = false;
}

Expand Down
23 changes: 23 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,16 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
)
);
}
if (
TokenTraits::isCompareOp(_operation.getOperator()) &&
commonType->category() == Type::Category::Contract
)
m_errorReporter.warning(
9170_error,
_operation.location(),
"Comparison of variables of contract type will be deprecated in the next breaking version."
"Consider using an explicit cast to address type."
);
}

Type const* TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
Expand Down Expand Up @@ -3212,6 +3222,19 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
if (contractType && contractType->isSuper())
requiredLookup = VirtualLookup::Super;
}

if (
funType->kind() == FunctionType::Kind::Send ||
funType->kind() == FunctionType::Kind::Transfer
)
m_errorReporter.warning(
9207_error,
_memberAccess.location(),
fmt::format(
"{} will be deprecated in the next breaking version.",
funType->kind() == FunctionType::Kind::Send ? "send" : "transfer"
)
);
}

annotation.requiredLookup = requiredLookup;
Expand Down
6 changes: 6 additions & 0 deletions test/cmdlineTests/model_checker_targets_all_all_engines/err
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Warning: transfer will be deprecated in the next breaking version.
--> input.sol:10:3:
|
10 | a.transfer(x);
| ^^^^^^^^^^

Warning: CHC: Underflow (resulting value less than 0) happens here.
Counterexample:
arr = []
Expand Down
6 changes: 6 additions & 0 deletions test/cmdlineTests/model_checker_targets_all_bmc/err
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Warning: transfer will be deprecated in the next breaking version.
--> input.sol:10:3:
|
10 | a.transfer(x);
| ^^^^^^^^^^

Warning: BMC: Condition is always true.
--> input.sol:6:11:
|
Expand Down
6 changes: 6 additions & 0 deletions test/cmdlineTests/model_checker_targets_all_chc/err
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Warning: transfer will be deprecated in the next breaking version.
--> input.sol:10:3:
|
10 | a.transfer(x);
| ^^^^^^^^^^

Warning: CHC: Underflow (resulting value less than 0) happens here.
Counterexample:
arr = []
Expand Down
6 changes: 6 additions & 0 deletions test/cmdlineTests/model_checker_targets_assert_bmc/err
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Warning: transfer will be deprecated in the next breaking version.
--> input.sol:10:3:
|
10 | a.transfer(x);
| ^^^^^^^^^^

Warning: BMC: Assertion violation happens here.
--> input.sol:11:3:
|
Expand Down
6 changes: 6 additions & 0 deletions test/cmdlineTests/model_checker_targets_assert_chc/err
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Warning: transfer will be deprecated in the next breaking version.
--> input.sol:10:3:
|
10 | a.transfer(x);
| ^^^^^^^^^^

Warning: CHC: Assertion violation happens here.
Counterexample:
arr = []
Expand Down
Loading