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

Add .exists() and .iscontract() on to the address type #4910

Open
axic opened this issue Sep 5, 2018 · 13 comments
Open

Add .exists() and .iscontract() on to the address type #4910

axic opened this issue Sep 5, 2018 · 13 comments
Labels
language design :rage4: Any changes to the language, e.g. new features

Comments

@axic
Copy link
Member

axic commented Sep 5, 2018

Not fully sure yet if .exists() can be implemented properly, but .iscontract() should be possible to be implemented via the extcodesize instruction.

With having .iscontract(), #4823 would not need to be implemented.

@axic axic added the feature label Sep 5, 2018
@axic axic changed the title Add .exists and .iscontract on to the address type Add .exists() and .iscontract() on to the address type Sep 5, 2018
@frangio
Copy link
Contributor

frangio commented Sep 5, 2018

What would be the semantics of .exists()?

@axic
Copy link
Member Author

axic commented Sep 5, 2018

.exists() probably should be postponed until there is a consensus on what that means in Ethereum, however when looking at the account cleanup rules during creation/selfdestruct/etc. should be a good indication.

I actually don't think this can be done properly without support form a new EVM opcode, because one could check for balance and code size, but cannot check for storage, which is possible to be non-empty if the account is only used through delegatecalls.

@wadealexc
Copy link
Contributor

I would be cautious of any implementation of .iscontract() -- the whole idea of testing iscontract has led to lots of contracts vulnerable to exploits done by constructors

@axic
Copy link
Member Author

axic commented Sep 25, 2018

Actually it seems that .iscontract() could be implemented by just using extcodehash.

@axic
Copy link
Member Author

axic commented Dec 13, 2019

.exists() can be clearly implemented post Constantinople, because EIP-1052 for EXTCODEHASH clearly defines it:

In case the account does not exist or is empty (as defined by EIP-161) 0 is pushed to the stack.

From EIP-161:

An account is considered empty when it has no code and zero nonce and zero balance.

Similarly .iscontract() is clearly defined with EIP-1052:

In case the account does not have code the keccak256 hash of empty data (i.e. c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) is pushed to the stack.

@axic
Copy link
Member Author

axic commented Apr 5, 2020

@frangio @wadealexc any change of view since these are provided by opcodes now?

@wadealexc
Copy link
Contributor

Since EXTCODEHASH returns a nonzero value during the constructor, this seems fine on the surface.

@frangio
Copy link
Contributor

frangio commented Apr 7, 2020

I don't think that really mitigates the vulnerabilities that can arise from using .isContract(), because an account can pass the EXTCODEHASH test but still become a contract in the future.

We do have an isContract function in OpenZeppelin though, because some ERCs require using it. So I think I would be okay with including it in Solidity. But it needs to be used carefully.

@chriseth
Copy link
Contributor

chriseth commented Apr 7, 2020

Would calling it hasCode help in any way?

@axic
Copy link
Member Author

axic commented Apr 7, 2020

I don't think that really mitigates the vulnerabilities that can arise from using .isContract(), because an account can pass the EXTCODEHASH test but still become a contract in the future.

Are we making commitments in the language that a property of an account in the state cannot ever change? 😉

@frangio Could you elaborate this sentence?

@axic axic added the language design :rage4: Any changes to the language, e.g. new features label Oct 30, 2020
@github-actions
Copy link

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Feb 22, 2023
@github-actions
Copy link

github-actions bot commented Mar 1, 2023

Hi everyone! This issue has been automatically closed due to inactivity.
If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen.
However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.

@github-actions github-actions bot added the closed due inactivity The issue/PR was automatically closed due to inactivity. label Mar 1, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2023
@axic
Copy link
Member Author

axic commented Sep 4, 2024

This would become very useful in conjunction with ethereum/EIPs#8838

On non-EOF targets it could fallback to extcodesize/extcodehash.

@axic axic reopened this Sep 4, 2024
@github-actions github-actions bot removed closed due inactivity The issue/PR was automatically closed due to inactivity. stale The issue/PR was marked as stale because it has been open for too long. labels Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language design :rage4: Any changes to the language, e.g. new features
Projects
None yet
Development

No branches or pull requests

5 participants