1
1
import { config } from "@lodestar/config/default" ;
2
2
import { ProtoBlock } from "@lodestar/fork-choice" ;
3
- import { ForkName } from "@lodestar/params" ;
3
+ import { ForkBlobs , ForkName } from "@lodestar/params" ;
4
4
import { SignedBeaconBlock , ssz } from "@lodestar/types" ;
5
5
import { Mock , Mocked , beforeEach , describe , it , vi } from "vitest" ;
6
6
import { BlockErrorCode } from "../../../../src/chain/errors/index.js" ;
@@ -20,12 +20,15 @@ describe("gossip block validation", () => {
20
20
let job : SignedBeaconBlock ;
21
21
const proposerIndex = 0 ;
22
22
const clockSlot = 32 ;
23
- const block = ssz . phase0 . BeaconBlock . defaultValue ( ) ;
23
+ const block = ssz . deneb . BeaconBlock . defaultValue ( ) ;
24
24
block . slot = clockSlot ;
25
25
const signature = EMPTY_SIGNATURE ;
26
26
const maxSkipSlots = 10 ;
27
27
28
28
beforeEach ( ( ) => {
29
+ // Fill up with kzg commitments
30
+ block . body . blobKzgCommitments = Array . from ( { length : config . MAX_BLOBS_PER_BLOCK } , ( ) => new Uint8Array ( [ 0 ] ) ) ;
31
+
29
32
chain = getMockedBeaconChain ( ) ;
30
33
vi . spyOn ( chain . clock , "currentSlotWithGossipDisparity" , "get" ) . mockReturnValue ( clockSlot ) ;
31
34
forkChoice = chain . forkChoice ;
@@ -184,9 +187,47 @@ describe("gossip block validation", () => {
184
187
regen . getPreState . mockResolvedValue ( state ) ;
185
188
// BLS signature verifier returns valid
186
189
verifySignature . mockResolvedValue ( true ) ;
187
- // Force proposer shuffling cache to return wrong value
190
+ // Force proposer shuffling cache to return correct value
188
191
vi . spyOn ( state . epochCtx , "getBeaconProposer" ) . mockReturnValue ( proposerIndex ) ;
189
192
190
193
await validateGossipBlock ( config , chain , job , ForkName . phase0 ) ;
191
194
} ) ;
195
+
196
+ it ( "deneb - TOO_MANY_KZG_COMMITMENTS" , async ( ) => {
197
+ // Return not known for proposed block
198
+ forkChoice . getBlockHex . mockReturnValueOnce ( null ) ;
199
+ // Returned parent block is latter than proposed block
200
+ forkChoice . getBlockHex . mockReturnValueOnce ( { slot : clockSlot - 1 } as ProtoBlock ) ;
201
+ // Regen returns some state
202
+ const state = generateCachedState ( ) ;
203
+ regen . getPreState . mockResolvedValue ( state ) ;
204
+ // BLS signature verifier returns valid
205
+ verifySignature . mockResolvedValue ( true ) ;
206
+ // Force proposer shuffling cache to return correct value
207
+ vi . spyOn ( state . epochCtx , "getBeaconProposer" ) . mockReturnValue ( proposerIndex + 1 ) ;
208
+ // Add one extra kzg commitment in the block so it goes over the limit
209
+ ( job as SignedBeaconBlock < ForkBlobs > ) . message . body . blobKzgCommitments . push ( new Uint8Array ( [ 0 ] ) ) ;
210
+
211
+ await expectRejectedWithLodestarError (
212
+ validateGossipBlock ( config , chain , job , ForkName . deneb ) ,
213
+ BlockErrorCode . TOO_MANY_KZG_COMMITMENTS
214
+ ) ;
215
+ } ) ;
216
+
217
+ it ( "deneb - valid" , async ( ) => {
218
+ // Return not known for proposed block
219
+ forkChoice . getBlockHex . mockReturnValueOnce ( null ) ;
220
+ // Returned parent block is latter than proposed block
221
+ forkChoice . getBlockHex . mockReturnValueOnce ( { slot : clockSlot - 1 } as ProtoBlock ) ;
222
+ // Regen returns some state
223
+ const state = generateCachedState ( ) ;
224
+ regen . getPreState . mockResolvedValue ( state ) ;
225
+ // BLS signature verifier returns valid
226
+ verifySignature . mockResolvedValue ( true ) ;
227
+ // Force proposer shuffling cache to return correct value
228
+ vi . spyOn ( state . epochCtx , "getBeaconProposer" ) . mockReturnValue ( proposerIndex ) ;
229
+ // Keep number of kzg commitments as is so it stays within the limit
230
+
231
+ await validateGossipBlock ( config , chain , job , ForkName . deneb ) ;
232
+ } ) ;
192
233
} ) ;
0 commit comments