Skip to content

Commit

Permalink
refac(crypto): allow KZG::DoMSM to populate different type of commi…
Browse files Browse the repository at this point in the history
…tment
  • Loading branch information
chokobole committed Jul 3, 2024
1 parent 8560f80 commit c300a70
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tachyon/crypto/commitments/kzg/kzg.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,32 +201,34 @@ class KZG {
}

private:
template <typename BaseContainer, typename ScalarContainer>
template <typename BaseContainer, typename ScalarContainer,
typename OutCommitment>
bool DoMSM(const BaseContainer& bases, const ScalarContainer& scalars,
Commitment* out) const {
OutCommitment* out) const {
#if TACHYON_CUDA
if (msm_gpu_) {
absl::Span<const G1Point> bases_span = absl::Span<const G1Point>(
bases.data(), std::min(bases.size(), scalars.size()));
if constexpr (std::is_same_v<Commitment, math::ProjectivePoint<Curve>>) {
if constexpr (std::is_same_v<OutCommitment,
math::ProjectivePoint<Curve>>) {
return msm_gpu_->Run(bases_span, scalars, out);
} else {
math::ProjectivePoint<Curve> result;
if (!msm_gpu_->Run(bases_span, scalars, &result)) return false;
*out = math::ConvertPoint<Commitment>(result);
*out = math::ConvertPoint<OutCommitment>(result);
return true;
}
}
#endif
math::VariableBaseMSM<G1Point> msm;
absl::Span<const G1Point> bases_span = absl::Span<const G1Point>(
bases.data(), std::min(bases.size(), scalars.size()));
if constexpr (std::is_same_v<Commitment, Bucket>) {
if constexpr (std::is_same_v<OutCommitment, Bucket>) {
return msm.Run(bases_span, scalars, out);
} else {
Bucket result;
if (!msm.Run(bases_span, scalars, &result)) return false;
*out = math::ConvertPoint<Commitment>(result);
*out = math::ConvertPoint<OutCommitment>(result);
return true;
}
}
Expand Down

0 comments on commit c300a70

Please sign in to comment.