-
Notifications
You must be signed in to change notification settings - Fork 837
Implement pectra devnet-5 spec #3807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
f290abe
85e937a
3525a19
4800a9f
d4e9496
caa9e1c
74a2123
7f5c4c5
13aafd6
fc3c150
fb7e67f
98806ff
5079664
c827859
e4adff7
34a4882
3938e7f
b665335
eadbf2c
e2b355a
4b863bf
a178857
4a9b0c2
b195bbb
df63978
90fc63a
3d1a61f
f0dbc53
cf39093
14fc7b9
737c60b
b06737b
5abc991
8535e2c
17038a3
bd18a48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| concatBytes, | ||
| equalsBytes, | ||
| getVerkleTreeIndicesForStorageSlot, | ||
| hexToBytes, | ||
| setLengthLeft, | ||
| } from '@ethereumjs/util' | ||
| import { keccak256 } from 'ethereum-cryptography/keccak.js' | ||
|
|
@@ -61,16 +62,40 @@ | |
|
|
||
| export type OpHandler = SyncOpHandler | AsyncOpHandler | ||
|
|
||
| // TODO: verify that this is the correct designator | ||
| // The PR https://github.com/ethereum/EIPs/pull/8969 has two definitions of the | ||
| // designator: the original (0xef0100) and the designator added in the changes (0xef01) | ||
| const eip7702Designator = hexToBytes('0xef01') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just confirming my thinking. These only get computed once at run time, right? They aren't recomputed every single time we access this code are they?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only computed once! Can also move it somewhere else like |
||
| const eip7702HashBigInt = bytesToBigInt(keccak256(eip7702Designator)) | ||
|
|
||
| function getEIP7702DelegatedAddress(code: Uint8Array) { | ||
| if (equalsBytes(code.slice(0, 3), DELEGATION_7702_FLAG)) { | ||
| return new Address(code.slice(3, 24)) | ||
| } | ||
| } | ||
|
|
||
| async function eip7702CodeCheck(runState: RunState, code: Uint8Array) { | ||
| /** | ||
| * This method performs checks to transform the code which the EVM observes regarding EIP-7702. | ||
| * If the code is 7702-delegated code, it will retrieve the code of the designated address | ||
| * in case of an executable operation (`isReadOperation` == false), or the 7702 designator | ||
| * code in case of a read operation | ||
| * @param runState | ||
| * @param code | ||
| * @param isReadOperation Boolean to determine if the target code is meant to be read or executed (default: `false`) | ||
| * @returns | ||
| */ | ||
| async function eip7702CodeCheck( | ||
| runState: RunState, | ||
| code: Uint8Array, | ||
| isReadOperation: boolean = false, | ||
| ) { | ||
| const address = getEIP7702DelegatedAddress(code) | ||
| if (address !== undefined) { | ||
| return runState.stateManager.getCode(address) | ||
| if (isReadOperation) { | ||
| return eip7702Designator | ||
| } else { | ||
| return runState.stateManager.getCode(address) | ||
| } | ||
| } | ||
|
|
||
| return code | ||
|
|
@@ -538,7 +563,7 @@ | |
| runState.stack.push(BigInt(EOFBYTES.length)) | ||
| return | ||
| } else if (common.isActivatedEIP(7702)) { | ||
| code = await eip7702CodeCheck(runState, code) | ||
| code = await eip7702CodeCheck(runState, code, true) | ||
| } | ||
|
|
||
| const size = BigInt(code.length) | ||
|
|
@@ -560,7 +585,7 @@ | |
| // In legacy code, the target code is treated as to be "EOFBYTES" code | ||
| code = EOFBYTES | ||
| } else if (common.isActivatedEIP(7702)) { | ||
| code = await eip7702CodeCheck(runState, code) | ||
| code = await eip7702CodeCheck(runState, code, true) | ||
| } | ||
|
|
||
| const data = getDataSlice(code, codeOffset, dataLength) | ||
|
|
@@ -587,13 +612,8 @@ | |
| } else if (common.isActivatedEIP(7702)) { | ||
| const possibleDelegatedAddress = getEIP7702DelegatedAddress(code) | ||
| if (possibleDelegatedAddress !== undefined) { | ||
| const account = await runState.stateManager.getAccount(possibleDelegatedAddress) | ||
| if (!account || account.isEmpty()) { | ||
| runState.stack.push(BIGINT_0) | ||
| return | ||
| } | ||
|
|
||
| runState.stack.push(BigInt(bytesToHex(account.codeHash))) | ||
| // The account is delegated by an EIP-7702 tx. Push the EIP-7702 designator hash to the stack | ||
| runState.stack.push(eip7702HashBigInt) | ||
| return | ||
| } else { | ||
| runState.stack.push(bytesToBigInt(keccak256(code))) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.