예제 #1
0
def test_create_petition_with_rng():
    script = """Scenario 'coconut': "Citizen creates a new petition"
    Given I have inside 'issuer identifier' a valid 'ca_verify'
    and I have a valid 'credential proof'
    and I have a valid 'petition'
    When I aggregate verifiers from 'ca_verify'
    and I verify the credential proof is correct
    and I verify the new petition to be empty
    Then print the 'petition'
    and print the 'verifiers'
    """
    keys = '{"issuer_identifier": {"ca_verify": {"alpha": "u64:CTkI_DudfVF9QbyRQjfue_ajdLGmeP5Ednd_j5efcy-WFUmEgqHpxYaAgvGTqcppCly7HNt_qBIzJk9IdlR_RBBEqebNV6jPqudNqGKTwcTo2B806nYRuCEnL97hj7xgDtXNSHu3bf57eEAE2vEcPPmamBHajNtLzRMmM74YwmYwtqZ-F-N2-RliXexESTMQBN8YdWoawA548_S6Ait6sphvrIw4E-Tu2Ti5uDFEYUJ7Muwus8fB0QHB3djmPaiA", "beta": "u64:DhlbAie3DM8ZLfPeg9lU02koN5J0mHqDkY10nO0bMvIevMRsRnoztEOId5MllVSeVEgLkhykaDO7ZO50O9TE-5Php7f5XtyWntl0KwGOLzoH3zvdQ2yBl6WHZpBWk7rmAw6KBAQ3IeDWbZ_-pd7I-IyaXh4KI8X2h7v6aqZ1OKWHgMkqmFZfLUmsfmxppqw3Idr5CTqsnttuwFpyLrUv86pbsQ2jCuicCcVFlRMs0Nsf_wKidyVdnkC73cpsnKWQ"}}}'
    data = ' {"credential_proof": {"kappa": "u64:Ekm_B59fBdzG3FBEEBtpIu4weaT_luV0sFG8zVZi0TWgxQicy9SL8Tr7NhoiCiS1SIk_HOnqQ8GXtNTAlUXg13R4E9rejKRJw30TF0AGJ6qDduZUPzvwvkiwjxXVvdqoNd30J4wQpcEkhIn03XABIVlOKVjIKPJxwZa3SXWsSsbKMrR0PdZi69-gAaReIjkKSiiYmWsrk7TVujObpQWN9q6hrRK8jyQ1y_epb-lOqDD_D-wv8av1MnsTjHZkt6IG", "nu": "u64:BEELrHoEpGEtmjAsJyQEqar3Sf4NyzmW4IipWCa8S23rFM9vMLl_GDUypI8GPcxLRBJBNFwSF2dY1cxcplFrm9rcM5hBrc5R8wv-QzWojMKCH8bL1JIO1vmILhdsbcimSQ", "pi_v": {"c": "u64:eWVEdfGaITBeGttVMcpF4vttK0rXoV-s2M1uIT-naxI", "rm": "u64:Y6Hk8MDpkdhzmrjTAPuNrgadB9KZQ2Llo7pLoNGPI9U", "rr": "u64:4I9cla6nDJ7AkLVYF33KzOPZK5Ovps6DS0TlX_fcFWU"}, "sigma_prime": {"h_prime": "u64:BBs1WW358uQYckW_DotJ8qefvlQwCX67UKUqvJdC_G7Y064lnDIafza4EgsMBARaIggd4Xg7qZCfkZzjQpfSgKBOIGyc2gUjOEAiZEvDCqbIAJEzzuF_3bVR0-NKNHGXKQ", "s_prime": "u64:BCCFu9VkSz4FiS3090o4zlHWQGnpa3dHurPUhErctBvIJ8CrWeeO6rwgrmgoYKf96ybErbDiphKlh2SIipDPEyVUQxRiNquRWXbJG8rIGUjBHNZ6Z97YOnFf0BCn9icVyA"}}, "petition": {"owner": "u64:BAnXgbjfC-25YaXPjT68wpxxcHWMYMzVdvq8W12fhJR0_l55MtQHLXjjYliES8DDiz9dTXc_5n-8bIFptRiwTPnheJlmE6JBawm4t6GYI7JMjcwwB0Uh4KfD6OunqRm2_w", "scores": {"neg": {"left": "Infinity", "right": "Infinity"}, "pos": {"left": "Infinity", "right": "Infinity"}}, "uid": "u64:tion"}}'

    results = []
    for _ in range(LOAD_FATIGUE):
        result, error = zenroom.zencode_exec_rng(
            script=script,
            data=data,
            keys=keys,
            random_seed=bytearray("random_se3d", "utf=8"),
        )
        sorted_result = json.dumps(json.loads(result), sort_keys=True)
        results.append(sorted_result)
        print(sorted_result)
    assert len(set(results)) == 1
예제 #2
0
    def count_petition(self):
        zencode = """Scenario coconut: count petition
Given that I have a valid 'petition'
and I have a valid 'petition tally'
When I count the petition results
Then print the 'results'
            """
        petition = zencode_exec_rng(
            script=zencode,
            random_seed=bytearray(self.seed, "utf=8"),
            keys=self.payload.keys,
            data=self.lookup_petition(),
        )
        LOG.debug("PETITION COUNT")
        LOG.info(petition.stdout)
예제 #3
0
    def tally_petition(self):
        zencode = """Scenario coconut: tally petition
Given that I am 'Alice'
and I have my valid 'credential keypair'
and I have a valid 'petition'
When I create a petition tally
Then print all data
        """
        petition = zencode_exec_rng(
            script=zencode,
            random_seed=bytearray(self.seed, "utf=8"),
            keys=self.payload.keys,
            data=self.lookup_petition(),
        )
        LOG.debug("PETITION TALLIED")
        LOG.info(petition.stdout)
예제 #4
0
 def tally_petition(self):
     zencode = """Scenario 'coconut': "Close the petition, formally the tally"
     Given that I am known as 'identifier'
     and I have my valid 'credential_keypair'
     and I have a valid 'petition'
     When I tally the petition
     Then print the 'petition'
     and print the 'petition_tally'
     """
     petition, _ = zencode_exec_rng(
         script=zencode,
         random_seed=bytearray(self.seed, "utf=8"),
         keys=self.payload.keys,
         data=self.lookup_petition(),
     )
     self.save_petition_state(petition)
     LOG.debug("PETITION TALLIED")
예제 #5
0
 def sign_petition(self):
     zencode = """Scenario 'coconut': "Add a signature to the petition"
     Given that I have a valid 'petition_signature'
     and I have a valid 'petition'
     and I have a valid 'verifiers'
     When the petition signature is not a duplicate
     and the petition signature is just one more
     and I add the signature to the petition
     Then print the 'petition'
     and print the 'verifiers'
     """
     petition, _ = zencode_exec_rng(
         script=zencode,
         random_seed=bytearray(self.seed, "utf=8"),
         keys=self.lookup_petition(),
         data=self.payload.keys,
     )
     self.save_petition_state(petition)
     LOG.debug("PETITION SIGNED")
예제 #6
0
 def create_petition(self):
     zencode = f"""Scenario 'coconut': "Create a new petition"
     Given I have inside 'issuer identifier' a valid 'ca_verify'
     and I have a valid 'credential proof'
     and I have a valid 'petition'
     When I aggregate verifiers from 'ca_verify'
     and I verify the credential proof is correct
     and I verify the new petition to be empty
     Then print the 'petition'
     and print the 'verifiers'
     """
     petition, _ = zencode_exec_rng(
         script=zencode,
         random_seed=bytearray(self.seed, "utf=8"),
         keys=self.payload.keys,
         data=self.payload.data,
     )
     self.save_petition_state(petition)
     LOG.debug("PETITION CREATED")
예제 #7
0
 def apply(self, transaction, context):
     try:
         script, data, keys, context_id = decode_transaction(transaction)
         LOG.debug(
             f"Context Id: ${context_id}\nExecuting Zencode: ${script}")
         payload = self.retrieve_payload()
         result, _ = zenroom.zencode_exec_rng(
             script=script,
             data=data,
             keys=keys,
             random_seed=bytearray(payload, "utf=8"),
         )
         json_result = json.dumps(json.loads(result), sort_keys=True)
         LOG.debug(json_result)
         save_state(context, context_id, json_result)
     except Exception:
         LOG.exception("Exception saving state")
         raise InvalidTransaction(
             "An error happened tying to process tx, see logs")
예제 #8
0
    def create_petition(self):
        zencode = f"""Scenario coconut: approve petition
Given that I have a valid 'verifier' from 'MadHatter'
and I have a valid 'credential proof'
and I have a valid 'petition'
When I aggregate the verifiers
and I verify the credential proof
and I verify the new petition to be empty
Then print the 'petition'
and print the 'verifiers'
        """
        result = zencode_exec_rng(
            script=zencode,
            random_seed=bytearray(self.seed, "utf=8"),
            keys=self.payload.keys,
            data=self.payload.data,
        )
        self.save_petition_state(result.stdout)
        LOG.debug("PETITION CREATED")