Skip to content

Commit

Permalink
Add ordering checks
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Apr 25, 2024
1 parent 352cd93 commit 975ab38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
intToHex,
isHexPrefixed,
} from '@ethereumjs/util'
import { equal } from 'assert'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

import { executionPayloadFromBeaconPayload } from './from-beacon-payload.js'
Expand Down Expand Up @@ -162,7 +161,9 @@ export class Block {
// stub till that time
const executionWitness = executionWitnessData

const requests = requestsData?.map(CLRequest.fromRequestsData)
// Requests are sorted in ascending order based on type
// TODO: Decide if we should require requests to be sorted correctly or just do it automatically
const requests = requestsData?.map(CLRequest.fromRequestsData).sort((a, b) => a.type - b.type)

return new Block(
header,
Expand Down
1 change: 0 additions & 1 deletion packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
ecsign,
equalsBytes,
hexToBytes,
toBytes,
toType,
zeros,
} from '@ethereumjs/util'
Expand Down
17 changes: 16 additions & 1 deletion packages/block/test/eip7685block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { CLRequest, KECCAK256_RLP, randomBytes } from '@ethereumjs/util'
import { CLRequest, KECCAK256_RLP, bytesToHex, equalsBytes, randomBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { Block } from '../src/index.js'
Expand Down Expand Up @@ -40,4 +40,19 @@ describe('7685 tests', () => {

assert.equal(await block.requestsTrieIsValid(), false)
})
it('should produce order requests correctly', async () => {
const request1: RequestData = { type: 0x1, data: '0x1234' }
const request2: RequestData = { type: 0x2, data: '0x2345' }
const requests = [CLRequest.fromRequestsData(request1), CLRequest.fromRequestsData(request2)]
const requestsRoot = await Block.genRequestsTrieRoot(requests)
const block = Block.fromBlockData(
{
requests: [request2, request1],
header: { requestsRoot },
},
{ common }
)
assert.equal(block.requests![0].type, 0x1)
assert.equal(bytesToHex(block.requests![1].data), '0x2345')
})
})

0 comments on commit 975ab38

Please sign in to comment.