Skip to content

Commit 015cdcb

Browse files
committed
fix params parse error
1 parent 755a653 commit 015cdcb

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎src/main/java/org/tron/common/zksnark/zen/Librustzcash.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public static String getLibraryByName(String name) {
402402
platform = "windows";
403403
extension = ".dll";
404404
} else if (Platform.isMac()) {
405-
platform = "macos";
405+
platform = "tmp";
406406
extension = ".dylib";
407407
} else {
408408
throw new RuntimeException("unsupportedPlatformException");

‎src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.File;
1111
import java.util.Arrays;
1212
import java.util.List;
13+
import org.apache.commons.lang3.ArrayUtils;
1314
import org.junit.Assert;
1415
import org.junit.Test;
1516
import org.testng.collections.Lists;
@@ -215,38 +216,53 @@ private IncrementalMerkleVoucherContainer createMerkleVoucherContainer() {
215216
return voucher;
216217
}
217218

218-
private String getParamsFile(String fileName){
219+
private String getParamsFile(String fileName) {
219220
return SendCoinShieldTest.class.getClassLoader()
220221
.getResource("params" + File.separator + fileName).getFile();
221222
}
222-
private void librustzcashInitZksnarkParams() {
223+
224+
public static byte[] stringToAscii(String value) {
225+
List<Byte> sbu = Lists.newArrayList();
226+
char[] chars = value.toCharArray();
227+
for (int i = 0; i < chars.length; i++) {
228+
sbu.add((byte) chars[i]);
229+
}
230+
231+
Byte[] bytes = sbu.toArray(new Byte[sbu.size()]);
232+
return ArrayUtils.toPrimitive(bytes);
233+
234+
}
235+
236+
private void librustzcashInitZksnarkParams() throws Exception {
223237

224238
String file1 = getParamsFile("sapling-spend.params");
225239

226240
byte[] spend_path = file1.getBytes();
227241
int spend_path_len = spend_path.length;
228-
byte[] spend_hash = ByteArray.fromHexString(
229-
"8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c");
242+
byte[] spend_hash = stringToAscii(
243+
"8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c\0");
230244

231245
String file2 = getParamsFile("sapling-output.params");
232246
byte[] output_path = file2.getBytes();
233247
int output_path_len = output_path.length;
234-
byte[] output_hash = ByteArray.fromHexString(
235-
"657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028");
248+
byte[] output_hash =
249+
stringToAscii(
250+
"657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028\0");
236251

237252
String file3 = getParamsFile("sprout-groth16.params");
238253
byte[] sprout_path = file3.getBytes();
239254
int sprout_path_len = sprout_path.length;
240-
byte[] sprout_hash = ByteArray.fromHexString(
241-
"e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a");
255+
byte[] sprout_hash =
256+
stringToAscii(
257+
"e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a\0");
242258

243259
Librustzcash.librustzcashInitZksnarkParams(spend_path, spend_path_len, spend_hash,
244260
output_path, output_path_len, output_hash, sprout_path, sprout_path_len,
245261
sprout_hash);
246262
}
247263

248264
@Test
249-
public void testGenerateSpendProof() {
265+
public void testGenerateSpendProof() throws Exception {
250266
librustzcashInitZksnarkParams();
251267

252268
TransactionBuilder builder = new TransactionBuilder();

0 commit comments

Comments
 (0)