devnet-5: Update EIP-7702: Remove delegation behavior of EXTCODE* (#2871)

This commit is contained in:
andri lim 2025-01-15 21:30:26 +07:00 committed by GitHub
parent 5c02b88f82
commit 232a9ad247
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 10 deletions

View File

@ -20,11 +20,14 @@ import
eth/common/keys
const
# the last 0x00 is the version
DelegationPrefix = [0xef.byte, 0x01, 0x00]
const
PER_AUTH_BASE_COST* = 12500
PER_EMPTY_ACCOUNT_COST* = 25000
EIP7702_MAGIC_BYTES* = [0xef.byte, 0x01]
EIP7702_MAGIC_HASH* = hash32"eadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329"
func authority*(auth: Authorization): Opt[Address] =
const SECP256K1halfN = SECPK1_N div 2
@ -73,3 +76,8 @@ func parseDelegationAddress*(code: CodeBytesRef): Opt[Address] =
return Opt.none(Address)
Opt.some(Address(slice[20](code, 3, 22)))
func isEip7702*(code: CodeBytesRef): bool =
if code.len != 23:
return false
code.hasPrefix(DelegationPrefix)

View File

@ -504,9 +504,10 @@ proc getCodeSize*(ac: LedgerRef, address: Address): int =
proc resolveCodeHash*(ac: LedgerRef, address: Address): Hash32 =
let (codeHash, code) = ac.getCode(address, true)
let delegateTo = parseDelegationAddress(code).valueOr:
return codeHash
ac.getCodeHash(delegateTo)
if code.isEip7702:
EIP7702_MAGIC_HASH
else:
codeHash
proc resolveCode*(ac: LedgerRef, address: Address): CodeBytesRef =
let code = ac.getCode(address)
@ -516,9 +517,10 @@ proc resolveCode*(ac: LedgerRef, address: Address): CodeBytesRef =
proc resolveCodeSize*(ac: LedgerRef, address: Address): int =
let code = ac.getCode(address)
let delegateTo = parseDelegationAddress(code).valueOr:
return code.len
ac.getCodeSize(delegateTo)
if code.isEip7702:
EIP7702_MAGIC_BYTES.len
else:
code.len
proc getDelegateAddress*(ac: LedgerRef, address: Address): Address =
let code = ac.getCode(address)

View File

@ -155,8 +155,7 @@ proc extCodeSizeEIP2929Op(cpt: VmCpt): EvmResultVoid =
proc extCodeSizeEIP7702Op(cpt: VmCpt): EvmResultVoid =
## 0x3b, Get size of an account's code (EIP-7702)
template ecsEIP7702(address): auto =
let gasCost = cpt.gasEip2929AccountCheck(address) +
cpt.gasEip7702CodeCheck(address)
let gasCost = cpt.gasEip2929AccountCheck(address)
? cpt.opcodeGasCost(ExtCodeSize, gasCost, reason = "ExtCodeSize EIP7702")
cpt.resolveCodeSize(address)
@ -265,8 +264,7 @@ proc extCodeHashEIP2929Op(cpt: VmCpt): EvmResultVoid =
proc extCodeHashEIP7702Op(cpt: VmCpt): EvmResultVoid =
## 0x3f, Returns the keccak256 hash of a contracts code (EIP-7702)
template echEIP7702(address): auto =
let gasCost = cpt.gasEip2929AccountCheck(address) +
cpt.gasEip7702CodeCheck(address)
let gasCost = cpt.gasEip2929AccountCheck(address)
? cpt.opcodeGasCost(ExtCodeHash, gasCost, reason = "ExtCodeHash EIP7702")
cpt.resolveCodeHash(address)
cpt.stack.unaryAddress(echEIP7702)