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

(De)serialize values without any modificaiton for PrimeField #421

Open
chokobole opened this issue May 20, 2024 · 0 comments
Open

(De)serialize values without any modificaiton for PrimeField #421

chokobole opened this issue May 20, 2024 · 0 comments

Comments

@chokobole
Copy link
Contributor

chokobole commented May 20, 2024

Issue type

Performance

Current behavior?

For the prime fields that supports montgomery reduction, it is serialized with a call ToBigInt(), which causes not only montgomery reductions but also uses the size than the required size of prime field.

Expected Behavior?

(De)serializes the value using value().

template <typename T>
class Copyable<
    T, std::enable_if_t<std::is_base_of_v<math::PrimeFieldBase<T>, T>>> {
 public:
  static bool WriteTo(const T& prime_field, Buffer* buffer) {
    return buffer->Write(prime_field.value());
  }

  static bool ReadFrom(const ReadOnlyBuffer& buffer, T* prime_field) {
    using value_type = typename T::value_type;
    value_type v;
    if (!buffer.Read(&v)) return false;
    if constexpr (T::Config::kUseMontgomery) {
      *prime_field = T::FromMontgomery(v);
    } else {
      *prime_field = T(v);
    }
    return true;
  }

  static size_t EstimateSize(const T& prime_field) {
    using value_type = typename T::value_type;
    return sizeof(value_type);
  }
};
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

No branches or pull requests

1 participant