Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [main, release_workflow, 'release_**']
branches: [main, develop, release_workflow, 'release_**']
pull_request:
branches: [main, release_workflow]
branches: [main, develop, release_workflow]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ nodeId.properties

# vm_trace
/vm_trace/

#test dependence
solcDIR
gRPCurl
1 change: 0 additions & 1 deletion testcase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ task lint(type: Checkstyle) {
source 'src'
include '**/*.java'
exclude 'main/gen/**'
exclude 'test/**'
// empty classpath
classpath = files()
//Failing the build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
@Slf4j
public class IncrementalMerkleTreeContainer {

@Getter
@Setter
private static Integer DEPTH = 32;
@Getter @Setter private static Integer DEPTH = 32;

private IncrementalMerkleTreeCapsule treeCapsule;

Expand Down Expand Up @@ -53,8 +51,7 @@ public void wfcheck() throws ZksnarkException {
}

if ((!leftIsPresent()) && treeCapsule.getParents().size() > 0) {
throw new ZksnarkException(
"tree has non-canonical representation; parents should be empty");
throw new ZksnarkException("tree has non-canonical representation; parents should be empty");
}
}

Expand Down Expand Up @@ -86,9 +83,7 @@ public int size() {
return ret;
}

/**
* append PedersenHash to the merkletree.
*/
/** append PedersenHash to the merkletree. */
public void append(PedersenHash obj) throws ZksnarkException {
if (isComplete(DEPTH)) {
throw new ZksnarkException("tree is full");
Expand Down Expand Up @@ -143,9 +138,7 @@ public boolean isComplete(long depth) {
return true;
}

/**
* get the depth of the skip exist element.
*/
/** get the depth of the skip exist element. */
public int nextDepth(int skip) {
if (!leftIsPresent()) {
if (skip != 0) {
Expand Down Expand Up @@ -314,9 +307,9 @@ public PedersenHash next(int depth) {

public static class EmptyMerkleRoots {

@Setter
@Getter
@Setter @Getter
private static EmptyMerkleRoots emptyMerkleRootsInstance = new EmptyMerkleRoots();

private List<PedersenHashCapsule> emptyRoots = new ArrayList<>();

public EmptyMerkleRoots() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

public class IncrementalMerkleVoucherContainer {

@Getter
@Setter
private static Integer DEPTH = IncrementalMerkleTreeContainer.getDEPTH();
@Getter @Setter private static Integer DEPTH = IncrementalMerkleTreeContainer.getDEPTH();

private IncrementalMerkleVoucherCapsule voucherCapsule;

Expand Down Expand Up @@ -96,7 +94,7 @@ public int size() {
+ voucherCapsule.getCursor().toMerkleTreeContainer().size();
}

//for test only
// for test only
public void printSize() {
System.out.println(
"TreeSize:"
Expand Down
152 changes: 107 additions & 45 deletions testcase/src/test/java/org/tron/common/zksnark/JLibrustzcash.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package org.tron.common.zksnark;

import lombok.extern.slf4j.Slf4j;
import org.tron.common.zksnark.LibrustzcashParam.BindingSigParams;
import org.tron.common.zksnark.LibrustzcashParam.CheckOutputNewParams;
import org.tron.common.zksnark.LibrustzcashParam.CheckOutputParams;
import org.tron.common.zksnark.LibrustzcashParam.CheckSpendNewParams;
import org.tron.common.zksnark.LibrustzcashParam.CheckSpendParams;
import org.tron.common.zksnark.LibrustzcashParam.ComputeCmParams;
import org.tron.common.zksnark.LibrustzcashParam.ComputeNfParams;
import org.tron.common.zksnark.LibrustzcashParam.CrhIvkParams;
import org.tron.common.zksnark.LibrustzcashParam.FinalCheckNewParams;
import org.tron.common.zksnark.LibrustzcashParam.FinalCheckParams;
import org.tron.common.zksnark.LibrustzcashParam.InitZksnarkParams;
import org.tron.common.zksnark.LibrustzcashParam.IvkToPkdParams;
import org.tron.common.zksnark.LibrustzcashParam.KaAgreeParams;
import org.tron.common.zksnark.LibrustzcashParam.KaDerivepublicParams;
import org.tron.common.zksnark.LibrustzcashParam.MerkleHashParams;
import org.tron.common.zksnark.LibrustzcashParam.OutputProofParams;
import org.tron.common.zksnark.LibrustzcashParam.SpendProofParams;
import org.tron.common.zksnark.LibrustzcashParam.SpendSigParams;
import org.tron.common.zksnark.LibrustzcashParam.Zip32XfvkAddressParams;
import org.tron.common.zksnark.LibrustzcashParam.Zip32XskDeriveParams;
import org.tron.common.zksnark.LibrustzcashParam.Zip32XskMasterParams;
import stest.tron.wallet.common.client.utils.ByteUtil;
import stest.tron.wallet.common.client.utils.CommonParameter;
import stest.tron.wallet.common.client.utils.exception.ZksnarkException;
import org.tron.common.zksnark.LibrustzcashParam.*;

@Slf4j
public class JLibrustzcash {
Expand All @@ -22,8 +42,11 @@ public static void librustzcashInitZksnarkParams(InitZksnarkParams params) {
if (!isOpenZen()) {
return;
}
INSTANCE.librustzcashInitZksnarkParams(params.getSpend_path(),
params.getSpend_hash(), params.getOutput_path(), params.getOutput_hash());
INSTANCE.librustzcashInitZksnarkParams(
params.getSpend_path(),
params.getSpend_hash(),
params.getOutput_path(),
params.getOutput_hash());
}

public static void librustzcashZip32XskDerive(Zip32XskDeriveParams params) {
Expand All @@ -37,8 +60,8 @@ public static boolean librustzcashZip32XfvkAddress(Zip32XfvkAddressParams params
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashZip32XfvkAddress(params.getXfvk(), params.getJ(),
params.getJ_ret(), params.getAddr_ret());
return INSTANCE.librustzcashZip32XfvkAddress(
params.getXfvk(), params.getJ(), params.getJ_ret(), params.getAddr_ret());
}

public static void librustzcashCrhIvk(CrhIvkParams params) {
Expand All @@ -59,14 +82,21 @@ public static boolean librustzcashComputeCm(ComputeCmParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingComputeCm(params.getD(), params.getPkD(),
params.getValue(), params.getR(), params.getCm());
return INSTANCE.librustzcashSaplingComputeCm(
params.getD(), params.getPkD(), params.getValue(), params.getR(), params.getCm());
}

public static boolean librustzcashComputeNf(ComputeNfParams params) {
if (isOpenZen()) {
INSTANCE.librustzcashSaplingComputeNf(params.getD(), params.getPkD(), params.getValue(),
params.getR(), params.getAk(), params.getNk(), params.getPosition(), params.getResult());
INSTANCE.librustzcashSaplingComputeNf(
params.getD(),
params.getPkD(),
params.getValue(),
params.getR(),
params.getAk(),
params.getNk(),
params.getPosition(),
params.getResult());
}
return true;
}
Expand Down Expand Up @@ -101,9 +131,7 @@ public static byte[] librustzcashNskToNk(byte[] nsk) throws ZksnarkException {

// void librustzcash_nsk_to_nk(const unsigned char *nsk, unsigned char *result);

/**
* @return r: random number, less than r_J, 32 bytes
*/
/** @return r: random number, less than r_J, 32 bytes */
public static byte[] librustzcashSaplingGenerateR(byte[] r) throws ZksnarkException {
if (!isOpenZen()) {
return ByteUtil.EMPTY_BYTE_ARRAY;
Expand All @@ -117,8 +145,8 @@ public static boolean librustzcashSaplingKaDerivepublic(KaDerivepublicParams par
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingKaDerivepublic(params.getDiversifier(), params.getEsk(),
params.getResult());
return INSTANCE.librustzcashSaplingKaDerivepublic(
params.getDiversifier(), params.getEsk(), params.getResult());
}

public static long librustzcashSaplingProvingCtxInit() {
Expand All @@ -145,35 +173,50 @@ public static boolean librustzcashSaplingSpendProof(SpendProofParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingSpendProof(params.getCtx(), params.getAk(),
params.getNsk(), params.getD(), params.getR(), params.getAlpha(), params.getValue(),
params.getAnchor(), params.getVoucherPath(), params.getCv(), params.getRk(),
return INSTANCE.librustzcashSaplingSpendProof(
params.getCtx(),
params.getAk(),
params.getNsk(),
params.getD(),
params.getR(),
params.getAlpha(),
params.getValue(),
params.getAnchor(),
params.getVoucherPath(),
params.getCv(),
params.getRk(),
params.getZkproof());
}

public static boolean librustzcashSaplingOutputProof(OutputProofParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingOutputProof(params.getCtx(), params.getEsk(),
params.getD(), params.getPkD(), params.getR(), params.getValue(), params.getCv(),
return INSTANCE.librustzcashSaplingOutputProof(
params.getCtx(),
params.getEsk(),
params.getD(),
params.getPkD(),
params.getR(),
params.getValue(),
params.getCv(),
params.getZkproof());
}

public static boolean librustzcashSaplingSpendSig(SpendSigParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingSpendSig(params.getAsk(), params.getAlpha(),
params.getSigHash(), params.getResult());
return INSTANCE.librustzcashSaplingSpendSig(
params.getAsk(), params.getAlpha(), params.getSigHash(), params.getResult());
}

public static boolean librustzcashSaplingBindingSig(BindingSigParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingBindingSig(params.getCtx(),
params.getValueBalance(), params.getSighash(), params.getResult());
return INSTANCE.librustzcashSaplingBindingSig(
params.getCtx(), params.getValueBalance(), params.getSighash(), params.getResult());
}

/**
Expand Down Expand Up @@ -209,52 +252,74 @@ public static boolean librustzcashSaplingCheckSpend(CheckSpendParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingCheckSpend(params.getCtx(), params.getCv(),
params.getAnchor(), params.getNullifier(), params.getRk(), params.getZkproof(),
params.getSpendAuthSig(), params.getSighashValue());
return INSTANCE.librustzcashSaplingCheckSpend(
params.getCtx(),
params.getCv(),
params.getAnchor(),
params.getNullifier(),
params.getRk(),
params.getZkproof(),
params.getSpendAuthSig(),
params.getSighashValue());
}

public static boolean librustzcashSaplingCheckOutput(CheckOutputParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingCheckOutput(params.getCtx(), params.getCv(),
params.getCm(), params.getEphemeralKey(), params.getZkproof());
return INSTANCE.librustzcashSaplingCheckOutput(
params.getCtx(),
params.getCv(),
params.getCm(),
params.getEphemeralKey(),
params.getZkproof());
}

public static boolean librustzcashSaplingFinalCheck(FinalCheckParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingFinalCheck(params.getCtx(),
params.getValueBalance(), params.getBindingSig(), params.getSighashValue());
return INSTANCE.librustzcashSaplingFinalCheck(
params.getCtx(),
params.getValueBalance(),
params.getBindingSig(),
params.getSighashValue());
}

public static boolean librustzcashSaplingCheckSpendNew(CheckSpendNewParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingCheckSpendNew(params.getCv(),
params.getAnchor(), params.getNullifier(), params.getRk(), params.getZkproof(),
params.getSpendAuthSig(), params.getSighashValue());
return INSTANCE.librustzcashSaplingCheckSpendNew(
params.getCv(),
params.getAnchor(),
params.getNullifier(),
params.getRk(),
params.getZkproof(),
params.getSpendAuthSig(),
params.getSighashValue());
}

public static boolean librustzcashSaplingCheckOutputNew(CheckOutputNewParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE.librustzcashSaplingCheckOutputNew(params.getCv(), params.getCm(),
params.getEphemeralKey(), params.getZkproof());
return INSTANCE.librustzcashSaplingCheckOutputNew(
params.getCv(), params.getCm(), params.getEphemeralKey(), params.getZkproof());
}

public static boolean librustzcashSaplingFinalCheckNew(FinalCheckNewParams params) {
if (!isOpenZen()) {
return true;
}
return INSTANCE
.librustzcashSaplingFinalCheckNew(params.getValueBalance(), params.getBindingSig(),
params.getSighashValue(), params.getSpendCv(), params.getSpendCvLen(),
params.getOutputCv(), params.getOutputCvLen());
return INSTANCE.librustzcashSaplingFinalCheckNew(
params.getValueBalance(),
params.getBindingSig(),
params.getSighashValue(),
params.getSpendCv(),
params.getSpendCvLen(),
params.getOutputCv(),
params.getOutputCvLen());
}

public static void librustzcashSaplingVerificationCtxFree(long ctx) {
Expand All @@ -275,13 +340,11 @@ public static void librustzcashMerkleHash(MerkleHashParams params) {
if (!isOpenZen()) {
return;
}
INSTANCE.librustzcashMerkleHash(params.getDepth(), params.getA(), params.getB(),
params.getResult());
INSTANCE.librustzcashMerkleHash(
params.getDepth(), params.getA(), params.getB(), params.getResult());
}

/**
* @param result uncommitted value, 32 bytes
*/
/** @param result uncommitted value, 32 bytes */
public static void librustzcashTreeUncommitted(byte[] result) throws ZksnarkException {
if (!isOpenZen()) {
return;
Expand All @@ -297,5 +360,4 @@ public static boolean isOpenZen() {
}
return res;
}

}
Loading
Loading