vyper icon indicating copy to clipboard operation
vyper copied to clipboard

add new built-in/stdlib function `is_eoa`

Open pcaversaccio opened this issue 7 months ago • 4 comments

I think it would be beneficial to have a built-in or stdlib function is_eoa 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. A simple Vyper implementation for a stdlib called address looks like this:

_DELEGATION_PREFIX: constant(bytes3) = 0xef0100

@internal
def is_eoa(target: address) -> bool:
    code: Bytes[3] = slice(target.code, 0, 3)
    return (len(code) == 0 or convert(code, bytes3) == _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.

pcaversaccio avatar May 12 '25 16:05 pcaversaccio

Big fan of stdlib approach personally, makes it easier to audit & add functions in the future as well. From what I've heard Vyper already has an stdlib somewhere? is that so?

Philogy avatar May 12 '25 16:05 Philogy

Big fan of stdlib approach personally, makes it easier to audit & add functions in the future as well. From what I've heard Vyper already has an stdlib somewhere? is that so?

https://github.com/vyperlang/vyper/commit/1591a1229cf837ccca6cfcc32aed601ce19fad44

charles-cooper avatar May 12 '25 18:05 charles-cooper

We could also have an additional stdlib function fetch_delegate; similar to here.

pcaversaccio avatar Jun 02 '25 08:06 pcaversaccio

fwiw, I added a utility function to 🐍 snekmate that allows you to fetch the EIP-7702 delegation contract address: https://github.com/pcaversaccio/snekmate/pull/335.

pcaversaccio avatar Jul 22 '25 13:07 pcaversaccio