Skip to content

Commit 261ca7e

Browse files
committed
fix conflict
2 parents f856276 + 8976673 commit 261ca7e

5 files changed

Lines changed: 175 additions & 26 deletions

File tree

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

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,21 @@ void librustzcash_merkle_hash(int depth, byte[] a, byte[] b, byte[] result
133133
void librustzcash_to_scalar(byte[] input, byte[] result);
134134
}
135135

136-
public static void librustzcashZip32XskMaster(Zip32XskMasterParams params)
137-
throws ZksnarkException {
136+
public static void librustzcashZip32XskMaster(Zip32XskMasterParams params) {
138137
INSTANCE.librustzcash_zip32_xsk_master(params.getData(), params.getSize(), params.getM_bytes());
139138
}
140139

141-
public static void librustzcashInitZksnarkParams(InitZksnarkParams params)
142-
throws ZksnarkException {
140+
public static void librustzcashInitZksnarkParams(InitZksnarkParams params) {
143141
INSTANCE.librustzcash_init_zksnark_params(params.getSpend_path(), params.getSpend_path_len(),
144142
params.getSpend_hash(), params.getOutput_path(), params.getOutput_path_len(),
145143
params.getOutput_hash());
146144
}
147145

148-
public static void librustzcashZip32XskDerive(Zip32XskDeriveParams params)
149-
throws ZksnarkException {
146+
public static void librustzcashZip32XskDerive(Zip32XskDeriveParams params) {
150147
INSTANCE.librustzcash_zip32_xsk_derive(params.getData(), params.getSize(), params.getM_bytes());
151148
}
152149

153-
public static boolean librustzcashZip32XfvkAddress(Zip32XfvkAddressParams params)
154-
throws ZksnarkException {
150+
public static boolean librustzcashZip32XfvkAddress(Zip32XfvkAddressParams params) {
155151
return INSTANCE.librustzcash_zip32_xfvk_address(params.getXfvk(), params.getJ(),
156152
params.getJ_ret(), params.getAddr_ret());
157153
}
@@ -351,5 +347,73 @@ private static String getLibrary(String name) {
351347
return fileOut.getAbsolutePath();
352348
}
353349

350+
public static void main(String[] args) throws ZksnarkException {
351+
byte[] d = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
352+
//byte[] d ={};
353+
//byte[] pk_d = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
354+
byte[] ivk = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8,
355+
9, 10, 11, 12, 13, 14, 15};
356+
byte[] pk_d = new byte[32];
357+
long value = 1;
358+
byte[] r = {(byte) 0xb7, 0x2c, (byte) 0xf7, (byte) 0xd6, 0x5e, 0x0e, (byte) 0x97, (byte) 0xd0,
359+
(byte) 0x82, 0x10, (byte) 0xc8, (byte) 0xcc, (byte) 0x93, 0x20, 0x68, (byte) 0xa6, 0x00,
360+
0x3b, 0x34, 0x01, 0x01, 0x3b, 0x67, 0x06, (byte) 0xa9, (byte) 0xaf, 0x33, 0x65, (byte) 0xea,
361+
(byte) 0xb4, 0x7d, 0x0e};
362+
byte[] cm = new byte[32];
363+
boolean check_d = librustzcashCheckDiversifier(d);
364+
System.out.println("d is " + check_d);
365+
366+
ivk[31] = (byte) 0x10;
367+
boolean check_pkd = librustzcashIvkToPkd(new IvkToPkdParams(ivk, d, pk_d));
368+
System.out.println("pk_d is\n");
369+
for (int j = 0; j < 32; j++) {
370+
System.out.printf("%x ", pk_d[j]);
371+
if ((j + 1) % 16 == 0) {
372+
System.out.printf("\n");
373+
}
374+
}
375+
376+
boolean res = librustzcashSaplingComputeCm(new SaplingComputeCmParams(d, pk_d, value, r, cm));
377+
System.out.println("cm is" + res);
378+
379+
//check range of alpha
380+
byte[] ask = {(byte) 0xb7, 0x2c, (byte) 0xf7, (byte) 0xd6, 0x5e, 0x0e, (byte) 0x97, (byte) 0xd0,
381+
(byte) 0x82, 0x10, (byte) 0xc8, (byte) 0xcc, (byte) 0x93, 0x20, 0x68, (byte) 0xa6, 0x00,
382+
0x3b, 0x34, 0x01, 0x01, 0x3b, 0x67, 0x06, (byte) 0xa9, (byte) 0xaf, 0x33, 0x65, (byte) 0xea,
383+
(byte) 0xb4, 0x7d, 0x0e};
384+
byte[] alpha = {(byte) 0xb6, 0x2c, (byte) 0xf7, (byte) 0xd6, 0x5e, 0x0e, (byte) 0x97,
385+
(byte) 0xd0, (byte) 0x82, 0x10, (byte) 0xc8, (byte) 0xcc, (byte) 0x93, 0x20, 0x68,
386+
(byte) 0xa6, 0x00, 0x3b, 0x34, 0x01, 0x01, 0x3b, 0x67, 0x06, (byte) 0xa9, (byte) 0xaf, 0x33,
387+
0x65, (byte) 0xea, (byte) 0xb4, 0x7d, 0x0e};
388+
byte[] sighash = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7,
389+
8, 9, 10, 11, 12, 13, 14, 15};
390+
byte[] sigRes = new byte[64];
391+
boolean boolSigRes = librustzcashSaplingSpendSig(
392+
new SaplingSpendSigParams(ask, alpha, sighash, sigRes));
393+
System.out.println("sig result " + boolSigRes);
394+
395+
byte[] nsk = {(byte) 0xb6, 0x2c, (byte) 0xf7, (byte) 0xd6, 0x5e, 0x0e, (byte) 0x97, (byte) 0xd0,
396+
(byte) 0x82, 0x10, (byte) 0xc8, (byte) 0xcc, (byte) 0x93, 0x20, 0x68, (byte) 0xa6, 0x00,
397+
0x3b, 0x34, 0x01, 0x01, 0x3b, 0x67, 0x06, (byte) 0xa9, (byte) 0xaf, 0x33, 0x65, (byte) 0xea,
398+
(byte) 0xb4, 0x7d, 0x0e};
399+
byte[] nk = new byte[32];
400+
nk = librustzcashNskToNk(nsk);
401+
402+
for (int j = 0; j < 32; j++) {
403+
System.out.printf("%x ", nk[j]);
404+
if ((j + 1) % 16 == 0) {
405+
System.out.printf("\n");
406+
}
407+
}
408+
409+
Pointer ctx = librustzcashSaplingProvingCtxInit();
410+
byte[] resbindSig = new byte[64];
411+
boolean boolBindSig = librustzcashSaplingBindingSig(
412+
new SaplingBindingSigParams(ctx, value, null, resbindSig));
413+
System.out.println("binding sig result " + boolBindSig);
414+
415+
416+
}
417+
354418

355419
}

‎src/main/java/org/tron/common/zksnark/LibrustzcashParam.java‎

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ public void valid() throws ZksnarkException {
118118

119119
}
120120
}
121-
121+
/**
122+
* (ak,nk)--> ivk
123+
* ak: spendAuthSig.publickey 32 bytes
124+
* nk: 32 bytes
125+
* ivk: incoming viewing key, 32 bytes
126+
*/
122127
public static class CrhIvkParams implements ValidParam {
123128

124129
@Setter
@@ -143,7 +148,12 @@ public void valid() throws ZksnarkException {
143148

144149
}
145150
}
146-
151+
/**
152+
* KaAgree(sk,p)=[h_J*sk]p
153+
* p: point, 32 bytes
154+
* sk: 32 bytes
155+
* result: 32 bytes
156+
*/
147157
public static class SaplingKaAgreeParams implements ValidParam {
148158

149159
@Setter
@@ -168,7 +178,13 @@ public void valid() throws ZksnarkException {
168178

169179
}
170180
}
171-
181+
/**
182+
* Compute note commitment
183+
* d: diversifier, 11 bytes
184+
* pk_d: 32 bytes
185+
* r: rcm, 32 bytes
186+
* cm: note commitment, 32 bytes
187+
*/
172188
public static class SaplingComputeCmParams implements ValidParam {
173189

174190
@Setter
@@ -202,7 +218,15 @@ public void valid() throws ZksnarkException {
202218

203219
}
204220
}
205-
221+
/**
222+
* compute nullifier
223+
* d: diversifier, 11 bytes
224+
* pk_d, 32 bytes
225+
* r: rcm, 32 bytes
226+
* ak: spendAuthSig.PulicKey, 32 bytes
227+
* nk: to genarate nullifier, 32 bytes
228+
* result: nullifier, 32 bytes
229+
*/
206230
public static class SaplingComputeNfParams implements ValidParam {
207231

208232
@Setter
@@ -248,7 +272,11 @@ public void valid() throws ZksnarkException {
248272

249273
}
250274
}
251-
275+
/**
276+
* diversifier: d, 11 bytes
277+
* esk: 32 bytes
278+
* result: return 32 bytes
279+
*/
252280
public static class SaplingKaDerivepublicParams implements ValidParam {
253281

254282
@Setter
@@ -274,7 +302,19 @@ public void valid() throws ZksnarkException {
274302

275303
}
276304
}
277-
305+
/**
306+
* calculate spend proof
307+
* ak: 32 bytes
308+
* nsk: the proof authorizing key, 32 bytes
309+
* d: 11 bytes
310+
* r: rcm, 32 bytes
311+
* alpha: random number, 32 bytes
312+
* anchor: 32 bytes
313+
* voucherPath: (1 + 33 * 32 + 8) bytes, voucherPath[0]=0x20, voucherPath[1+i*33]=0x20,i=0,1,...31.
314+
* cv: value commitment, 32 bytes
315+
* rk: spendAuthSig.randomizePublicKey 32 bytes
316+
* zkproof: spend proof, 192 bytes
317+
*/
278318
public static class SaplingSpendProofParams implements ValidParam {
279319

280320
@Setter
@@ -337,7 +377,14 @@ public void valid() throws ZksnarkException {
337377

338378
}
339379
}
340-
380+
/**
381+
* esk: 32 bytes
382+
* d: 11 bytes
383+
* pk_d: 32 bytes
384+
* r: rcm, 32 bytes
385+
* cv: value commitment, 32 bytes
386+
* zkproof: receive proof, 192 bytes
387+
*/
341388
public static class SaplingOutputProofParams implements ValidParam {
342389

343390
@Setter
@@ -383,7 +430,12 @@ public void valid() throws ZksnarkException {
383430

384431
}
385432
}
386-
433+
/**
434+
* ask: the spend authorizing key, 32 bytes
435+
* alpha: random number, 32 bytes
436+
* sigHash: sha256 of transaction, 32 bytes
437+
* result: spendAuthSig, 64 bytes
438+
*/
387439
public static class SaplingSpendSigParams implements ValidParam {
388440

389441
@Setter
@@ -413,7 +465,11 @@ public void valid() throws ZksnarkException {
413465

414466
}
415467
}
416-
468+
/**
469+
* Generate binding signature
470+
* sighash: sha256 of transaction,32 bytes
471+
* result: binding signature, 64 bytes
472+
*/
417473
public static class SaplingBindingSigParams implements ValidParam {
418474

419475
@Setter
@@ -443,7 +499,15 @@ public void valid() throws ZksnarkException {
443499

444500
}
445501
}
446-
502+
/**
503+
* cv: value commitments, 32 bytes
504+
* anchor: 32 bytes
505+
* nullifier: 32 bytes
506+
* rk: spendAuthSig.randomizePublicKey, 32 bytes
507+
* zkproof: spend proof, 192 bytes
508+
* spendAuthSig: 64 bytes
509+
* sighashValue: sha256 of transaction, 32 bytes
510+
*/
447511
public static class SaplingCheckSpendParams implements ValidParam {
448512

449513
@Setter
@@ -490,7 +554,12 @@ public void valid() throws ZksnarkException {
490554

491555
}
492556
}
493-
557+
/**
558+
* cv: value commitments, 32 bytes
559+
* cm: note commitment, 32 bytes
560+
* ephemeralKey: 32 bytes
561+
* zkproof: 192 bytes
562+
*/
494563
public static class SaplingCheckOutputParams implements ValidParam {
495564

496565
@Setter
@@ -524,7 +593,10 @@ public void valid() throws ZksnarkException {
524593

525594
}
526595
}
527-
596+
/**
597+
* bindingSig: 64 bytes
598+
* sighashValue: sha256 of transaction,32 bytes
599+
*/
528600
public static class SaplingFinalCheckParams implements ValidParam {
529601

530602
@Setter
@@ -554,7 +626,11 @@ public void valid() throws ZksnarkException {
554626

555627
}
556628
}
557-
629+
/**
630+
* ivk: incoming viewing key, 32 bytes
631+
* d: 11 bytes
632+
* pk_d: 32 bytes
633+
*/
558634
public static class IvkToPkdParams implements ValidParam {
559635

560636
@Setter
@@ -579,7 +655,12 @@ public void valid() throws ZksnarkException {
579655

580656
}
581657
}
582-
658+
/**
659+
*
660+
* a: 32 bytes
661+
* b: 32 bytes
662+
* result: 32 bytes
663+
*/
583664
public static class MerkleHashParams implements ValidParam {
584665

585666
@Setter

‎src/test/java/org/tron/core/actuator/ShieldedReceiveActuatorTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ private static byte[] randomUint4640() {
189189
return org.tron.keystore.Wallet.generateRandomBytes(580);
190190
}
191191

192-
private IncrementalMerkleVoucherContainer createSimpleMerkleVoucherContainer(byte[] cm) {
192+
private IncrementalMerkleVoucherContainer createSimpleMerkleVoucherContainer(byte[] cm)
193+
throws ZksnarkException {
193194
IncrementalMerkleTreeContainer tree =
194195
new IncrementalMerkleTreeContainer(new IncrementalMerkleTreeCapsule());
195196
PedersenHashCapsule compressCapsule1 = new PedersenHashCapsule();

‎src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest2.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ private TransactionCapsule getPublicToShieldedTransaction() throws Exception {
158158
return builder.build();
159159
}
160160

161-
private IncrementalMerkleVoucherContainer createSimpleMerkleVoucherContainer(byte[] cm) {
161+
private IncrementalMerkleVoucherContainer createSimpleMerkleVoucherContainer(byte[] cm)
162+
throws ZksnarkException {
162163
IncrementalMerkleTreeContainer tree =
163164
new IncrementalMerkleTreeContainer(new IncrementalMerkleTreeCapsule());
164165
PedersenHashCapsule compressCapsule1 = new PedersenHashCapsule();

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ private PedersenHash ByteArray2PedersenHash(byte[] bytes) {
180180
return compressCapsule_in.getInstance();
181181
}
182182

183-
private IncrementalMerkleVoucherContainer createComplexMerkleVoucherContainer(byte[] cm) {
183+
private IncrementalMerkleVoucherContainer createComplexMerkleVoucherContainer(byte[] cm)
184+
throws ZksnarkException {
184185

185186
IncrementalMerkleTreeContainer tree =
186187
new IncrementalMerkleTreeContainer(new IncrementalMerkleTreeCapsule());
@@ -204,7 +205,8 @@ private IncrementalMerkleVoucherContainer createComplexMerkleVoucherContainer(by
204205
return voucher;
205206
}
206207

207-
private IncrementalMerkleVoucherContainer createSimpleMerkleVoucherContainer(byte[] cm) {
208+
private IncrementalMerkleVoucherContainer createSimpleMerkleVoucherContainer(byte[] cm)
209+
throws ZksnarkException {
208210

209211
IncrementalMerkleTreeContainer tree =
210212
new IncrementalMerkleTreeContainer(new IncrementalMerkleTreeCapsule());

0 commit comments

Comments
 (0)