# EIP-7702 Set Code Tx Intro *2025.02.19* --- ## Agenda * About Me * tl;dr * Motivation * What & How? * Some examples --- ## About Me * Jeff aka FoodChain * zkmopro gpu acceleration (metal) * interested in zk & blockchain * ex-intern @NM --- ## tl;dr * EIP-7702 is included in Pectra * EIP-7702 is a better version of EIP-3074 * Introduces `Set Code Transaction` (`0x04`) * EOA -> set code tx -> Smart contract account --- ## Motivation 2 types of accounts: Externally Owned Account (EOA) Smart Contract Account (SCA) ---- ## AA 1. EOA can init tx; but cannot execute code. 2. SCA can execute code but not init tx. which means EOAs cannot do: * multisend * multi-sig recovery * custom authorization * USDC as gas fee The endgame RIP-7560 want to make all EOA -> AA (native AA) ---- ## EIP-3074 > 2020 ~ 2024 * New Opcodes * `AUTH`: auth an **invoker** (contract) to delegate EOA. * `AUTHCALL`: after `AUTH`, invoker use `AUTHCALL` to delegating the transactions for the orignal EOA. (multisend...) * Invoker: * The delegation contract that verify the signature & execute the calls ---- ## What's the problem with EIP-3074? * New Opcodes: * Too much work. * Invoker: * this separate another contract ecosystem from EIP-4337 ---- ## 3074 -> 7702 Vitalik [proposed 7702 to replace 3074](https://hackmd.io/@vbuterin/3074_via_tx_type). * introduce a new tx type instead of adding Opcodes * invoker -> delegation designator * `AUTH` -> `verify()` or `authorize()` * `AUTHCALL` -> `execute()` * allows EOAs to convert themselves into contracts. This is forward-compatible with ERC-4337; more native. --- ## What and How? There are four slots in Ethereum account ![image](https://hackmd.io/_uploads/SJHTXWy9kg.png =500x) The `contract_code` is empty in an EOA. ---- ## Transaction payload `eip-2718` transaction: ``` rlp([ chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, value, data, access_list, "authorization_list", signature_y_parity, signature_r, signature_s ]) ``` ---- ## Authorization List ``` authorization_list = [ [chain_id_1, address_1, nonce_1, y_parity_1, r_1, s_1], [chain_id_2, address_2, nonce_2, y_parity_2, r_2, s_2], ... ] ``` * address = delegation designator's address * `Delegation Designator` could be a customized contract (multi-sig recovery, passkey auth, etc); a ERC-4337 contract... ---- ## What does it mean? This sig means: "As an EOA, you authorized/allow some code to live in your account." ---- ## Some problem: EIP-3607 EIP-3607: "Bro, your account has code. You're not allowed to originate a tx!" ---- ## Delegation Designator * 23-bytes ![image](https://hackmd.io/_uploads/Syi4zGmqye.png) *cited from [Devcon video](https://www.youtube.com/watch?v=_k5fKlKBWV4)* ---- ![IMG_2542](https://hackmd.io/_uploads/Sk877HdIke.jpg) ---- ## When executing 1. EOA uses its pk to sign the transaction, it remains what it is before. 2. However, when someone "calls" EOA, EVM applies the bytecode on EOA to call. ---- 1. ![image](https://hackmd.io/_uploads/Skarcz9Yke.png) 2. ![image](https://hackmd.io/_uploads/ByPR5pb5kx.png) ---- ## Some examples ![image](https://hackmd.io/_uploads/rkP5SZ1cyg.png =600x) *cited from [jchaskin22](https://x.com/jchaskin22/status/1880253557926162841/photo/1)* --- ## Delegation Contract * [exp-0001](https://www.ithaca.xyz/writings/exp-0001) * [from ithaca](https://odyssey-explorer.ithaca.xyz/address/0x35202a6E6317F3CC3a177EeEE562D3BcDA4a6FcC?tab=contract) ---- ## an simple example to show the `set code tx` ``` anvil --odyssey export DEPLOYER_PK=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 export DEPLOYER_ADDR=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 export ALICE_PK=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d export ALICE_ADDR=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 ``` ``` forge create SimpleDelegateContract --private-key $DEPLOYER_PK --broadcast export DELEGATE=0x5FbDB2315678afecb367f032d93F642f64180aa3 ``` ``` cast code $ALICE_ADDR cast wallet sign-auth $DELEGATE --private-key $ALICE_PK export SIGNED_AUTH=$(cast wallet sign-auth $DELEGATE --private-key $ALICE_PK) cast send $(cast az) --private-key $DEPLOYER_PK --auth $SIGNED_AUTH cast tx 0xea54f6ba7a9b3dfeab7f79d6f11b335887931d77b44ec9e1610293f7473336e2 cast code $ALICE_ADDR ``` --- ### some questions? * Can an EOA delegate to multiple delegation? * No. * How to cancel delegation? * `address(0)` ``` cast code $ALICE_ADDR export SIGNED_AUTH=$(cast wallet sign-auth $(cast az) --private-key $ALICE_PK) cast send $(cast az) --private-key $DEPLOYER_PK --auth $SIGNED_AUTH cast code $ALICE_ADDR ``` * What if we want to delegate in multiple chains? * `chain_id = 0` --- # Thank you :smile:
{"title":"EIP-7702 Introduction (TEM sharing)","description":"EIP-7702 Introduction","contributors":"[{\"id\":\"ca82b36c-64ab-4b0e-b065-0d7a70717183\",\"add\":7787,\"del\":2102}]"}
    576 views