@@ -58,7 +58,7 @@ public unsafe byte[] BlobToKzgCommitment(byte[] blob)
58
58
return commitment ;
59
59
}
60
60
61
- public unsafe byte [ ] ComputeCells ( byte [ ] blob )
61
+ public unsafe byte [ ] [ ] ComputeCells ( byte [ ] blob )
62
62
{
63
63
byte [ ] cells = new byte [ BytesForAllCells ] ;
64
64
@@ -68,10 +68,10 @@ public unsafe byte[] ComputeCells(byte[] blob)
68
68
CResult result = compute_cells ( _context , Convert . ToUInt64 ( blob . Length ) , blobPtr , cellsPtr ) ;
69
69
ThrowOnError ( result ) ;
70
70
}
71
- return cells ;
71
+ return DeflattenArray ( cells , BytesPerCell ) ;
72
72
}
73
73
74
- public unsafe ( byte [ ] , byte [ ] ) ComputeCellsAndKZGProofs ( byte [ ] blob )
74
+ public unsafe ( byte [ ] [ ] , byte [ ] [ ] ) ComputeCellsAndKZGProofs ( byte [ ] blob )
75
75
{
76
76
byte [ ] cells = new byte [ BytesForAllCells ] ;
77
77
byte [ ] proofs = new byte [ BytesForAllProofs ] ;
@@ -83,7 +83,7 @@ public unsafe (byte[], byte[]) ComputeCellsAndKZGProofs(byte[] blob)
83
83
CResult result = compute_cells_and_kzg_proofs ( _context , Convert . ToUInt64 ( blob . Length ) , blobPtr , cellsPtr , proofsPtr ) ;
84
84
ThrowOnError ( result ) ;
85
85
}
86
- return ( cells , proofs ) ;
86
+ return ( DeflattenArray ( cells , BytesPerCell ) , DeflattenArray ( proofs , BytesPerCommitment ) ) ;
87
87
}
88
88
89
89
public unsafe bool VerifyCellKZGProof ( byte [ ] cell , byte [ ] commitment , ulong cellId , byte [ ] proof )
@@ -125,7 +125,7 @@ public bool VerifyCellKZGProofBatch(byte[][] rowCommitments, ulong[] rowIndices,
125
125
return verified ;
126
126
}
127
127
128
- public byte [ ] RecoverAllCells ( ulong [ ] cellIds , byte [ ] [ ] cells )
128
+ public byte [ ] [ ] RecoverAllCells ( ulong [ ] cellIds , byte [ ] [ ] cells )
129
129
{
130
130
byte [ ] cellsFlattened = FlattenArray ( cells ) ;
131
131
@@ -138,7 +138,7 @@ public byte[] RecoverAllCells(ulong[] cellIds, byte[][] cells)
138
138
ThrowOnError ( result ) ;
139
139
}
140
140
141
- return recoveredCells ;
141
+ return DeflattenArray ( recoveredCells , BytesPerCell ) ;
142
142
}
143
143
144
144
private static void ThrowOnError ( CResult result )
@@ -167,7 +167,7 @@ private static void ThrowOnError(CResult result)
167
167
}
168
168
}
169
169
170
- public static byte [ ] FlattenArray ( byte [ ] [ ] jaggedArray )
170
+ private static byte [ ] FlattenArray ( byte [ ] [ ] jaggedArray )
171
171
{
172
172
int totalLength = 0 ;
173
173
@@ -192,6 +192,20 @@ public static byte[] FlattenArray(byte[][] jaggedArray)
192
192
return flattenedArray ;
193
193
}
194
194
195
+ private static byte [ ] [ ] DeflattenArray ( byte [ ] flattenedArray , int length )
196
+ {
197
+ int numArrays = flattenedArray . Length / length ;
198
+ byte [ ] [ ] jaggedArray = new byte [ numArrays ] [ ] ;
199
+
200
+ for ( int i = 0 ; i < numArrays ; i ++ )
201
+ {
202
+ jaggedArray [ i ] = new byte [ length ] ;
203
+ Array . Copy ( flattenedArray , i * length , jaggedArray [ i ] , 0 , length ) ;
204
+ }
205
+
206
+ return jaggedArray ;
207
+ }
208
+
195
209
public enum ContextSetting
196
210
{
197
211
ProvingOnly ,
0 commit comments