File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,10 @@ export async function dataColumnMatrixRecovery(
8484 return Array . from ( partialSidecars . values ( ) ) ;
8585 }
8686
87- const firstDataColumn = partialSidecars . values ( ) . next ( ) . value ;
87+ // Sort data columns by index in ascending order before passing for kzg operations
88+ const partialSidecarsSorted = Array . from ( partialSidecars . values ( ) ) . sort ( ( a , b ) => a . index - b . index ) ;
89+
90+ const firstDataColumn = partialSidecarsSorted [ 0 ] ;
8891 if ( firstDataColumn == null ) {
8992 // should not happen because we check the size of the cache before this
9093 throw new Error ( "No data column found in cache to recover from" ) ;
@@ -101,8 +104,8 @@ export async function dataColumnMatrixRecovery(
101104 blobProofs . map ( ( _ , blobIndex ) => {
102105 const cellIndices : number [ ] = [ ] ;
103106 const cells : Uint8Array [ ] = [ ] ;
104- for ( const [ columnIndex , dataColumn ] of partialSidecars . entries ( ) ) {
105- cellIndices . push ( columnIndex ) ;
107+ for ( const dataColumn of partialSidecarsSorted ) {
108+ cellIndices . push ( dataColumn . index ) ;
106109 cells . push ( dataColumn . column [ blobIndex ] ) ;
107110 }
108111 // recovered cells and proofs are of the same row/blob, their length should be NUMBER_OF_COLUMNS
Original file line number Diff line number Diff line change @@ -169,6 +169,11 @@ type RecoverCellsAndKzgProofsInput = {
169169 cells : string [ ] ;
170170} ;
171171function recoverCellsAndKzgProofs ( input : RecoverCellsAndKzgProofsInput ) : [ string [ ] , string [ ] ] | null {
172+ const isSorted = input . cell_indices . every ( ( val , i , arr ) => i === 0 || arr [ i - 1 ] < val ) ;
173+ // If cell indices are not in ascending order, they are deemed invalid and cannot pass it to kzg
174+ // Though in practice, we sort them before passing to kzg, here we follow the spec test case expectation
175+ // See https://github.com/ChainSafe/lodestar/pull/8450/files#r2372830108 for context
176+ if ( ! isSorted ) return null ;
172177 const cellIndices = input . cell_indices . map ( BigInt ) ;
173178 const cells = input . cells . map ( fromHexString ) ;
174179 try {
You can’t perform that action at this time.
0 commit comments