Package com.horizen.certnative
Class NaiveThresholdSignatureWKeyRotation
- java.lang.Object
-
- com.horizen.certnative.NaiveThresholdSignatureWKeyRotation
-
public class NaiveThresholdSignatureWKeyRotation extends Object
-
-
Constructor Summary
Constructors Constructor Description NaiveThresholdSignatureWKeyRotation()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldElementcreateMsgToSign(WithdrawalCertificate withdrawalCertificate)static CreateProofResultcreateProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, String provingKeyPath, boolean zk)Compute proof for given parametersstatic CreateProofResultcreateProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, Optional<Integer> supportedDegree, String provingKeyPath, boolean zk)Compute proof for given parametersstatic CreateProofResultcreateProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, Optional<Integer> supportedDegree, String provingKeyPath, boolean checkProvingKey, boolean zk)Compute proof for given parametersstatic CreateProofResultcreateProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, Optional<Integer> supportedDegree, String provingKeyPath, boolean checkProvingKey, boolean zk, boolean compressedPk, boolean compressProof)Compute proof for given parametersstatic Optional<String>debugCircuit(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignatures, long maxPks, long threshold, FieldElement genesisKeysRootHash)Checks if possible to create a valid proof with the supplied data.static FieldElementgetConstant(FieldElement genesisKeyRootHash, long threshold)static FieldElementgetMsgToSignForMasterKeyUpdate(SchnorrPublicKey newMasterKey, int epochNumber, FieldElement scId)static FieldElementgetMsgToSignForSigningKeyUpdate(SchnorrPublicKey newSigningKey, int epochNumber, FieldElement scId)static FieldElementnativeGetMsgToSignForMasterKeyUpdate(SchnorrPublicKey newMasterKey, int epochNumber, FieldElement scId)static FieldElementnativeGetMsgToSignForSigningKeyUpdate(SchnorrPublicKey newSigningKey, int epochNumber, FieldElement scId)static 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(WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, FieldElement genesisConstant, byte[] proof, boolean checkProof, String verificationKeyPath, boolean checkVerificationKey)Verify proof using the supplied parametersstatic booleanverifyProof(WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, FieldElement genesisConstant, byte[] proof, String verificationKeyPath)Verify proof using the supplied parameters
-
-
-
Method Detail
-
createMsgToSign
public static FieldElement createMsgToSign(WithdrawalCertificate withdrawalCertificate)
-
nativeGetMsgToSignForSigningKeyUpdate
public static FieldElement nativeGetMsgToSignForSigningKeyUpdate(SchnorrPublicKey newSigningKey, int epochNumber, FieldElement scId) throws Exception
- Throws:
Exception
-
getMsgToSignForSigningKeyUpdate
public static FieldElement getMsgToSignForSigningKeyUpdate(SchnorrPublicKey newSigningKey, int epochNumber, FieldElement scId) throws Exception
- Throws:
Exception
-
nativeGetMsgToSignForMasterKeyUpdate
public static FieldElement nativeGetMsgToSignForMasterKeyUpdate(SchnorrPublicKey newMasterKey, int epochNumber, FieldElement scId) throws Exception
- Throws:
Exception
-
getMsgToSignForMasterKeyUpdate
public static FieldElement getMsgToSignForMasterKeyUpdate(SchnorrPublicKey newMasterKey, int epochNumber, FieldElement scId) throws Exception
- Throws:
Exception
-
getConstant
public static FieldElement getConstant(FieldElement genesisKeyRootHash, long threshold) throws Exception
- Throws:
Exception
-
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) throws Exception
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
- Throws:
Exception
-
setup
public static boolean setup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, boolean zk, int maxProofPlusVkSize) throws Exception
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
- Throws:
Exception
-
setup
public static boolean setup(ProvingSystemType psType, long maxPks, int numCustomFields, Optional<Integer> segmentSize, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize) throws Exception
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.
- Throws:
Exception
-
setup
public static boolean setup(ProvingSystemType psType, long maxPks, int numCustomFields, String provingKeyPath, String verificationKeyPath, int maxProofPlusVkSize) throws Exception
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.
- Throws:
Exception
-
debugCircuit
public static Optional<String> debugCircuit(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignatures, long maxPks, long threshold, FieldElement genesisKeysRootHash) throws Exception
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:
keysSignaturesList- - the collection of keys and signatures for this epochwithdrawalCertificate- - the withdrawal certificate to testprevWithdrawalCertificate- - the previous withdrawal certificate to testcertSignatures- - the list of signatures over the message by the validatorsmaxPks- - maximum number of public keys and signaturesthreshold- - minimum number of signatures that must be verified for the certificate to be acceptedgenesisKeysRootHash- - The root hash of the first block- 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:
Exception
-
createProof
public static CreateProofResult createProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, Optional<Integer> supportedDegree, String provingKeyPath, boolean checkProvingKey, boolean zk, boolean compressedPk, boolean compressProof) throws Exception
Compute proof for given parameters- Parameters:
keysSignaturesList- - the collection of keys and signatures for this epochwithdrawalCertificate- - the withdrawal certificate to testprevWithdrawalCertificate- - the previous withdrawal certificate to testcertSignaturesList- - the list of signatures over the message by the validatorsmaxPks- - maximum number of public keys and signaturesthreshold- - minimum number of signatures that must be verified for the certificate to be acceptedgenesisKeysRootHash- - The root hash of the first blocksupportedDegree- - 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 notcompressedPk- - if the pk read from provingKeyPath is in compressed form or notcompressProof- - 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.
- Throws:
Exception
-
createProof
public static CreateProofResult createProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, Optional<Integer> supportedDegree, String provingKeyPath, boolean checkProvingKey, boolean zk) throws Exception
Compute proof for given parameters- Parameters:
keysSignaturesList- - the collection of keys and signatures for this epochwithdrawalCertificate- - the withdrawal certificate to testprevWithdrawalCertificate- - the previous withdrawal certificate to testcertSignaturesList- - the list of signatures over the message by the validatorsmaxPks- - maximum number of public keys and signaturesthreshold- - minimum number of signatures that must be verified for the certificate to be acceptedgenesisKeysRootHash- - The root hash of the first blocksupportedDegree- - 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.
- Throws:
Exception
-
createProof
public static CreateProofResult createProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, Optional<Integer> supportedDegree, String provingKeyPath, boolean zk) throws Exception
Compute proof for given parameters- Parameters:
keysSignaturesList- - the collection of keys and signatures for this epochwithdrawalCertificate- - the withdrawal certificate to testprevWithdrawalCertificate- - the previous withdrawal certificate to testcertSignaturesList- - the list of signatures over the message by the validatorsmaxPks- - maximum number of public keys and signaturesthreshold- - minimum number of signatures that must be verified for the certificate to be acceptedgenesisKeysRootHash- - The root hash of the first blocksupportedDegree- - 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.
- Throws:
Exception
-
createProof
public static CreateProofResult createProof(ValidatorKeysUpdatesList keysSignaturesList, WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, List<SchnorrSignature> certSignaturesList, long maxPks, long threshold, FieldElement genesisKeysRootHash, String provingKeyPath, boolean zk) throws Exception
Compute proof for given parameters- Parameters:
keysSignaturesList- - the collection of keys and signatures for this epochwithdrawalCertificate- - the withdrawal certificate to testprevWithdrawalCertificate- - the previous withdrawal certificate to testcertSignaturesList- - the list of signatures over the message by the validatorsmaxPks- - maximum number of public keys and signaturesthreshold- - minimum number of signatures that must be verified for the certificate to be acceptedgenesisKeysRootHash- - The root hash of the first blockprovingKeyPath- - 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.
- Throws:
Exception
-
verifyProof
public static boolean verifyProof(WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, FieldElement genesisConstant, byte[] proof, boolean checkProof, String verificationKeyPath, boolean checkVerificationKey) throws Exception
Verify proof using the supplied parameters- Parameters:
withdrawalCertificate- - the withdrawal certificate to testprevWithdrawalCertificate- - the previous withdrawal certificate to testgenesisConstant- - The root hash of the first blockproof- - 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
- Throws:
Exception
-
verifyProof
public static boolean verifyProof(WithdrawalCertificate withdrawalCertificate, Optional<WithdrawalCertificate> prevWithdrawalCertificate, FieldElement genesisConstant, byte[] proof, String verificationKeyPath) throws Exception
Verify proof using the supplied parameters- Parameters:
withdrawalCertificate- - the withdrawal certificate to testprevWithdrawalCertificate- - the previous withdrawal certificate to testgenesisConstant- - The root hash of the first blockproof- - 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
- Throws:
Exception
-
-