mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-28 21:16:29 +00:00
devnet-5: Update EIP-7702: Remove delegation behavior of EXTCODE* (#2871)
This commit is contained in:
parent
5c02b88f82
commit
232a9ad247
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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 contract’s 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user