Class NaiveThresholdSignatureWKeyRotation


  • public class NaiveThresholdSignatureWKeyRotation
    extends Object
    • Constructor Detail

      • NaiveThresholdSignatureWKeyRotation

        public NaiveThresholdSignatureWKeyRotation()
    • Method Detail

      • 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 used
        maxPks - - maximum number of public keys (and so signatures) the circuit must support
        numCustomFields - - exact number of custom fields the circuit must support
        segmentSize - - 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
        verificationKeyPath - - file path to which saving the verification key
        zk - - used to estimate the proof and vk size, tells if the proof will be created using zk or not
        maxProofPlusVkSize - - maximum allowed size for proof + vk
        compressPk - - if the proving key must be saved to provingKeyPath in compressed form
        compressVk - - 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 used
        maxPks - - maximum number of public keys (and so signatures) the circuit must support
        numCustomFields - - exact number of custom fields the circuit must support
        segmentSize - - 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 not
        maxProofPlusVkSize - - 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 used
        maxPks - - maximum number of public keys (and so signatures) the circuit must support
        numCustomFields - - exact number of custom fields the circuit must support
        segmentSize - - 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 used
        maxPks - - maximum number of public keys (and so signatures) the circuit must support
        numCustomFields - - exact number of custom fields the circuit must support
        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
      • 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 epoch
        withdrawalCertificate - - the withdrawal certificate to test
        prevWithdrawalCertificate - - the previous withdrawal certificate to test
        certSignatures - - the list of signatures over the message by the validators
        maxPks - - maximum number of public keys and signatures
        threshold - - minimum number of signatures that must be verified for the certificate to be accepted
        genesisKeysRootHash - - 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 epoch
        withdrawalCertificate - - the withdrawal certificate to test
        prevWithdrawalCertificate - - the previous withdrawal certificate to test
        certSignaturesList - - the list of signatures over the message by the validators
        maxPks - - maximum number of public keys and signatures
        threshold - - minimum number of signatures that must be verified for the certificate to be accepted
        genesisKeysRootHash - - The root hash of the first block
        supportedDegree - - 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
        checkProvingKey - - enable semantic checks on the proving key (WARNING: very expensive)
        zk - - if proof must be created using zk property or not
        compressedPk - - if the pk read from provingKeyPath is in compressed form or not
        compressProof - - 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 epoch
        withdrawalCertificate - - the withdrawal certificate to test
        prevWithdrawalCertificate - - the previous withdrawal certificate to test
        certSignaturesList - - the list of signatures over the message by the validators
        maxPks - - maximum number of public keys and signatures
        threshold - - minimum number of signatures that must be verified for the certificate to be accepted
        genesisKeysRootHash - - The root hash of the first block
        supportedDegree - - 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
        checkProvingKey - - 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 epoch
        withdrawalCertificate - - the withdrawal certificate to test
        prevWithdrawalCertificate - - the previous withdrawal certificate to test
        certSignaturesList - - the list of signatures over the message by the validators
        maxPks - - maximum number of public keys and signatures
        threshold - - minimum number of signatures that must be verified for the certificate to be accepted
        genesisKeysRootHash - - The root hash of the first block
        supportedDegree - - 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
        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,
                                                    String provingKeyPath,
                                                    boolean zk)
                                             throws Exception
        Compute proof for given parameters
        Parameters:
        keysSignaturesList - - the collection of keys and signatures for this epoch
        withdrawalCertificate - - the withdrawal certificate to test
        prevWithdrawalCertificate - - the previous withdrawal certificate to test
        certSignaturesList - - the list of signatures over the message by the validators
        maxPks - - maximum number of public keys and signatures
        threshold - - minimum number of signatures that must be verified for the certificate to be accepted
        genesisKeysRootHash - - The root hash of the first block
        provingKeyPath - - file path from which reading the proving key, expected to be in compressed form
        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
      • 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 test
        prevWithdrawalCertificate - - the previous withdrawal certificate to test
        genesisConstant - - The root hash of the first block
        proof - - the bytes of the proof to be verified, expected to be in compressed form
        checkProof - - enable semantic checks on the proof
        verificationKeyPath - - file path from which loading the verification key, expected to be in compressed form
        checkVerificationKey - - 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 test
        prevWithdrawalCertificate - - the previous withdrawal certificate to test
        genesisConstant - - The root hash of the first block
        proof - - the bytes of the proof to be verified, expected to be in compressed form
        verificationKeyPath - - 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