Serialize and Deserialize between wasm and python

Hello,

I comprehend that the WebAssembly (openfhe-Wasm) library is still under development and may not be fully stable. In my usage, I employed the Wasm library to serialize ciphertext, but encountered an error when attempting to deserialize it using a openfhe-Python library. The specific error message reads:

RuntimeError: Error while trying to deserialize a polymorphic pointer. Could not find type id 169877536.

Could you kindly assist me in comprehending the root cause of this issue and resolving it? Your assistance would be greatly appreciated.

Thank you in advance.

Thanks. The wasm bindings are not fully functional yet. So it is possible there is an issue with serialization.

Something to check. Are you using the same OpenFHE version for both Python and WASM bindings? Are you using the same format, i.e., JSON or binary? The error seems to imply that the serialization formats are different (maybe a different version of OpenFHE is used?).

The problem occurred during serialization because I inadvertently passed “BINARY” as a string instead of using the correct format, which should have been something like “module.sertype.BINARY”. Additionally, I ensured that both instances of the openfhe library were the same version to avoid compatibility issues.

Thank you

Hey I updated the openfhe library to 1.2.1 and compiled the openfhe-python with 0.8.9

When I try to deserialise openfhe-wasm serialized crypto context I get error
ValueError: vector::_M_default_append

when I try to deserialised crypto context from python in wasm I get the issue

std::length_error: vector
    at ___cxa_throw (webpack-internal:///(app-pages-browser)/./src/lib/openfhe/openfhe.js:1188:29)
    at openfhe.wasm.std::__2::__throw_length_error[abi:ne180100](char const*) (http://localhost:3000/openfhe.wasm:wasm-function[732]:0x3902e)
    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::__throw_length_error[abi:ne180100]() const (http://localhost:3000/openfhe.wasm:wasm-function[2531]:0x6fbba)
    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::__recommend[abi:ne180100](unsigned long) const (http://localhost:3000/openfhe.wasm:wasm-function[2522]:0x6f536)
    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::__append(unsigned long) (http://localhost:3000/openfhe.wasm:wasm-function[15222]:0x1e7610)
    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::resize(unsigned long) (http://localhost:3000/openfhe.wasm:wasm-function[15195]:0x1e67e7)
    at openfhe.wasm.std::__2::enable_if<traits::is_input_serializable<cereal::BinaryData<unsigned int>, cereal::PortableBinaryInputArchive>::value && std::is_arithmetic<unsigned int>::value && !std::is_same<unsigned int, bool>::value, void>::type cereal::load<cereal::PortableBinaryInputArchive, unsigned int, std::__2::allocator<unsigned int>>(cereal::PortableBinaryInputArchive&, std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&) (http://localhost:3000/openfhe.wasm:wasm-function[29162]:0x3c82dd)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::processImpl<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>, (cereal::traits::detail::sfinae)0>(std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&) (http://localhost:3000/openfhe.wasm:wasm-function[29160]:0x3c81e2)
    at openfhe.wasm.void cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::process<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>(std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&) (http://localhost:3000/openfhe.wasm:wasm-function[29158]:0x3c8141)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::operator()<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>(std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&) (http://localhost:3000/openfhe.wasm:wasm-function[29157]:0x3c80b8)
    at openfhe.wasm.std::__2::enable_if<cereal::traits::is_same_archive<cereal::PortableBinaryInputArchive, cereal::PortableBinaryInputArchive>::value || cereal::traits::is_same_archive<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>::value, void>::type cereal::serialize<cereal::PortableBinaryInputArchive, std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>(cereal::PortableBinaryInputArchive&, cereal::NameValuePair<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>&) (http://localhost:3000/openfhe.wasm:wasm-function[29156]:0x3c805d)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::processImpl<cereal::NameValuePair<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>, (cereal::traits::detail::sfinae)0>(cereal::NameValuePair<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>&) (http://localhost:3000/openfhe.wasm:wasm-function[29154]:0x3c7fcc)
    at openfhe.wasm.void cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::process<cereal::NameValuePair<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>>(cereal::NameValuePair<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>&&) (http://localhost:3000/openfhe.wasm:wasm-function[29151]:0x3c7ed2)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::operator()<cereal::NameValuePair<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>>(cereal::NameValuePair<std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>&>&&) (http://localhost:3000/openfhe.wasm:wasm-function[29150]:0x3c7e49)
    at openfhe.wasm.void bigintdyn::ubint<unsigned int>::load<cereal::PortableBinaryInputArchive>(cereal::PortableBinaryInputArchive&, unsigned int) (http://localhost:3000/openfhe.wasm:wasm-function[29147]:0x3c7d49)
    at openfhe.wasm.decltype(fp0.load(fp, fp1)) cereal::access::member_load<cereal::PortableBinaryInputArchive, bigintdyn::ubint<unsigned int>>(cereal::PortableBinaryInputArchive&, bigintdyn::ubint<unsigned int>&, unsigned int) (http://localhost:3000/openfhe.wasm:wasm-function[29146]:0x3c7af3)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::processImpl<bigintdyn::ubint<unsigned int>, (cereal::traits::detail::sfinae)0>(bigintdyn::ubint<unsigned int>&) (http://localhost:3000/openfhe.wasm:wasm-function[29143]:0x3c7787)
    at openfhe.wasm.void cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::process<bigintdyn::ubint<unsigned int>&>(bigintdyn::ubint<unsigned int>&) (http://localhost:3000/openfhe.wasm:wasm-function[29141]:0x3c76c9)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::operator()<bigintdyn::ubint<unsigned int>&>(bigintdyn::ubint<unsigned int>&) (http://localhost:3000/openfhe.wasm:wasm-function[29140]:0x3c7640)
    at openfhe.wasm.std::__2::enable_if<cereal::traits::is_same_archive<cereal::PortableBinaryInputArchive, cereal::PortableBinaryInputArchive>::value || cereal::traits::is_same_archive<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>::value, void>::type cereal::serialize<cereal::PortableBinaryInputArchive, bigintdyn::ubint<unsigned int>&>(cereal::PortableBinaryInputArchive&, cereal::NameValuePair<bigintdyn::ubint<unsigned int>&>&) (http://localhost:3000/openfhe.wasm:wasm-function[29139]:0x3c75e5)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::processImpl<cereal::NameValuePair<bigintdyn::ubint<unsigned int>&>, (cereal::traits::detail::sfinae)0>(cereal::NameValuePair<bigintdyn::ubint<unsigned int>&>&) (http://localhost:3000/openfhe.wasm:wasm-function[29137]:0x3c7554)
    at openfhe.wasm.void cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::process<cereal::NameValuePair<bigintdyn::ubint<unsigned int>&>>(cereal::NameValuePair<bigintdyn::ubint<unsigned int>&>&&) (http://localhost:3000/openfhe.wasm:wasm-function[29134]:0x3c745a)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::operator()<cereal::NameValuePair<bigintdyn::ubint<unsigned int>&>>(cereal::NameValuePair<bigintdyn::ubint<unsigned int>&>&&) (http://localhost:3000/openfhe.wasm:wasm-function[29133]:0x3c73d1)
    at openfhe.wasm.void lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>::load<cereal::PortableBinaryInputArchive>(cereal::PortableBinaryInputArchive&, unsigned int) (http://localhost:3000/openfhe.wasm:wasm-function[29130]:0x3c727a)
    at openfhe.wasm.decltype(fp0.load(fp, fp1)) cereal::access::member_load<cereal::PortableBinaryInputArchive, lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>>(cereal::PortableBinaryInputArchive&, lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>&, unsigned int) (http://localhost:3000/openfhe.wasm:wasm-function[29129]:0x3c6ef0)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::processImpl<lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>, (cereal::traits::detail::sfinae)0>(lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>&) (http://localhost:3000/openfhe.wasm:wasm-function[29127]:0x3c6bab)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::processImpl<lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>>(cereal::base_class<lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>>&) (http://localhost:3000/openfhe.wasm:wasm-function[29125]:0x3c6afa)
    at openfhe.wasm.void cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::process<cereal::base_class<lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>>>(cereal::base_class<lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>>&&) (http://localhost:3000/openfhe.wasm:wasm-function[29121]:0x3c6960)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::operator()<cereal::base_class<lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>>>(cereal::base_class<lbcrypto::ElemParams<bigintdyn::ubint<unsigned int>>>&&) (http://localhost:3000/openfhe.wasm:wasm-function[29118]:0x3c6819)
    at openfhe.wasm.void lbcrypto::ILDCRTParams<bigintdyn::ubint<unsigned int>>::load<cereal::PortableBinaryInputArchive>(cereal::PortableBinaryInputArchive&, unsigned int) (http://localhost:3000/openfhe.wasm:wasm-function[29116]:0x3c6766)
    at openfhe.wasm.decltype(fp0.load(fp, fp1)) cereal::access::member_load<cereal::PortableBinaryInputArchive, lbcrypto::ILDCRTParams<bigintdyn::ubint<unsigned int>>>(cereal::PortableBinaryInputArchive&, lbcrypto::ILDCRTParams<bigintdyn::ubint<unsigned int>>&, unsigned int) (http://localhost:3000/openfhe.wasm:wasm-function[29115]:0x3c6525)
    at openfhe.wasm.cereal::PortableBinaryInputArchive& cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::processImpl<lbcrypto::ILDCRTParams<bigintdyn::ubint<unsigned int>>, (cereal::traits::detail::sfinae)0>(lbcrypto::ILDCRTParams<bigintdyn::ubint<unsigned int>>&) (http://localhost:3000/openfhe.wasm:wasm-function[29112]:0x3c61b9)
    at openfhe.wasm.void cereal::InputArchive<cereal::PortableBinaryInputArchive, 1u>::process<lbcrypto::ILDCRTParams<bigintdyn::ubint<unsigned… ……
arg0: std::length_error: vector\n    at ___cxa_throw (webpack-internal:///(app-pages-browser)/./src/lib/openfhe/openfhe.js:1188:29)\n    at openfhe.wasm.std::__2::__throw_length_error[abi:ne180100](char const*) (http://localhost:3000/openfhe.wasm:wasm-function[732]:0x3902e)\n    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::__throw_length_error[abi:ne180100]() const (http://localhost:3000/openfhe.wasm:wasm-function[2531]:0x6fbba)\n    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::__recommend[abi:ne180100](unsigned long) const (http://localhost:3000/openfhe.wasm:wasm-function[2522]:0x6f536)\n    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::__append(unsigned long) (http://localhost:3000/openfhe.wasm:wasm-function[15222]:0x1e7610)\n    at openfhe.wasm.std::__2::vector<unsigned int, std::__2::allocator<unsigned int>>::resize(unsigned long) (http://localhost:3000/openfhe.wasm:wasm-function… …
eval @ repl:8:15

Looks like the core library std::vector is trying to be resized to a size that is invalid (likely too large).

Before cross compatibility used to work, there were no issue

Could you kindly assist me in understanding and fix this issue

Thanks in advance

Please create a new topic for a new issue.