# EIP-7702 explanation ## Geth PRs - https://github.com/ethereum/go-ethereum/pull/29431 - https://github.com/ethereum/go-ethereum/pull/30571 ## Key takeaways 1. Introduce a new transaction type: `setCodeTx` 2. `setCodeTx` includes an `AuthList`, which defines delegations for EOAs 3. With delegations, EOAs can function like smart contract accounts 4. Delegations can be revoked/updated 5. When executing transactions, if `msg.to` refers to an EOA with a delegation, the contract byteCode from the delegation address will be used ## Illustration ### Structure of setCodeTx ![Structure of tx](https://hackmd.io/_uploads/H12fcfehyg.png) The only difference between an eip1559 tx and a `setCodeTx` is that setCodeTx includes an `AuthList` which defines delegations for EOAs. ### How to transform an EOA into a contract account(CA) #### Step 1: Setting code for the EOA ![step1 of transformation](https://hackmd.io/_uploads/BkXiiQlhkx.png) A `setCodeTx` can be sent by bundlers, meaning that the EOA 0x9a..f2 doesn't need to have a positive balance. `0xef` is a banned opcode in [eip-3541](https://eips.ethereum.org/EIPS/eip-3541), which means a contract whose byteCode starts with `0xef` cannot be deployed on chain. Here `0xef` is used to indicate that the byteCode is a delegation reference rather than actual contract byteCode. After`setCodeTx`, the byteCode of EOA is no longer empty. #### Step 2 ![step2 of transformation](https://hackmd.io/_uploads/SyURs7x3yg.png) Traditionally a smart contract is deployed with `initCode`. After the deployment `byteCode` of the contract is set. Meanwhile the storage slots of the contract is initialized. However, `setCodeTx` only sets the `byteCode` but doesn't perform initialization. Therefore, an additional init tx is required. The init tx should include signature of the EOA and necessary paramters for contract setup. Once again NOTICE: EOA does'nt call contract 0x12..34 directly. Instead, the bytecode of contract 0x12..34 is set into the EOA and then is used to initialize a new contract instance during execution. The address of the new contract instance is EOA's address, which means the EOA has been transformed successfully ### How to execute a tx when tx.to refers to a transformed EOA (This flow also applies to the init tx mentioned above) 1. Retrieve the byteCode associated with the EOA address 2. Resolve the byteCode - Since the byteCode starts with `0xef0100`m it's recognized as a delegation - Trim the delegation prefix to extract the delegation address 4. Retrieve the actual contract byteCode from the resolved address 5. Initialize a contract instance with the byteCode of resolved address and the address of the EOA 6. Execute the contract call, treating the EOA as a smart contract