Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize the security_content_manager and SecurityContentService in simulator #1959

Open
holgerroth opened this issue Aug 28, 2023 · 3 comments
Labels
Feature request Ask for new features or examples

Comments

@holgerroth
Copy link
Collaborator

holgerroth commented Aug 28, 2023

This would help in experimenting with homomorphic encryption in simulation mode. Thanks @shawndengucf for raising the issue and providing a workaround.

Based on previous issue #1924. See also #1994

Thanks, @holgerroth ! It's really helpful. I created the secure_workspace and copied the whole folder to my project folder and specified the tenseal_context_file for HEModelEncryptor. However, the error persisted and I noticed that SecurityContentService doesn't get a chance to initial the security_content_manager if I submit the job with the simulator, see load_tenseal_context_from_workspace from homomorphic_encrypt.py.

I made it work by editing the function to below:

def load_tenseal_context_from_workspace(ctx_file_name: str, fl_ctx: FLContext):
    """Loads homomorphic encryption (HE) context from TenSEAL (https://github.com/OpenMined/TenSEAL) containing encryption keys and parameters.

    Args:
        ctx_file_name: filepath of TensSEAL context file
        fl_ctx: FL context

    Returns:
        TenSEAL context

    """
    is_secure_mode = fl_ctx.get_prop(FLContextKey.SECURE_MODE, True)
    if ctx_file_name != "client_context.tenseal":
        ssc = SecurityContentService()
        ssc.initialize(os.path.dirname(ctx_file_name))
        data, rc = ssc.load_content(ctx_file_name)
    else:
        data, rc = SecurityContentService.load_content(ctx_file_name)

    bad_rcs = [LoadResult.INVALID_CONTENT, LoadResult.NO_SUCH_CONTENT]
    if is_secure_mode:
        bad_rcs.extend([LoadResult.INVALID_SIGNATURE, LoadResult.NOT_SIGNED])

    if rc in bad_rcs:
        raise ValueError("Cannot load tenseal_context {}: {}".format(ctx_file_name, rc))

    context = ts.context_from(data)
    return context

Originally posted by @shawndengucf in #1924 (comment)

@chesterxgchen
Copy link
Collaborator

This is caused by "Unknown type tenseal.tensors.ckksvector.CKKSVector, ..."
which means FOBs doesn't know how serialize the object CKKSVector. If you define a decomposer for FOBs, and register the decomposer, then the serialization should pass.

@holgerroth
Copy link
Collaborator Author

@chesterxgchen , This issue is only about the secure content manager when running HE in simulation. The serialization error is discussed in this issue #1924.

@holgerroth
Copy link
Collaborator Author

Note the related issue at #1970

@YuanTingHsieh YuanTingHsieh added the Feature request Ask for new features or examples label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Ask for new features or examples
Projects
None yet
Development

No branches or pull requests

3 participants