Skip to content

Commit a405cce

Browse files
committed
format Librustzcash
1 parent ceaff78 commit a405cce

2 files changed

Lines changed: 42 additions & 186 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ src/main/java/org/tron/core/bftconsensus
3636
src/test/java/org/tron/consensus2
3737
src/main/java/META-INF/
3838
src/main/resources/META-INF/
39+
src/main/resources/params
3940
/bin/
4041

4142
# Eclipse IDE specific files and folders

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

Lines changed: 41 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ public class Librustzcash {
1919

2020
public interface ILibrustzcash extends Library {
2121

22-
void librustzcash_init_zksnark_params(byte[] spend_path,
23-
int spend_path_len,
24-
byte[] spend_hash,
25-
byte[] output_path,
26-
int output_path_len,
27-
byte[] output_hash,
28-
byte[] sprout_path,
29-
int sprout_path_len,
30-
byte[] sprout_hash);
22+
void librustzcash_init_zksnark_params(byte[] spend_path, int spend_path_len, byte[] spend_hash,
23+
byte[] output_path, int output_path_len, byte[] output_hash, byte[] sprout_path,
24+
int sprout_path_len, byte[] sprout_hash);
3125

3226
void librustzcash_zip32_xsk_master(byte[] data, int size, byte[] m_bytes);
3327

@@ -37,14 +31,8 @@ void librustzcash_init_zksnark_params(byte[] spend_path,
3731

3832
void librustzcash_ask_to_ak(byte[] ask, byte[] result);
3933

40-
void librustzcash_sapling_compute_nf(byte[] d,
41-
byte[] pk_d,
42-
long value_,
43-
byte[] r,
44-
byte[] ak,
45-
byte[] nk,
46-
long position,
47-
byte[] result);
34+
void librustzcash_sapling_compute_nf(byte[] d, byte[] pk_d, long value_, byte[] r, byte[] ak,
35+
byte[] nk, long position, byte[] result);
4836

4937
void librustzcash_nsk_to_nk(byte[] nsk, byte[] result);
5038

@@ -73,74 +61,30 @@ boolean librustzcash_sapling_compute_cm(byte[] diversifier, byte[] pk_d, long va
7361

7462
Pointer librustzcash_sapling_proving_ctx_init();
7563

76-
boolean librustzcash_sapling_spend_proof(
77-
Pointer ctx,
78-
byte[] ak,
79-
byte[] nsk,
80-
byte[] diversifier,
81-
byte[] rcm,
82-
byte[] ar,
83-
long value,
84-
byte[] anchor,
85-
byte[] witness,
86-
byte[] cv,
87-
byte[] rk,
88-
byte[] zkproof
89-
);
64+
boolean librustzcash_sapling_spend_proof(Pointer ctx, byte[] ak, byte[] nsk, byte[] diversifier,
65+
byte[] rcm, byte[] ar, long value, byte[] anchor, byte[] witness, byte[] cv, byte[] rk,
66+
byte[] zkproof);
9067

91-
boolean librustzcash_sapling_output_proof(
92-
Pointer ctx,
93-
byte[] esk,
94-
byte[] diversifier,
95-
byte[] pk_d,
96-
byte[] rcm,
97-
long value,
98-
byte[] cv,
99-
byte[] zkproof
100-
);
68+
boolean librustzcash_sapling_output_proof(Pointer ctx, byte[] esk, byte[] diversifier,
69+
byte[] pk_d, byte[] rcm, long value, byte[] cv, byte[] zkproof);
10170

102-
boolean librustzcash_sapling_spend_sig(
103-
byte[] ask,
104-
byte[] ar,
105-
byte[] sighash,
106-
byte[] result);
71+
boolean librustzcash_sapling_spend_sig(byte[] ask, byte[] ar, byte[] sighash, byte[] result);
10772

108-
boolean librustzcash_sapling_binding_sig(
109-
Pointer ctx,
110-
long valueBalance,
111-
byte[] sighash,
112-
byte[] result
113-
);
73+
boolean librustzcash_sapling_binding_sig(Pointer ctx, long valueBalance, byte[] sighash,
74+
byte[] result);
11475

11576
void librustzcash_sapling_proving_ctx_free(Pointer ctx);
11677

11778
Pointer librustzcash_sapling_verification_ctx_init();
11879

119-
boolean librustzcash_sapling_check_spend(
120-
Pointer ctx,
121-
byte[] cv,
122-
byte[] anchor,
123-
byte[] nullifier,
124-
byte[] rk,
125-
byte[] zkproof,
126-
byte[] spendAuthSig,
127-
byte[] sighashValue
128-
);
80+
boolean librustzcash_sapling_check_spend(Pointer ctx, byte[] cv, byte[] anchor,
81+
byte[] nullifier, byte[] rk, byte[] zkproof, byte[] spendAuthSig, byte[] sighashValue);
12982

130-
boolean librustzcash_sapling_check_output(
131-
Pointer ctx,
132-
byte[] cv,
133-
byte[] cm,
134-
byte[] ephemeralKey,
135-
byte[] zkproof
136-
);
83+
boolean librustzcash_sapling_check_output(Pointer ctx, byte[] cv, byte[] cm,
84+
byte[] ephemeralKey, byte[] zkproof);
13785

138-
boolean librustzcash_sapling_final_check(
139-
Pointer ctx,
140-
long valueBalance,
141-
byte[] bindingSig,
142-
byte[] sighashValue
143-
);
86+
boolean librustzcash_sapling_final_check(Pointer ctx, long valueBalance, byte[] bindingSig,
87+
byte[] sighashValue);
14488

14589
void librustzcash_sapling_verification_ctx_free(Pointer ctx);
14690

@@ -153,80 +97,38 @@ boolean librustzcash_sapling_final_check(
15397
///
15498
/// The result of the merkle tree hash is placed in
15599
/// `result`, which must also be of length 32.
156-
void librustzcash_merkle_hash(
157-
int depth,
158-
byte[] a,
159-
byte[] b,
160-
byte[] result
100+
void librustzcash_merkle_hash(int depth, byte[] a, byte[] b, byte[] result
161101
);
162102

163103
/// Writes the "uncommitted" note value for empty leaves
164104
/// of the merkle tree. `result` must be a valid pointer
165105
/// to 32 bytes which will be written.
166-
void librustzcash_tree_uncommitted(
167-
byte[] result
168-
);
106+
void librustzcash_tree_uncommitted(byte[] result);
169107

170108
void librustzcash_to_scalar(byte[] input, byte[] result);
171109
}
172110

173-
// todo jni
174-
/*
175-
/// Derive the master ExtendedSpendingKey from a seed.
176-
void librustzcash_zip32_xsk_master(
177-
const unsigned char *seed,
178-
size_t seedlen,
179-
unsigned char *xsk_master
180-
);
181-
* */
182111
public static void librustzcashZip32XskMaster(byte[] data, int size, byte[] m_bytes) {
183112
INSTANCE.librustzcash_zip32_xsk_master(data, size, m_bytes);
184113
}
185114

186-
public static void librustzcashInitZksnarkParams(
187-
byte[] spend_path,
188-
int spend_path_len,
189-
byte[] spend_hash,
190-
byte[] output_path,
191-
int output_path_len,
192-
byte[] output_hash,
193-
byte[] sprout_path,
194-
int sprout_path_len,
195-
byte[] sprout_hash
196-
) {
197-
115+
public static void librustzcashInitZksnarkParams(byte[] spend_path, int spend_path_len,
116+
byte[] spend_hash, byte[] output_path, int output_path_len, byte[] output_hash,
117+
byte[] sprout_path, int sprout_path_len, byte[] sprout_hash) {
198118
INSTANCE.librustzcash_init_zksnark_params(spend_path, spend_path_len, spend_hash,
199119
output_path, output_path_len, output_hash, sprout_path, sprout_path_len,
200120
sprout_hash);
201121
}
202122

203-
/*
204-
/// Derive a child ExtendedSpendingKey from a parent.
205-
void librustzcash_zip32_xsk_derive(
206-
const unsigned char *xsk_parent,
207-
uint32_t i,
208-
unsigned char *xsk_i
209-
);
210-
* */
211123
public static void librustzcashZip32XskDerive(byte[] p_bytes, int i, byte[] m_bytes) {
212124
INSTANCE.librustzcash_zip32_xsk_derive(p_bytes, i, m_bytes);
213125
}
214126

215-
// /// Derive a PaymentAddress from an ExtendedFullViewingKey.
216-
// bool librustzcash_zip32_xfvk_address(
217-
// const unsigned char *xfvk,
218-
// const unsigned char *j,
219-
// unsigned char *j_ret,
220-
// unsigned char *addr_ret
221-
// );
222127
public static boolean librustzcashZip32XfvkAddress(byte[] xfvk, byte[] j, byte[] j_ret,
223128
byte[] addr_ret) {
224129
return INSTANCE.librustzcash_zip32_xfvk_address(xfvk, j, j_ret, addr_ret);
225130
}
226131

227-
228-
// void librustzcash_crh_ivk(const unsigned char *ak, const unsigned char *nk, unsigned char
229-
// *result);
230132
public static void librustzcashCrhIvk(byte[] ak, byte[] nk, byte[] ivk) {
231133
INSTANCE.librustzcash_crh_ivk(ak, nk, ivk);
232134
}
@@ -235,20 +137,13 @@ public static boolean librustzcashSaplingKaAgree(byte[] p, byte[] sk, byte[] res
235137
return INSTANCE.librustzcash_sapling_ka_agree(p, sk, result);
236138
}
237139

238-
public static boolean librustzcashSaplingComputeCm(
239-
byte[] d, byte[] pk_d, long value, byte[] r, byte[] cm) {
140+
public static boolean librustzcashSaplingComputeCm(byte[] d, byte[] pk_d, long value, byte[] r,
141+
byte[] cm) {
240142
return INSTANCE.librustzcash_sapling_compute_cm(d, pk_d, value, r, cm);
241143
}
242144

243-
public static boolean librustzcashSaplingComputeNf(
244-
byte[] d,
245-
byte[] pk_d,
246-
long value_,
247-
byte[] r,
248-
byte[] ak,
249-
byte[] nk,
250-
long position,
251-
byte[] result) {
145+
public static boolean librustzcashSaplingComputeNf(byte[] d, byte[] pk_d, long value_, byte[] r,
146+
byte[] ak, byte[] nk, long position, byte[] result) {
252147
INSTANCE.librustzcash_sapling_compute_nf(d, pk_d, value_, r, ak, nk, position, result);
253148
return true;
254149
}
@@ -272,7 +167,8 @@ public static byte[] librustzcashSaplingGenerateR(byte[] r) {
272167
return r;
273168
}
274169

275-
public static boolean librustzcashSaplingKaDerivepublic(byte[] diversifier, byte[] esk, byte[] result) {
170+
public static boolean librustzcashSaplingKaDerivepublic(byte[] diversifier, byte[] esk,
171+
byte[] result) {
276172
return INSTANCE.librustzcash_sapling_ka_derivepublic(diversifier, esk, result);
277173
}
278174

@@ -284,41 +180,20 @@ public static boolean librustzcashCheckDiversifier(byte[] b) {
284180
return INSTANCE.librustzcash_check_diversifier(b);
285181
}
286182

287-
288-
public static boolean librustzcashSaplingSpendProof(
289-
Pointer ctx,
290-
byte[] ak,
291-
byte[] nsk,
292-
byte[] d,
293-
byte[] r,
294-
byte[] alpha,
295-
long value,
296-
byte[] anchor,
297-
byte[] voucherPath,
298-
byte[] cv,
299-
byte[] rk,
183+
public static boolean librustzcashSaplingSpendProof(Pointer ctx, byte[] ak, byte[] nsk, byte[] d,
184+
byte[] r, byte[] alpha, long value, byte[] anchor, byte[] voucherPath, byte[] cv, byte[] rk,
300185
byte[] zkproof) {
301186
return INSTANCE
302187
.librustzcash_sapling_spend_proof(ctx, ak, nsk, d, r, alpha, value, anchor, voucherPath, cv,
303188
rk, zkproof);
304189
}
305190

306-
public static boolean librustzcashSaplingOutputProof(
307-
Pointer ctx,
308-
byte[] esk,
309-
byte[] d,
310-
byte[] pk_d,
311-
byte[] r,
312-
long value,
313-
byte[] cv,
314-
byte[] zkproof) {
191+
public static boolean librustzcashSaplingOutputProof(Pointer ctx, byte[] esk, byte[] d,
192+
byte[] pk_d, byte[] r, long value, byte[] cv, byte[] zkproof) {
315193
return INSTANCE.librustzcash_sapling_output_proof(ctx, esk, d, pk_d, r, value, cv, zkproof);
316194
}
317195

318-
public static boolean librustzcashSaplingSpendSig(
319-
byte[] ask,
320-
byte[] alpha,
321-
byte[] sigHash,
196+
public static boolean librustzcashSaplingSpendSig(byte[] ask, byte[] alpha, byte[] sigHash,
322197
byte[] result) {
323198
return INSTANCE.librustzcash_sapling_spend_sig(ask, alpha, sigHash, result);
324199
}
@@ -340,39 +215,20 @@ public static Pointer librustzcashSaplingVerificationCtxInit() {
340215
return INSTANCE.librustzcash_sapling_verification_ctx_init();
341216
}
342217

343-
public static boolean librustzcashSaplingCheckSpend(
344-
Pointer ctx,
345-
byte[] cv,
346-
byte[] anchor,
347-
byte[] nullifier,
348-
byte[] rk,
349-
byte[] zkproof,
350-
byte[] spendAuthSig,
351-
byte[] sighashValue
352-
353-
) {
218+
public static boolean librustzcashSaplingCheckSpend(Pointer ctx, byte[] cv, byte[] anchor,
219+
byte[] nullifier, byte[] rk, byte[] zkproof, byte[] spendAuthSig, byte[] sighashValue) {
354220
return INSTANCE
355221
.librustzcash_sapling_check_spend(ctx, cv, anchor, nullifier, rk, zkproof, spendAuthSig,
356222
sighashValue);
357223
}
358224

359-
public static boolean librustzcashSaplingCheckOutput(
360-
Pointer ctx,
361-
byte[] cv,
362-
byte[] cm,
363-
byte[] ephemeralKey,
364-
byte[] zkproof
365-
366-
) {
225+
public static boolean librustzcashSaplingCheckOutput(Pointer ctx, byte[] cv, byte[] cm,
226+
byte[] ephemeralKey, byte[] zkproof) {
367227
return INSTANCE.librustzcash_sapling_check_output(ctx, cv, cm, ephemeralKey, zkproof);
368228
}
369229

370-
public static boolean librustzcashSaplingFinalCheck(
371-
Pointer ctx,
372-
long valueBalance,
373-
byte[] bindingSig,
374-
byte[] sighashValue
375-
) {
230+
public static boolean librustzcashSaplingFinalCheck(Pointer ctx, long valueBalance,
231+
byte[] bindingSig, byte[] sighashValue) {
376232
return INSTANCE.librustzcash_sapling_final_check(ctx, valueBalance, bindingSig, sighashValue);
377233
}
378234

@@ -426,7 +282,6 @@ public static void main(String[] args) throws Exception {
426282
int ZIP32_XSK_SIZE = 169; // byte
427283
byte[] m_bytes = new byte[ZIP32_XSK_SIZE];
428284
librustzcash.librustzcashZip32XskMaster(rawSeed.getData(), rawSeed.getData().length, m_bytes);
429-
430285
}
431286

432287
}

0 commit comments

Comments
 (0)