Skip to content

Utility to determine if an address is an EOA #5676

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

Closed
pcaversaccio opened this issue May 9, 2025 · 4 comments · Fixed by #5587
Closed

Utility to determine if an address is an EOA #5676

pcaversaccio opened this issue May 9, 2025 · 4 comments · Fixed by #5587

Comments

@pcaversaccio
Copy link
Contributor

pcaversaccio commented May 9, 2025

I was wondering if it makes sense to have a utility function that can determine if an address is an EOA. With EIP-7702 we have now also (0xef0100 || address) as code for an EOA. So the function could check if the code length is either zero or the first 3 bytes is ef_01_00. I haven't thought this completely through, but dropping this as an idea here for now.

bytes3 internal constant _DELEGATION_PREFIX = 0xef0100;
function isEOA(address target) internal view returns (bool) {
    bytes memory code = target.code;
    // Add here a comment addressing the normal disclaimers around
    // construction-time issues and zero-length contracts.
    return (code.length == 0 || bytes3(code) == _DELEGATION_PREFIX);
}

The reason why I don't check for the length of 23 bytes is that you cannot deploy a contract starting with 0xef according to EIP-3541.

@ernestognw
Copy link
Member

Sounds like a great idea @pcaversaccio. The delegation prefix 0xef00 should be unambiguous given EIP-3541.
Even if an EOA delegates to an empty contract (not sure if possible) should work

@frangio
Copy link
Contributor

frangio commented May 15, 2025

I think there's utility in a function to confirm that an account is EIP-7702 delegated and to get the delegation target (this is useful for paymasters IIUC), but this is not what's proposed here. What would be the use of checking if an account is an EOA like this issue proposes?

@pcaversaccio
Copy link
Contributor Author

pcaversaccio commented May 15, 2025

One example use case could be this line:

You can argue this is still accepted pattern as it's now a a smart contract wallet and not a "simple" EOA anymore. The delegation contracts like the one from MM (https://etherscan.io/address/0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B#code) will return a valid EIP-1271 magic for such case.

Another one could be here:

So the question is how to deal with .code.length == 0 checks after delegation and if isEOA would be useful to have here.

@ernestognw
Copy link
Member

ernestognw commented May 16, 2025

You can argue this is still accepted pattern as it's now a a smart contract wallet and not a "simple" EOA anymore.

Yes, this would be my main argument. Users sign a delegation message that literally means "execute this code in my EOA's context", and that's the way it should be treated IMO. If they delegated to a contract that doesn't implement 1271, then wasn't that their intention? They can always redelegate to a contract that does implement ERC1271 and will be ready to go. No harm to anyone. (Just as recommended by default in Wizard, though)

On the other hand, I would argue that using an isEOA utility is overkill, the protocol should already be designed with considerations about code.length == 0. Delegated contracts should behave no differently, and IMO current protocols have no reasons to implement this check (new ones may, but I feel everyone is overthinking it).

So the question is how to deal with .code.length == 0 checks after delegation and if isEOA would be useful to have here.

Right, I'm looking for an actual use case because other than that, the current assumptions in smart contracts about empty addresses should remain. For protocols there's conceptually no difference in how accounts are interacting with them

@ernestognw ernestognw linked a pull request May 27, 2025 that will close this issue
3 tasks
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

Successfully merging a pull request may close this issue.

3 participants