Skip to content

Commit ea0761c

Browse files
author
Wenhua Zhang
committed
feat(zn_api): update createshieldedtransaction process
1 parent aad5da5 commit ea0761c

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎src/main/java/org/tron/core/Wallet.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Lo
13831383
cmCapsule.setContent(receiveDescription.getNoteCommitment());
13841384
PedersenHash cm = cmCapsule.getInstance();
13851385

1386-
if (outPoint.getIndex() < index) {
1386+
if (index < outPoint.getIndex()) {
13871387
tree.append(cm);
13881388
}else if(outPoint.getIndex() == index){
13891389
tree.append(cm);
@@ -1392,6 +1392,8 @@ private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Lo
13921392
}else {
13931393
witness.append(cm);
13941394
}
1395+
1396+
index ++;
13951397
}
13961398

13971399
} else {
@@ -1633,16 +1635,17 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request)
16331635
if (!(ArrayUtils.isEmpty(ask) || ArrayUtils.isEmpty(nsk) || ArrayUtils.isEmpty(ovk))) {
16341636
ExpandedSpendingKey expsk = new ExpandedSpendingKey(ask, nsk, ovk);
16351637
for (SpendNote spendNote : shieldedSpends) {
1636-
IncrementalMerkleTreeCapsule merkleTreeCapsule = dbManager.getMerkleContainer()
1637-
.getMerkleTree(spendNote.getAnchor().toByteArray());
1638+
16381639

16391640
GrpcAPI.Note note = spendNote.getNote();
16401641
BaseNote.Note baseNote = new BaseNote.Note(new DiversifierT(note.getD().toByteArray()),
16411642
note.getPkD().toByteArray(), note.getValue(), note.getRcm().toByteArray());
16421643

1644+
IncrementalMerkleVoucherContainer voucherContainer = new IncrementalMerkleVoucherCapsule(
1645+
spendNote.getVoucher()).toMerkleVoucherContainer();
16431646
builder.addSaplingSpend(expsk, baseNote, spendNote.getAlpha().toByteArray(),
1644-
spendNote.getAnchor().toByteArray(),
1645-
merkleTreeCapsule.toMerkleTreeContainer().toVoucher());
1647+
spendNote.getVoucher().getRt().toByteArray(),
1648+
voucherContainer );
16461649
}
16471650
}
16481651

‎src/main/java/org/tron/core/zen/ZenTransactionBuilder.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ public SpendDescriptionInfo(
316316
this.voucher = voucher;
317317
alpha = new byte[32];
318318
Librustzcash.librustzcashSaplingGenerateR(alpha);
319+
System.out.println("alpha is: " + ByteArray.toHexString(alpha));
319320
}
320321

321322
public SpendDescriptionInfo(

‎src/main/java/org/tron/core/zen/address/SpendingKey.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public static void main(String[] args) throws Exception {
135135
Optional<PaymentAddress> op = sk.fullViewingKey().inViewingKey().address(diversifierT);
136136
byte[] rcm = Note.generateR();
137137
System.out.println("rcm is " + ByteUtil.toHexString(rcm));
138+
139+
byte[] alpha = Note.generateR();
140+
System.out.println("alpha is " + ByteUtil.toHexString(alpha));
141+
138142
if (op.isPresent()) {
139143
System.out.println(
140144
"sk.Address:" + KeyIo.EncodePaymentAddress(op.get()));

‎src/main/java/org/tron/core/zen/note/BaseNote.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.tron.core.zen.note;
22

3+
import com.google.protobuf.ByteString;
4+
import org.tron.common.utils.ByteArray;
35
import org.tron.common.zksnark.Librustzcash;
46
import org.tron.core.zen.address.DiversifierT;
57
import org.tron.core.zen.address.FullViewingKey;
@@ -62,4 +64,18 @@ public byte[] nullifier(FullViewingKey vk, long position) {
6264
return result;
6365
}
6466
}
67+
68+
public static void main(String[] args) throws Exception {
69+
byte[] result = new byte[32];
70+
if (!Librustzcash.librustzcashSaplingComputeCm(
71+
(ByteArray.fromHexString("fc6eb90855700861de6639")), (
72+
ByteArray
73+
.fromHexString("1abfbf64bc4934aaf7f29b9fea995e5a16e654e63dbe07db0ef035499d216e19")),
74+
9990000000L, (ByteArray.fromHexString("08e3a2ff1101b628147125b786c757b483f1cf7c309f8a647055bfb1ca819c02")), result)) {
75+
System.out.println(" error");
76+
} else {
77+
System.out.println(" ok");
78+
}
79+
80+
}
6581
}

‎src/main/protos/api/api.proto‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,8 @@ message Note {
11431143
message SpendNote {
11441144
Note note = 3;
11451145
bytes alpha = 4; // random number for spend authority signature
1146-
bytes anchor = 5; // merkle root
1146+
// bytes anchor = 5; // merkle root
1147+
IncrementalMerkleVoucher voucher = 5;
11471148
bytes path = 6; // path for cm from leaf to root in merkle tree
11481149
}
11491150

0 commit comments

Comments
 (0)