Remove Address.isContract (#3945)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
@ -7,44 +7,6 @@ pragma solidity ^0.8.1;
|
||||
* @dev Collection of functions related to the address type
|
||||
*/
|
||||
library Address {
|
||||
/**
|
||||
* @dev Returns true if `account` is a contract.
|
||||
*
|
||||
* [IMPORTANT]
|
||||
* ====
|
||||
* It is unsafe to assume that an address for which this function returns
|
||||
* false is an externally-owned account (EOA) and not a contract.
|
||||
*
|
||||
* Among others, `isContract` will return false for the following
|
||||
* types of addresses:
|
||||
*
|
||||
* - an externally-owned account
|
||||
* - a contract in construction
|
||||
* - an address where a contract will be created
|
||||
* - an address where a contract lived, but was destroyed
|
||||
*
|
||||
* Furthermore, `isContract` will also return true if the target contract within
|
||||
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
|
||||
* which only has an effect at the end of a transaction.
|
||||
* ====
|
||||
*
|
||||
* [IMPORTANT]
|
||||
* ====
|
||||
* You shouldn't rely on `isContract` to protect against flash loan attacks!
|
||||
*
|
||||
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
|
||||
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
|
||||
* constructor.
|
||||
* ====
|
||||
*/
|
||||
function isContract(address account) internal view returns (bool) {
|
||||
// This method relies on extcodesize/address.code.length, which returns 0
|
||||
// for contracts in construction, since the code is only stored at the end
|
||||
// of the constructor execution.
|
||||
|
||||
return account.code.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
|
||||
* `recipient`, forwarding all available gas and reverting on errors.
|
||||
@ -200,9 +162,9 @@ library Address {
|
||||
) internal view returns (bytes memory) {
|
||||
if (success) {
|
||||
if (returndata.length == 0) {
|
||||
// only check isContract if the call was successful and the return data is empty
|
||||
// only check if target is a contract if the call was successful and the return data is empty
|
||||
// otherwise we already know that it was a contract
|
||||
require(isContract(target), "Address: call to non-contract");
|
||||
require(target.code.length > 0, "Address: call to non-contract");
|
||||
}
|
||||
return returndata;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user