Skip to content

Add serialization functionality - #104

Merged
sloede merged 19 commits into
hpsc-lab:mainfrom
Tom-Finke:serial
Jun 25, 2026
Merged

Add serialization functionality#104
sloede merged 19 commits into
hpsc-lab:mainfrom
Tom-Finke:serial

Conversation

@Tom-Finke

Copy link
Copy Markdown
Collaborator

No description provided.

@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

Pipeline fails because OpenFHE will expose SerializeToString and DeserializeFromString only when hpsc-lab/openfhe-julia#129 is implemented.

@Tom-Finke
Tom-Finke marked this pull request as ready for review May 20, 2026 15:11
@Tom-Finke
Tom-Finke requested a review from sloede May 20, 2026 15:11
@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

@sloede this is ready for a first review despite the failing pipeline, see comment above.

@sloede

sloede commented May 28, 2026

Copy link
Copy Markdown
Member

Note that the implementation might have to change very soon again, see openfheorg/openfhe-development#1191. We should thus discuss if we still want to use the effectively deprecated API or rather find a "proper" solution to serializing/deserializing right now.

@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

As I understand it, openfheorg/openfhe-development#1191 removes only the override for cryptocontext serialization which is implemented in cryptocontext-ser.h, this should not be a problem. The implementation in serial.h seems to be identical, so wen can already leave out the override for cryptocontext on our side in anticipation of this change.

@Tom-Finke

Tom-Finke commented May 28, 2026

Copy link
Copy Markdown
Collaborator Author

ToDos:

  • test type stability, e.g. by using @code_warntype
  • exported serialize function overwrites julia standard serialize function. Instead: rename to serialize_to_json_string. Note in the docs that this is an experimental implementation and could change over time
  • research the canonical way for serializing objects containing pointers to C objects
  • serialize SecureArithmetic objects directly instead of OpenFHE objects
    • Over julia API? Probably not ideal, we dont know exactly what julia will do and we want full control over serialization
    • Alternative: wrapper functions have SecureArithmetic objects as parameters and construct / deconstruct them internally

Tom-Finke added 3 commits June 1, 2026 12:19
Rename `serialize` → `serialize_to_json_string` and `deserialize` → `deserialize_from_json_string`
to avoid overwriting `Serialization.serialize`/`Serialization.deserialize` from Julia's stdlib.

Add experimental warnings to serialization docstrings and
cross-references between string-based and file-based variants.
- overload julia stdlib serialization and
- work directly with SecureArithmetic objects
@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

@sloede I reworked the serialization implementation so it overloads Julias Serialization.jl functions serialize and deserialize.

At the moment, this serialized OpenFHE objects to JSON strings in the background. This does not make a lot of sense since the output is still not human readable, because we have to serialize the json string with Julias standard serialization function and add additional information to the serialized stream. This makes it non-human-readable, thus json does not make any sense for this application.

We could save a lot of space by switching to binary serialization on the OpenFHE side. As we saw, they only implement binary serialization is serialize to file. We could mitigate this by passing std::ostringstream to lbcrypto::Serial::Serialize instead of a file handle like openfhe does internally when calling SerializeToFile.

If we still want to support serialization to JSON for human readability: we could use JSON.jl to serialize to and from JSON. We would have to wrap the json we get from openfhe, because the Secure Arithmetic serializations need additional information like the cryptocontext, shape and capacity.

@sloede

sloede commented Jun 8, 2026

Copy link
Copy Markdown
Member

Thanks a lot for the summary. Let's put the focus on creating an MVP first, then optimizing it later. Thus I'd say if the current PR already supports what we want to do (albeit less efficiently), then let's move forward and create an issue for the discussed potential improvements.

@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

@sloede I just created a new release for openfhe-julia which includes the code for exposing the serialization functionality. This new functionality never touches OpenFHE.jl. But SecureArithmetic only depends on OpenFHE.jl, not openfhe_julia. But this particular feature requires a minimum version of openfhe_julia (the new v0.6.1) to work. We cannot simply add openfhe_julia as a dependency, because of the compatibility issues we are trying to solve with hpsc-lab/OpenFHE.jl#123. I see three options:

  • OpenFHE.jl release with new version bound on openfhe_julia. Add the new version of OpenFHE.jl as the new bound in SecureArithmetic.jl.
  • Add both openfhe_julia_jll and OpenFHE_jll as a dependency to SecureArithmetic. This means we will have to manage the correct lower and upper version bounds in both SecureArithmetic.jl and OpenFHE.jl, which introduces the risk of compatibility mismatch.
  • Add only openfhe_julia_jll to SecureArithmetic as a dependency. Revert our decision to manage compatibility between openfhe_julia_jll and OpenFHE_jll on OpenFHE.jl, and instead manage the compatibility directly openfhe_julia_jll via Yggdrasil / the Julia General Registry.

@sloede

sloede commented Jun 10, 2026

Copy link
Copy Markdown
Member

SA.jl should only depend on OpenFHE.jl and be shielded from any upstream shenanigans. AFAICT, releasing the new version of OpenFHE.jl with compat bounds on both openfhe-julia and OpenFHE_jll would allow us to just bump the lower bound for OpenFHE.jl in SA.jl's Project.toml, right? If yes, then let's do it this way.

@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

SA.jl should only depend on OpenFHE.jl and be shielded from any upstream shenanigans.

I agree.

AFAICT, releasing the new version of OpenFHE.jl with compat bounds on both openfhe-julia and OpenFHE_jll would allow us to just bump the lower bound for OpenFHE.jl in SA.jl's Project.toml, right? If yes, then let's do it this way.

Yes, but only if we also bump the minimum required openfhe-julia version in the new OpenFHE.jl release to v0.6.1.

Plan:

Comment thread benchmark/serialization_sizes.jl
Comment thread Project.toml
Comment thread src/openfhe.jl Outdated
Comment thread src/openfhe.jl
Comment thread src/openfhe.jl Outdated
Tom-Finke and others added 4 commits June 10, 2026 17:32
Use loop instead of map

Co-authored-by: Michael Schlottke-Lakemper <michael@sloede.com>
…or experimental state of serialization functions
Comment thread src/openfhe.jl Outdated
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
benchmark/serialization_sizes.jl 100.00% <100.00%> (ø)
src/SecureArithmetic.jl 100.00% <ø> (ø)
src/openfhe.jl 95.50% <100.00%> (+0.65%) ⬆️
src/operations.jl 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tom-Finke
Tom-Finke requested a review from sloede June 23, 2026 06:26
@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

@sloede CI already passes with current openfhe-julia release, the OpenFHE.jl release is on its way with hpsc-lab/OpenFHE.jl#126.

@sloede

sloede commented Jun 23, 2026

Copy link
Copy Markdown
Member

Before I review, please address my open comments above. If you fixed/addressed them, please mark them as resolved (with our without commenting). If they are not relevant anymore, just say so in the comment and mark as resolved. If you are unsure how to respond, just ask :-)

If everything is resolved (or responded to), please ping me again.

@Tom-Finke

Copy link
Copy Markdown
Collaborator Author

@sloede I marked everything as resolved except the unit tests for the benchmark script. We can either remove the script or add a smoke test, but proper unit tests do not seem fitting.

@sloede

sloede commented Jun 23, 2026

Copy link
Copy Markdown
Member

@sloede I marked everything as resolved

Thanks!

except the unit tests for the benchmark script. We can either remove the script or add a smoke test, but proper unit tests do not seem fitting.

I think running this as part of the tests, but rather a as a smoke test (i.e., it runs without warnings), would be good. As I said before, you should also add the benchmark directory to the list of directories covered by Codecov/Coveralls/whatever we use here :-)

Comment thread src/openfhe.jl
Comment thread src/openfhe.jl Outdated
Comment thread test/Project.toml
Co-authored-by: Michael Schlottke-Lakemper <michael@sloede.com>

@sloede sloede left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@sloede
sloede merged commit b375f0c into hpsc-lab:main Jun 25, 2026
11 checks passed
@Tom-Finke
Tom-Finke deleted the serial branch June 25, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants