Skip to content

Commit 669925f

Browse files
g11techacolytec3
andauthored
common: update eip 2935 as per latest devnet1 spec and add related eip 7709 (#3475)
* common: update eip 2935 as per latest devnet1 spec and add related eip 7709 * typo * fix 2935 test * fix casing typo * lint * apply feedback * empty --------- Co-authored-by: acolytec3 <[email protected]>
1 parent 81cd86d commit 669925f

File tree

6 files changed

+47
-21
lines changed

6 files changed

+47
-21
lines changed

packages/block/src/from-beacon-payload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type BeaconDepositRequest = {
2020

2121
type BeaconWithdrawalRequest = {
2222
source_address: PrefixedHexString
23-
validator_pub_key: PrefixedHexString
23+
validator_pubkey: PrefixedHexString
2424
amount: PrefixedHexString
2525
}
2626

@@ -160,7 +160,7 @@ export function executionPayloadFromBeaconPayload(payload: BeaconPayloadJson): E
160160
if (payload.withdrawal_requests !== undefined && payload.withdrawal_requests !== null) {
161161
executionPayload.withdrawalRequests = payload.withdrawal_requests.map((breq) => ({
162162
sourceAddress: breq.source_address,
163-
validatorPubkey: breq.validator_pub_key,
163+
validatorPubkey: breq.validator_pubkey,
164164
amount: breq.amount,
165165
}))
166166
}

packages/client/test/rpc/engine/newPayloadV4.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const [blockData] = blocks
1212

1313
const parentBeaconBlockRoot = '0x42942949c4ed512cd85c2cb54ca88591338cbb0564d3a2bea7961a639ef29d64'
1414
const validForkChoiceState = {
15-
headBlockHash: '0x586b459d3fa589fa0e30477ef0e9d11794629b8b914e00b2703c0615a33ab9ed',
16-
safeBlockHash: '0x586b459d3fa589fa0e30477ef0e9d11794629b8b914e00b2703c0615a33ab9ed',
17-
finalizedBlockHash: '0x586b459d3fa589fa0e30477ef0e9d11794629b8b914e00b2703c0615a33ab9ed',
15+
headBlockHash: '0x3ff9144b3f0818580798b0a9ff5cedc1350ff62f46ec99b098344e2864be1e47',
16+
safeBlockHash: '0x3ff9144b3f0818580798b0a9ff5cedc1350ff62f46ec99b098344e2864be1e47',
17+
finalizedBlockHash: '0x3ff9144b3f0818580798b0a9ff5cedc1350ff62f46ec99b098344e2864be1e47',
1818
}
1919
const validPayloadAttributes = {
2020
timestamp: '0x64ba84fd',
@@ -50,6 +50,11 @@ describe(`${method}: call with executionPayloadV4`, () => {
5050
const { pragueJson, pragueTime } = readyPragueGenesis(genesisJSON)
5151
const { service, server } = await setupChain(pragueJson, 'post-merge', { engine: true })
5252
const rpc = getRpcClient(server)
53+
let res
54+
55+
res = await rpc.request(`eth_getBlockByNumber`, ['0x0', false])
56+
assert.equal(res.result.hash, validForkChoiceState.headBlockHash)
57+
5358
const validBlock = {
5459
...blockData,
5560
timestamp: bigIntToHex(BigInt(pragueTime)),
@@ -58,11 +63,10 @@ describe(`${method}: call with executionPayloadV4`, () => {
5863
excessBlobGas: '0x0',
5964
depositRequests: [],
6065
withdrawalRequests: [],
61-
parentHash: '0x586b459d3fa589fa0e30477ef0e9d11794629b8b914e00b2703c0615a33ab9ed',
62-
stateRoot: '0x76869ec89f1bc786e10a03ecf4a3f9815ec9dddecb372bd0eff51fe75d0d921e',
63-
blockHash: '0x34ec8335d47f4ba04a4c1f75f414b85b5e5200d60a6a639b6fc71ce90bcaaee2',
66+
parentHash: '0x3ff9144b3f0818580798b0a9ff5cedc1350ff62f46ec99b098344e2864be1e47',
67+
stateRoot: '0xd207043769091b6cdc91621f12bf2800b0b4643aeff09118fca52543c7a8ff03',
68+
blockHash: '0xf9b4285204630ca183fec0a9a282cb68021af1aa9f3ab5f10d6b9ea8a7a3d4b6',
6469
}
65-
let res
6670

6771
const oldMethods = ['engine_newPayloadV1', 'engine_newPayloadV2', 'engine_newPayloadV3']
6872
const expectedErrors = [
@@ -129,10 +133,10 @@ describe(`${method}: call with executionPayloadV4`, () => {
129133
const electraGenesisContracts = {
130134
// sender corresponding to the priv key 0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355
131135
'0x610adc49ecd66cbf176a8247ebd59096c031bd9f': { balance: '0x6d6172697573766477000000' },
132-
'0x25a219378dad9b3503c8268c9ca836a52427a4fb': {
136+
'0x0aae40965e6800cd9b1f4b05ff21581047e3f91e': {
133137
balance: '0',
134138
nonce: '1',
135-
code: '0x60203611603157600143035f35116029575f356120000143116029576120005f3506545f5260205ff35b5f5f5260205ff35b5f5ffd00',
139+
code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500',
136140
},
137141
'0x00A3ca265EBcb825B45F985A16CEFB49958cE017': {
138142
balance: '0',

packages/common/src/eips.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export const EIPs: EIPsDict = {
222222
requiredEIPs: [],
223223
vm: {
224224
historyStorageAddress: {
225-
v: BigInt('0x25a219378dad9b3503c8268c9ca836a52427a4fb'),
225+
v: BigInt('0x0aae40965e6800cd9b1f4b05ff21581047e3f91e'),
226226
d: 'The address where the historical blockhashes are stored',
227227
},
228228
historyServeWindow: {
@@ -623,4 +623,11 @@ export const EIPs: EIPsDict = {
623623
requiredEIPs: [3675],
624624
gasPrices: {},
625625
},
626+
7709: {
627+
comment: 'Use historical block hashes saved in state for BLOCKHASH',
628+
url: 'https://eips.ethereum.org/EIPS/eip-7709',
629+
status: Status.Draft,
630+
minimumHardfork: Hardfork.Chainstart,
631+
requiredEIPs: [2935],
632+
},
626633
}

packages/evm/src/evm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export class EVM implements EVMInterface {
211211
const supportedEIPs = [
212212
1153, 1559, 2537, 2565, 2718, 2929, 2930, 2935, 3074, 3198, 3529, 3540, 3541, 3607, 3651,
213213
3670, 3855, 3860, 4399, 4895, 4788, 4844, 5133, 5656, 6110, 6780, 6800, 7002, 7516, 7685,
214+
7709,
214215
]
215216

216217
for (const eip of this.common.eips()) {

packages/evm/src/opcodes/functions.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,23 +608,24 @@ export const handlers: Map<number, OpHandler> = new Map([
608608
async function (runState, common) {
609609
const number = runState.stack.pop()
610610

611-
if (common.isActivatedEIP(2935)) {
611+
if (common.isActivatedEIP(7709)) {
612612
if (number >= runState.interpreter.getBlockNumber()) {
613613
runState.stack.push(BIGINT_0)
614614
return
615615
}
616616

617617
const diff = runState.interpreter.getBlockNumber() - number
618-
const historyServeWindow = common.param('vm', 'historyServeWindow')
619-
// block lookups must be within the `historyServeWindow`
620-
if (diff > historyServeWindow || diff <= BIGINT_0) {
618+
// block lookups must be within the original window even if historyStorageAddress's
619+
// historyServeWindow is much greater than 256
620+
if (diff > BIGINT_256 || diff <= BIGINT_0) {
621621
runState.stack.push(BIGINT_0)
622622
return
623623
}
624624

625625
const historyAddress = new Address(
626626
bigIntToAddressBytes(common.param('vm', 'historyStorageAddress'))
627627
)
628+
const historyServeWindow = common.param('vm', 'historyServeWindow')
628629
const key = setLengthLeft(bigIntToBytes(number % historyServeWindow), 32)
629630

630631
if (common.isActivatedEIP(6800)) {

packages/vm/test/api/EIPs/eip-2935-historical-block-hashes.spec.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function eip2935ActiveAtCommon(timestamp: number) {
6161
comment: 'Start of the Ethereum main chain',
6262
url: '',
6363
status: 'final',
64-
eips: [2935],
64+
eips: [2935, 7709],
6565
},
6666
},
6767
hardforks,
@@ -248,8 +248,17 @@ describe('EIP 2935: historical block hashes', () => {
248248
})
249249
}
250250

251-
for (let i = 0; i <= blocksToBuild; i++) {
252-
const block = await vm.blockchain.getBlock(i)
251+
// swap out the blockchain to test from storage
252+
const blockchainEmpty = await Blockchain.create({
253+
common,
254+
validateBlocks: false,
255+
validateConsensus: false,
256+
})
257+
;(vm as any).blockchain = blockchainEmpty
258+
;(vm.evm as any).blockchain = blockchainEmpty
259+
260+
for (let i = 1; i <= blocksToBuild; i++) {
261+
const block = await blockchain.getBlock(i)
253262
const storage = await vm.stateManager.getContractStorage(
254263
historyAddress,
255264
setLengthLeft(bigIntToBytes(BigInt(i) % historyServeWindow), 32)
@@ -263,7 +272,11 @@ describe('EIP 2935: historical block hashes', () => {
263272
})
264273
if (i <= blocksToBuild - 1 && i >= blocksToBuild - Number(historyServeWindow)) {
265274
assert.ok(equalsBytes(setLengthLeft(storage, 32), block.hash()))
266-
assert.ok(equalsBytes(ret.execResult.returnValue, setLengthLeft(block.hash(), 64)))
275+
if (i >= blocksToBuild - 256) {
276+
assert.ok(equalsBytes(ret.execResult.returnValue, setLengthLeft(block.hash(), 64)))
277+
} else {
278+
assert.ok(equalsBytes(ret.execResult.returnValue, zeros(64)))
279+
}
267280
} else {
268281
assert.ok(equalsBytes(ret.execResult.returnValue, zeros(64)))
269282
}
@@ -284,7 +297,7 @@ describe('EIP 2935: historical block hashes', () => {
284297
// should be able to resolve blockhash via contract code
285298
for (const i of [0, 1, blocksActivation, blocksToBuild - 1]) {
286299
const blockHashi = await testBlockhashContract(vm, block, BigInt(i))
287-
const blocki = await vm.blockchain.getBlock(i)
300+
const blocki = await blockchain.getBlock(i)
288301
assert.ok(equalsBytes(blockHashi, blocki.hash()))
289302
}
290303

0 commit comments

Comments
 (0)