Package com.horizen.cswnative
Class CswProof
- java.lang.Object
-
- com.horizen.cswnative.CswProof
-
public class CswProof extends Object
-
-
Constructor Summary
Constructors Constructor Description CswProof()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, String provingKeyPath)Compute proof for given parameters.static byte[]createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath)Compute proof for given parameters.static byte[]createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath, boolean zk)Compute proof for given parametersstatic byte[]createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk)Compute proof for given parametersstatic byte[]createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk, boolean compressed_pk, boolean compress_proof)Compute proof for given parametersstatic Optional<String>debugCircuit(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData)Checks if possible to create a valid proof with the supplied data.static booleansetup(ProvingSystemType psType, int rangeSize, int numCustomFields, boolean isConstantPresent, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)Generate (provingKey, verificationKey) pair for this circuit.static booleansetup(ProvingSystemType psType, int rangeSize, int numCustomFields, boolean isConstantPresent, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, boolean zk, int maxProofPlusVkSize)Generate (provingKey, verificationKey) pair for this circuit.static booleansetup(ProvingSystemType psType, int rangeSize, int numCustomFields, boolean isConstantPresent, 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, int rangeSize, int numCustomFields, boolean isConstantPresent, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)Generate (provingKey, verificationKey) pair for this circuit.static booleanverifyProof(CswSysData sysData, FieldElement scId, byte[] proof, boolean checkProof, String verificationKeyPath, boolean checkVerificationKey)Verify proof using the supplied parametersstatic booleanverifyProof(CswSysData sysData, FieldElement scId, byte[] proof, String verificationKeyPath)Verify proof using the supplied parameters
-
-
-
Method Detail
-
setup
public static boolean setup(ProvingSystemType psType, int rangeSize, int numCustomFields, boolean isConstantPresent, 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 usedrangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportisConstantPresent- - whether the circuit must support the presence of a constantsegmentSize- - 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 keymaxProofPlusVkSize- - 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, int rangeSize, int numCustomFields, boolean isConstantPresent, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, boolean zk, int maxProofPlusVkSize)
Generate (provingKey, verificationKey) pair for this circuit.- Parameters:
psType- - proving system to be usedrangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportisConstantPresent- - whether the circuit must support the presence of a constantsegmentSize- - 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, int rangeSize, int numCustomFields, boolean isConstantPresent, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)
Generate (provingKey, verificationKey) pair for this circuit.- Parameters:
psType- - proving system to be usedrangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportisConstantPresent- - whether the circuit must support the presence of a constantsegmentSize- - 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, int rangeSize, int numCustomFields, boolean isConstantPresent, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize)
Generate (provingKey, verificationKey) pair for this circuit.- Parameters:
psType- - proving system to be usedrangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportisConstantPresent- - whether the circuit must support the presence of a constantprovingKeyPath- - 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(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData) throws IllegalArgumentException
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:
rangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportsysData- - certificate sys data.scId- - the id of the corresponding sidechainlastWcert- - the last confirmed wcert in the MC. Can be empty if SC has ceased before we have at least certs for 2 epochs (in this case we can only withdraw FT)utxoData- - data required to prove withdraw of a SC utxo. Must be empty if the prover wants to prove withdraw of a FT instead. If this field is present, then lastWCert and sysData.scLastWCertHash must be present too.ftData- - data required to prove withdraw of a FT. Must be empty if the prover wants to prove withdraw of a SC utxo instead. If present, then sysData.mcbScTxsComEnd must be present too.- 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.
- Throws:
IllegalArgumentException- - if inputs are not consistent
-
createProof
public static byte[] createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk, boolean compressed_pk, boolean compress_proof) throws IllegalArgumentExceptionCompute proof for given parameters- Parameters:
rangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportsysData- - certificate sys data.scId- - the id of the corresponding sidechainlastWcert- - the last confirmed wcert in the MC. Can be empty if SC has ceased before we have at least certs for 2 epochs (in this case we can only withdraw FT)utxoData- - data required to prove withdraw of a SC utxo. Must be empty if the prover wants to prove withdraw of a FT instead. If this field is present, then lastWCert and sysData.scLastWCertHash must be present too.ftData- - data required to prove withdraw of a FT. Must be empty if the prover wants to prove withdraw of a SC utxo instead. If present, then sysData.mcbScTxsComEnd must be present too.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:
- the proof bytes
- Throws:
IllegalArgumentException- if utxoData is present but lastWcert is empty, or if utxoData and ftData are both present
-
createProof
public static byte[] createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath, boolean checkProvingKey, boolean zk) throws IllegalArgumentExceptionCompute proof for given parameters- Parameters:
rangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportsysData- - certificate sys data.scId- - the id of the corresponding sidechainlastWcert- - the last confirmed wcert in the MC. Can be empty if SC has ceased before we have at least certs for 2 epochs (in this case we can only withdraw FT)utxoData- - data required to prove withdraw of a SC utxo. Must be empty if the prover wants to prove withdraw of a FT instead. If this field is present, then lastWCert and sysData.scLastWCertHash must be present too.ftData- - data required to prove withdraw of a FT. Must be empty if the prover wants to prove withdraw of a SC utxo instead. If present, then sysData.mcbScTxsComEnd must be present too.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:
- the proof bytes
- Throws:
IllegalArgumentException- if utxoData is present but lastWcert is empty, or if utxoData and ftData are both present
-
createProof
public static byte[] createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath, boolean zk) throws IllegalArgumentExceptionCompute proof for given parameters- Parameters:
rangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportscId- - the id of the corresponding sidechainsysData- - certificate sys data.lastWcert- - the last confirmed wcert in the MC. Can be empty if SC has ceased before we have at least certs for 2 epochs (in this case we can only withdraw FT)utxoData- - data required to prove withdraw of a SC utxo. Must be empty if the prover wants to prove withdraw of a FT instead. If this field is present, then lastWCert and sysData.scLastWCertHash must be present too.ftData- - data required to prove withdraw of a FT. Must be empty if the prover wants to prove withdraw of a SC utxo instead. If present, then sysData.mcbScTxsComEnd must be present too.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 formzk- - if proof must be created using zk property or not- Returns:
- the proof bytes
- Throws:
IllegalArgumentException- if utxoData is present but lastWcert is empty, or if utxoData and ftData are both present
-
createProof
public static byte[] createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, Optional<Integer> segmentSize, String provingKeyPath) throws IllegalArgumentExceptionCompute proof for given parameters. Zero knowledge will be used.- Parameters:
rangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportsysData- - certificate sys data.scId- - the id of the corresponding sidechainlastWcert- - the last confirmed wcert in the MC. Can be empty if SC has ceased before we have at least certs for 2 epochs (in this case we can only withdraw FT)utxoData- - data required to prove withdraw of a SC utxo. Must be empty if the prover wants to prove withdraw of a FT instead. If this field is present, then lastWCert and sysData.scLastWCertHash must be present too.ftData- - data required to prove withdraw of a FT. Must be empty if the prover wants to prove withdraw of a SC utxo instead. If present, then sysData.mcbScTxsComEnd must be present too.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 form- Returns:
- the proof bytes
- Throws:
IllegalArgumentException- if utxoData is present but lastWcert is empty, or if utxoData and ftData are both present
-
createProof
public static byte[] createProof(int rangeSize, int numCustomFields, CswSysData sysData, FieldElement scId, Optional<WithdrawalCertificate> lastWcert, Optional<CswUtxoProverData> utxoData, Optional<CswFtProverData> ftData, String provingKeyPath) throws IllegalArgumentExceptionCompute proof for given parameters. Zero knowledge will be used.- Parameters:
rangeSize- - number of blocks between `mcbScTxsComStart` and `mcbScTxsComEnd`numCustomFields- - exact number of custom fields the circuit must supportsysData- - certificate sys data.scId- - the id of the corresponding sidechainlastWcert- - the last confirmed wcert in the MC. Can be empty if SC has ceased before we have at least certs for 2 epochs (in this case we can only withdraw FT)utxoData- - data required to prove withdraw of a SC utxo. Must be empty if the prover wants to prove withdraw of a FT instead. If this field is present, then lastWCert and sysData.scLastWCertHash must be present too.ftData- - data required to prove withdraw of a FT. Must be empty if the prover wants to prove withdraw of a SC utxo instead. If present, then sysData.mcbScTxsComEnd must be present too.provingKeyPath- - file path from which reading the proving key, expected to be in compressed form- Returns:
- the proof bytes
- Throws:
IllegalArgumentException- if utxoData is present but lastWcert is empty, or if utxoData and ftData are both present
-
verifyProof
public static boolean verifyProof(CswSysData sysData, FieldElement scId, byte[] proof, boolean checkProof, String verificationKeyPath, boolean checkVerificationKey)
Verify proof using the supplied parameters- Parameters:
sysData- - certificate sys data.scId- - the id of the corresponding sidechainproof- - 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(CswSysData sysData, FieldElement scId, byte[] proof, String verificationKeyPath)
Verify proof using the supplied parameters- Parameters:
sysData- - certificate sys data.scId- - the id of the corresponding sidechainproof- - 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
-
-