7
7
import java .nio .file .Path ;
8
8
import java .nio .file .StandardCopyOption ;
9
9
10
- // TODO(Note): If the underlying java bindings call into the rust code directly,
11
- // We can remove the length checks in the java code.
12
-
13
10
public class LibPeerDASKZG implements AutoCloseable {
14
11
// These constants were taken from c-kzg
15
12
//
@@ -53,65 +50,25 @@ public void destroy() {
53
50
}
54
51
55
52
public byte [] blobToKZGCommitment (byte [] blob ) {
56
- // Length checks
57
- if (blob .length != BYTES_PER_BLOB ) {
58
- throw new IllegalArgumentException ("Invalid blob length" );
59
- }
60
53
return blobToKZGCommitment (contextPtr , blob );
61
54
}
62
55
63
56
public CellsAndProofs computeCellsAndKZGProofs (byte [] blob ) {
64
- // Length checks
65
- if (blob .length != BYTES_PER_BLOB ) {
66
- throw new IllegalArgumentException ("Invalid blob length" );
67
- }
68
57
CellsAndProofs cellsAndProofs = computeCellsAndKZGProofs (contextPtr , blob );
69
58
return cellsAndProofs ;
70
59
}
71
60
72
61
public byte [][] computeCells (byte [] blob ) {
73
- // Length checks
74
- if (blob .length != BYTES_PER_BLOB ) {
75
- throw new IllegalArgumentException ("Invalid blob length" );
76
- }
77
62
CellsAndProofs cellsAndProofs = computeCellsAndKZGProofs (blob );
78
63
return cellsAndProofs .cells ;
79
64
}
80
65
81
66
public boolean verifyCellKZGProof (byte [] commitment , long cellID , byte [] cell , byte [] proof ) {
82
- // Length checks
83
- if (commitment .length != BYTES_PER_COMMITMENT ) {
84
- throw new IllegalArgumentException ("Invalid commitment length" );
85
- }
86
- if (cell .length != BYTES_PER_CELL ) {
87
- throw new IllegalArgumentException ("Invalid cell length" );
88
- }
89
- if (proof .length != BYTES_PER_PROOF ) {
90
- throw new IllegalArgumentException ("Invalid proof length" );
91
- }
92
67
return verifyCellKZGProof (contextPtr , commitment , cellID , cell , proof );
93
68
}
94
69
95
70
public boolean verifyCellKZGProofBatch (byte [][] commitmentsArr , long [] rowIndices , long [] columnIndices , byte [][] cellsArr ,
96
71
byte [][] proofsArr ) {
97
-
98
- // Length checks
99
- for (int i = 0 ; i < commitmentsArr .length ; i ++) {
100
- if (commitmentsArr [i ].length != BYTES_PER_COMMITMENT ) {
101
- throw new IllegalArgumentException ("Invalid commitment length" );
102
- }
103
- }
104
- for (int i = 0 ; i < proofsArr .length ; i ++) {
105
- if (proofsArr [i ].length != BYTES_PER_PROOF ) {
106
- throw new IllegalArgumentException ("Invalid proof length" );
107
- }
108
- }
109
- for (int i = 0 ; i < cellsArr .length ; i ++) {
110
- if (cellsArr [i ].length != BYTES_PER_CELL ) {
111
- throw new IllegalArgumentException ("Invalid cell length" );
112
- }
113
- }
114
-
115
72
return verifyCellKZGProofBatch (contextPtr , commitmentsArr , rowIndices , columnIndices , cellsArr , proofsArr );
116
73
}
117
74
@@ -120,13 +77,6 @@ public byte[][] recoverAllCells(long[] cellIDs, byte[][] cellsArr) {
120
77
}
121
78
122
79
public CellsAndProofs recoverCellsAndProofs (long [] cellIDs , byte [][] cellsArr ) {
123
- // Length checks
124
- for (int i = 0 ; i < cellsArr .length ; i ++) {
125
- if (cellsArr [i ].length != BYTES_PER_CELL ) {
126
- throw new IllegalArgumentException ("Invalid cell length" );
127
- }
128
- }
129
-
130
80
return recoverCellsAndProof (contextPtr , cellIDs , cellsArr );
131
81
}
132
82
0 commit comments