-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Remove Address.isContract #3945
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
Changes from 5 commits
acd97fd
a87bd43
81667ae
26863ed
8ad9f9f
df7ff46
aa1a158
3e9c380
c484d04
0fb4423
23b8f57
95799e9
7981474
ba6ca20
300f4ff
f8d0f40
46d68bf
e697766
33b55af
91802e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,40 +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 | ||
* ==== | ||
* | ||
* [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. | ||
* ==== | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a new file at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check the new doc page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of "FAQ" as the title for the section? Or you can check how I did it and if it can remain like that, no problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes FAQ works. |
||
*/ | ||
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. | ||
|
@@ -196,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 { | ||
|
Uh oh!
There was an error while loading. Please reload this page.