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

isContract() Implementation is no longer valid #3355

Closed
tina1998612 opened this issue Apr 25, 2022 · 4 comments
Closed

isContract() Implementation is no longer valid #3355

tina1998612 opened this issue Apr 25, 2022 · 4 comments

Comments

@tina1998612
Copy link

tina1998612 commented Apr 25, 2022

It was recently discovered that the account.code.length > 0 assertion for checking if an account is EOA is not valid. It can be exploited as shown in here: https://github.com/0xKitsune/Ghost-Contract

As demonstrated in this repo, a contract can use the CREATE opcode and execute an arbitrary payload, which can call another contract, transfer funds or anything else that a normal contract can do. When using this approach to call another contract, because the execution of this logic is within the constructor, the codesize of the msg.sender is 0.

One can use tx.origin == msg.sender to check whether the msg.sender is EOA. The isContract() method may need to be removed to avoid confusion.

Current implemetation:

return account.code.length > 0;

@StillFantastic
Copy link
Contributor

I think it is mentioned in the document to be careful with that case.

* 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

#1212 also discussed the drawback of tx.origin approach.

@tina1998612
Copy link
Author

hmm I see, it's still a bit misleading with the naming.

@Amxx Amxx closed this as completed Apr 26, 2022
@frank890417
Copy link

Agree with @tina1998612 that isContract should consider cases like "a contract in construction", or it is not aligned with its function name and cannot help developers to avoid ghost contract calls.

@Amxx
Copy link
Collaborator

Amxx commented May 16, 2022

This as been discussed numerous times already:

  • The isContract function is necessary for some operation such as ERC721 & ERC1155 safeTransfer hooks.
  • Limitation of the isConstract function are clearly and extensively documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants