-
Notifications
You must be signed in to change notification settings - Fork 772
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
Implement pectra devnet-5 spec #3807
Draft
jochem-brouwer
wants to merge
18
commits into
master
Choose a base branch
from
devnet-5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f290abe
evm: add devnet-5 EIP-7702 changes
jochem-brouwer 85e937a
vm: add devnet-5 EIP-7685 changes
jochem-brouwer 3525a19
monorepo: make cspell happy
jochem-brouwer 4800a9f
vm/client: fix tests
jochem-brouwer d4e9496
evm: remove redundant test
jochem-brouwer caa9e1c
remove accidental console.log
jochem-brouwer 74a2123
remove 7742 and add 7691 independently
g11tech 7f5c4c5
fix t8ntool empty requests reporting
jochem-brouwer 13aafd6
client: fix engine reporting empty requests
jochem-brouwer fc3c150
t8n: fix requests reporting
jochem-brouwer fb7e67f
Implement EIP 7623: calldata cost increase (#3813)
jochem-brouwer 98806ff
client: fix requests contract address (devnet-5) (#3818)
lucassaldanha 5079664
update chainid to uint256
jochem-brouwer c827859
evm: update bls gas (eips PR 9097)
jochem-brouwer e4adff7
evm: bls update msm gas (eips PR 9116)
jochem-brouwer 34a4882
evm: bls update pairing gas (eips PR 9098)
jochem-brouwer 3938e7f
evm: rename bls files and remove g1mul, g2mul (eips PR 8945)
jochem-brouwer b665335
Merge branch 'master' into devnet-5
jochem-brouwer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { Common, Hardfork, Mainnet } from '@ethereumjs/common' | ||
import { | ||
Address, | ||
bytesToBigInt, | ||
equalsBytes, | ||
hexToBytes, | ||
setLengthRight, | ||
unprefixedHexToBytes, | ||
} from '@ethereumjs/util' | ||
import { keccak256 } from 'ethereum-cryptography/keccak' | ||
import { assert, describe, it } from 'vitest' | ||
|
||
import { createEVM } from '../../src/index.js' | ||
|
||
const eip7702Designator = hexToBytes('0xef01') | ||
const addressHex = '01'.repeat(20) // Address as unprefixed hex string | ||
const address = new Address(unprefixedHexToBytes(addressHex)) | ||
|
||
const delegationCode = hexToBytes('0xef0100' + addressHex) // This code will delegate to `address` | ||
|
||
// Helpers for unprefixed hex strings of opcodes | ||
const EXTCODESIZE = '3B' | ||
const EXTCODECOPY = '3C' | ||
const EXTCODEHASH = '3F' | ||
|
||
// This code stores the topmost stack item in slot 0 | ||
const STORE_TOP_STACK_CODE = '5F55' | ||
|
||
// This code pushes the `address` to the stack | ||
const PUSH_Address = '73' + addressHex // PUSH20 <address> as unprefixed hex string | ||
|
||
const testCodeAddress = new Address(unprefixedHexToBytes('02'.repeat(20))) | ||
|
||
// Setups EVM with an account at `address` which is delegated to itself | ||
async function getEVM() { | ||
const common = new Common({ | ||
chain: Mainnet, | ||
hardfork: Hardfork.Prague, | ||
}) | ||
const evm = await createEVM({ | ||
common, | ||
}) | ||
await evm.stateManager.putCode(address, delegationCode) | ||
return evm | ||
} | ||
|
||
describe('EIP 7702 tests', () => { | ||
it('EXTCODESIZE', async () => { | ||
const evm = await getEVM() | ||
const code = unprefixedHexToBytes(PUSH_Address + EXTCODESIZE + STORE_TOP_STACK_CODE) | ||
await evm.stateManager.putCode(testCodeAddress, code) | ||
|
||
await evm.runCall({ | ||
to: testCodeAddress, | ||
gasLimit: BigInt(100_000), | ||
}) | ||
|
||
const result = await evm.stateManager.getStorage(testCodeAddress, new Uint8Array(32)) | ||
const expected = BigInt(eip7702Designator.length) | ||
|
||
assert.equal(bytesToBigInt(result), expected) | ||
}) | ||
|
||
it('EXTCODEHASH', async () => { | ||
const evm = await getEVM() | ||
const code = unprefixedHexToBytes(PUSH_Address + EXTCODEHASH + STORE_TOP_STACK_CODE) | ||
await evm.stateManager.putCode(testCodeAddress, code) | ||
|
||
await evm.runCall({ | ||
to: testCodeAddress, | ||
gasLimit: BigInt(100_000), | ||
}) | ||
|
||
const result = await evm.stateManager.getStorage(testCodeAddress, new Uint8Array(32)) | ||
const expected = keccak256(eip7702Designator) | ||
|
||
assert.ok(equalsBytes(result, expected)) | ||
}) | ||
|
||
it('EXTCODECOPY', async () => { | ||
const evm = await getEVM() | ||
// This code does some extra logic than other tests, because it has to setup EXTCODECOPY (4 stack items instead of 1) | ||
// It EXTCODECOPYs 32 bytes of the delegated address in memory at key 0, and then MLOADs key 0 before storing the result | ||
const code = unprefixedHexToBytes( | ||
'60205F5F' + PUSH_Address + EXTCODECOPY + '5F51' + STORE_TOP_STACK_CODE, | ||
) | ||
await evm.stateManager.putCode(testCodeAddress, code) | ||
|
||
await evm.runCall({ | ||
to: testCodeAddress, | ||
gasLimit: BigInt(100_000), | ||
}) | ||
|
||
const result = await evm.stateManager.getStorage(testCodeAddress, new Uint8Array(32)) | ||
const expected = setLengthRight(eip7702Designator, 32) | ||
|
||
assert.ok(equalsBytes(result, expected)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only computed once! Can also move it somewhere else like
types.ts
.