Package com.horizen.certnative
Class NaiveThresholdSigProof
- java.lang.Object
-
- com.horizen.certnative.NaiveThresholdSigProof
-
public class NaiveThresholdSigProof extends Object
-
-
Constructor Summary
Constructors Constructor Description NaiveThresholdSigProof()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldElementcreateMsgToSign(BackwardTransfer[] bt, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<FieldElement> customFields)Compute message to be signedstatic CreateProofResultcreateProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, String provingKeyPath, boolean zk)Compute proof for given parametersstatic CreateProofResultcreateProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, Optional<Integer> segmentSize, String provingKeyPath, boolean zk)Compute proof for given parametersstatic CreateProofResultcreateProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk)Compute proof for given parametersstatic CreateProofResultcreateProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk, boolean compressed_pk, boolean compress_proof)Compute proof for given parametersstatic Optional<String>debugCircuit(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields)Checks if possible to create a valid proof with the supplied data.static FieldElementgetConstant(List<SchnorrPublicKey> schnorrPublicKeys, long threshold)Compute constant parameterstatic booleansetup(ProvingSystemType psType, long maxPks, int numCustomFields, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)Generate (provingKey, verificationKey) pair for this circuit.static booleansetup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, boolean zk, int maxProofPlusVkSize)Generate (provingKey, verificationKey) pair for this circuit.static booleansetup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, boolean zk, int maxProofPlusVkSize, boolean compressPk, boolean compressVk)Generate (provingKey, verificationKey) pair for this circuit.static booleansetup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)Generate (provingKey, verificationKey) pair for this circuit.static booleanverifyProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, FieldElement constant, long quality, List<FieldElement> customFields, byte[] proof, boolean checkProof, String verificationKeyPath, boolean checkVerificationKey)Verify proof using the supplied parametersstatic booleanverifyProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, FieldElement constant, long quality, List<FieldElement> customFields, byte[] proof, String verificationKeyPath)Verify proof using the supplied parameters
-
-
-
Method Detail
-
getConstant
public static FieldElement getConstant(List<SchnorrPublicKey> schnorrPublicKeys, long threshold)
Compute constant parameter- Parameters:
schnorrPublicKeys- - Schnorr signature keys, part of the constant computationthreshold- - minimum number of valid Schnorr signatures, part of the constant computation- Returns:
- the constant as FieldElement, computed as PoseidonHash(PoseidonHash(schnorrPublicKeys), threshold), or null pointer if some error occured.
-
createMsgToSign
public static FieldElement createMsgToSign(BackwardTransfer[] bt, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<FieldElement> customFields)
Compute message to be signed- Parameters:
bt- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward TransfercustomFields- - additional parameters. Can be empty.- Returns:
- The message to be signed, computed as PoseidonHash(scId, epochNumber, MR(bt), endCumulativeScTxCommTreeRoot, btrFee, ftMinAmount, [H(customFields)]) or null pointer if some error occured.
-
setup
public static boolean setup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, boolean zk, int maxProofPlusVkSize, boolean compressPk, boolean compressVk)
Generate (provingKey, verificationKey) pair for this circuit.- Parameters:
psType- - proving system to be usedmaxPks- - maximum number of public keys (and so signatures) the circuit must supportnumCustomFields- - exact number of custom fields the circuit must supportsegmentSize- - the segment size to be used to generate (pk, vk). Must be smaller equal than the segment size passed to the ProvingSystem.generateDLogKeys() method. If not specified, it will default to the same size as the one passed to ProvingSystem.generateDLogKeys() method.provingKeyPath- - file path to which saving the proving keyverificationKeyPath- - file path to which saving the verification keyzk- - used to estimate the proof and vk size, tells if the proof will be created using zk or notmaxProofPlusVkSize- - maximum allowed size for proof + vkcompressPk- - if the proving key must be saved to provingKeyPath in compressed formcompressVk- - if the verification key must be saved to verificationKeyPath in compressed form- Returns:
- true if (pk, vk) generation and saving to file was successfull, false otherwise
-
setup
public static boolean setup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, boolean zk, int maxProofPlusVkSize)
Generate (provingKey, verificationKey) pair for this circuit.- Parameters:
psType- - proving system to be usedmaxPks- - maximum number of public keys (and so signatures) the circuit must supportnumCustomFields- - exact number of custom fields the circuit must supportsegmentSize- - the segment size to be used to generate (pk, vk). Must be smaller equal than the segment size passed to the ProvingSystem.generateDLogKeys() method. If not specified, it will default to the same size as the one passed to ProvingSystem.generateDLogKeys() method.provingKeyPath- - file path to which saving the proving key. Proving key will be saved in compressed form.verificationKeyPath- - file path to which saving the verification key. Verification key will be saved in compressed form.zk- - used to estimate the proof and vk size, tells if the proof will be created using zk or notmaxProofPlusVkSize- - maximum allowed size for proof + vk- Returns:
- true if (pk, vk) generation and saving to file was successfull, false otherwise
-
setup
public static boolean setup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)
Generate (provingKey, verificationKey) pair for this circuit.- Parameters:
psType- - proving system to be usedmaxPks- - maximum number of public keys (and so signatures) the circuit must supportnumCustomFields- - exact number of custom fields the circuit must supportsegmentSize- - the segment size to be used to generate (pk, vk). Must be smaller equal than the segment size passed to the ProvingSystem.generateDLogKeys() method. If not specified, it will default to the same size as the one passed to ProvingSystem.generateDLogKeys() method.provingKeyPath- - file path to which saving the proving key. Proving key will be saved in compressed form.verificationKeyPath- - file path to which saving the verification key. Verification key will be saved in compressed form.maxProofPlusVkSize- - maximum allowed size for proof + vk, estimated assuming not to use zk property- Returns:
- true if (pk, vk) generation and saving to file was successfull, false otherwise.
-
setup
public static boolean setup(ProvingSystemType psType, long maxPks, int numCustomFields, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)
Generate (provingKey, verificationKey) pair for this circuit.- Parameters:
psType- - proving system to be usedmaxPks- - maximum number of public keys (and so signatures) the circuit must supportnumCustomFields- - exact number of custom fields the circuit must supportprovingKeyPath- - file path to which saving the proving key. Proving key will be saved in compressed form.verificationKeyPath- - file path to which saving the verification key. Verification key will be saved in compressed form.maxProofPlusVkSize- - maximum allowed size for proof + vk, estimated assuming not to use zk property- Returns:
- true if (pk, vk) generation and saving to file was successfull, false otherwise.
-
debugCircuit
public static Optional<String> debugCircuit(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields)
Checks if possible to create a valid proof with the supplied data. Useful to understand the reason for which proof creation fails (usually some inconsistency with input data).- Parameters:
btList- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward TransferschnorrSignatureList- - list of Schnorr signatures to be verified using the corresponding public keys passed in SchnorrPublicKeyListschnorrPublicKeyList- - list of Schnorr public keys corresponding to schnorrSignaturesListthreshold- - Minimum number of signatures that must be verified for the certificate to be acceptedcustomFields- - additional parameters. Can be empty.- Returns:
- an Optional containing the name of the first failing constraint if the supplied data don't satisfy all the circuit's constraints, and nothing if all constraints are satisfied.
-
createProof
public static CreateProofResult createProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk, boolean compressed_pk, boolean compress_proof)
Compute proof for given parameters- Parameters:
btList- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward TransferschnorrSignatureList- - list of Schnorr signatures to be verified using the corresponding public keys passed in SchnorrPublicKeyListschnorrPublicKeyList- - list of Schnorr public keys corresponding to schnorrSignaturesListthreshold- - Minimum number of signatures that must be verified for the certificate to be acceptedcustomFields- - additional parameters. Can be empty.segmentSize- - the segment size to be used to create the proof. Must be equal to the one passed to the setup() method. If not specified, it will default to the same size as the one passed to ProvingSystem.generateDLogKeys() method.provingKeyPath- - file path from which reading the proving keycheckProvingKey- - enable semantic checks on the proving key (WARNING: very expensive)zk- - if proof must be created using zk property or notcompressed_pk- - if the pk read from provingKeyPath is in compressed form or notcompress_proof- - whether to return the proof bytes in compressed form or not- Returns:
- a CreateProofResult instance, i.e. the computed proof bytes and the quality of the certificate (i.e. in this case, number of valid signatures), OR null pointer if some errors occured during proof creation.
-
createProof
public static CreateProofResult createProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk)
Compute proof for given parameters- Parameters:
btList- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward TransferschnorrSignatureList- - list of Schnorr signatures to be verified using the corresponding public keys passed in SchnorrPublicKeyListschnorrPublicKeyList- - list of Schnorr public keys corresponding to schnorrSignaturesListthreshold- - Minimum number of signatures that must be verified for the certificate to be acceptedcustomFields- - additional parameters. Can be empty.segmentSize- - the segment size to be used to create the proof. Must be equal to the one passed to the setup() method. If not specified, it will default to the same size as the one passed to ProvingSystem.generateDLogKeys() method.provingKeyPath- - file path from which reading the proving key, expected to be in compressed formcheckProvingKey- - enable semantic checks on the proving key (WARNING: very expensive)zk- - if proof must be created using zk property or not- Returns:
- a CreateProofResult instance, i.e. the computed proof bytes (in compressed form), and the quality of the certificate (i.e. in this case, number of valid signatures) OR null pointer if some errors occured during proof creation.
-
createProof
public static CreateProofResult createProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, Optional<Integer> segmentSize, String provingKeyPath, boolean zk)
Compute proof for given parameters- Parameters:
btList- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward TransferschnorrSignatureList- - list of Schnorr signatures to be verified using the corresponding public keys passed in SchnorrPublicKeyListschnorrPublicKeyList- - list of Schnorr public keys corresponding to schnorrSignaturesListthreshold- - Minimum number of signatures that must be verified for the certificate to be acceptedcustomFields- - additional optional parameters. Can be emptysegmentSize- - the segment size to be used to create the proof. Must be equal to the one passed to the setup() method. If not specified, it will default to the same size as the one passed to ProvingSystem.generateDLogKeys() method.provingKeyPath- - file path from which reading the proving key, expected to be in compressed formzk- - if proof must be created using zk property or not- Returns:
- a CreateProofResult instance, i.e. the computed proof bytes (in compressed form), and the quality of the certificate (i.e. in this case, number of valid signatures); OR null pointer if some errors occured during proof creation.
-
createProof
public static CreateProofResult createProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, List<SchnorrSignature> schnorrSignatureList, List<SchnorrPublicKey> schnorrPublicKeyList, long threshold, List<FieldElement> customFields, String provingKeyPath, boolean zk)
Compute proof for given parameters- Parameters:
btList- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward TransferschnorrSignatureList- - list of Schnorr signatures to be verified using the corresponding public keys passed in SchnorrPublicKeyListschnorrPublicKeyList- - list of Schnorr public keys corresponding to schnorrSignaturesListthreshold- - Minimum number of signatures that must be verified for the certificate to be acceptedcustomFields- - additional optional parameters. Can be emptyprovingKeyPath- - file path from which reading the proving key, expected to be in compressed formzk- - if proof must be created using zk property or not- Returns:
- a CreateProofResult instance, i.e. the computed proof bytes (in compressed form), and the quality of the certificate (i.e. in this case, number of valid signatures); OR null pointer if some errors occured during proof creation.
-
verifyProof
public static boolean verifyProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, FieldElement constant, long quality, List<FieldElement> customFields, byte[] proof, boolean checkProof, String verificationKeyPath, boolean checkVerificationKey)
Verify proof using the supplied parameters- Parameters:
btList- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward Transferconstant- - constant parameter, as defined by getConstant() methodquality- - quality parameter, as returned by the createProof() function (in this case the number of valid signatures)customFields- - additional parameters. Can be empty.proof- - the bytes of the proof to be verified, expected to be in compressed formcheckProof- - enable semantic checks on the proofverificationKeyPath- - file path from which loading the verification key, expected to be in compressed formcheckVerificationKey- - enable semantic checks on the verification key- Returns:
- true, if proof verification was successfull, false if proof verification failed or if some errors occured during verification
-
verifyProof
public static boolean verifyProof(List<BackwardTransfer> btList, FieldElement scId, int epochNumber, FieldElement endCumulativeScTxCommTreeRoot, long btrFee, long ftMinAmount, FieldElement constant, long quality, List<FieldElement> customFields, byte[] proof, String verificationKeyPath)
Verify proof using the supplied parameters- Parameters:
btList- - the list of backward transfer for a given certificatescId- - the id of the corresponding sidechainepochNumber- - the epoch number for the certificateendCumulativeScTxCommTreeRoot- - the value of the cumulative sidechain transaction commitment tree at epoch endbtrFee- - fee for BackwardTransferftMinAmount- - minimum amount for Forward Transferconstant- - constant parameter, as defined by getConstant() methodquality- - quality parameter, as returned by the createProof() function (in this case the number of valid signatures)customFields- - additional parameters. Can be empty.proof- - the bytes of the proof to be verified, expected to be in compressed formverificationKeyPath- - file path from which loading the verification key, expected to be in compressed form- Returns:
- true, if proof verification was successfull, false if proof verification failed or if some errors occured during verification
-
-