Skip to content

Running the computation

Run the computation

The Secure Computations will automatically run when all the participants have provided their sealed keys.

As a Result Consumer, you have created a symmetric key, sealed it with the enclave’s public key and sent it to the enclave. This is the symmetric key you will use to decrypt the results.


import time
from cosmian_secure_computation_client.crypto.helper import seal
from cosmian_secure_computation_client.crypto.helper import random_symkey

while True:
    computation = result_consumer.get_computation(computation_uuid)
    if computation.enclave.identity is None:
        print("Waiting 5s the generation of the enclave identity…")

manifest = computation.enclave.identity.manifest
quote = computation.enclave.identity.quote

symmetric_key_ro = random_symkey()
sealed_symmetric_key = seal(symmetric_key_ro, computation.enclave.identity.public_key)

result_consumer.key_provisioning(computation.uuid, sealed_symmetric_key)

This last step will automatically launch the computation.

The secure enclave does not send any message when the Secure Computation completes. You must ping it to to check the computation status.

from cosmian_secure_computation_client import ResultConsumerAPI
result_consumer = ResultConsumerAPI(cosmian_token)

while True:
    computation = result_consumer.get_computation(computation_uuid)

    if computation.runs.current is None and len(computation.runs.previous) == 1:
        run = computation.runs.previous[0]
        if run.exit_code != 0:
            print("\n\n### Exit Code ###\n")
            print("\n\n### stdout ###\n")
            print("\n\n### stderr ###\n")
            raise "Run fail."
        print("Waiting 2s end of computation…")

Fetch results

When the computation has completed, you can then fetch results.

encrypted_results = result_consumer.fetch_results(computation.uuid)

from cosmian_secure_computation_client.crypto.helper import decrypt
results = decrypt(encrypted_results, symmetric_key)

Use your symmetric key to decrypt your results.

Please note that these results are represented in bytes. Ask your Code Provider how to deserialize them.