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

fix sumcheck transcript-config copy rather than move #799

Merged
merged 5 commits into from
Mar 6, 2025

Conversation

yshekel
Copy link
Collaborator

@yshekel yshekel commented Mar 5, 2025

This PR addresses a critical issue in the SumcheckTranscript API where move semantics are improperly implemented due to the use of const rvalue references. This misuse leads to unintended copying of objects instead of moving them, which contradicts the original design intentions and can lead to performance degradation, especially since some of the data structures involved (like labels and public data) are potentially large.

Issues Addressed:

  1. Const Rvalue Reference Misuse: The API currently accepts and stores configurations as const rvalue references (const SumcheckTranscriptConfig<S>&&). This approach mistakenly assumes that objects can be moved efficiently, but due to their constness, they are actually copied. This undermines the efficiency of move semantics.
  2. Faulty Move Operations in Tests: The associated tests incorrectly move an object twice. This behavior, under normal circumstances, should lead to undefined behavior but appears to work correctly due to the accidental copying. This masks potential bugs and can lead to false positives during testing.

cuda-backend-branch: yshekel/fix_sumcheck_transcript

@yshekel yshekel force-pushed the yshekel/fix_sumcheck_transcript_bug branch from 4dba784 to 5077034 Compare March 6, 2025 10:13
@@ -82,7 +82,7 @@ namespace icicle {

// Move Constructor
SumcheckTranscriptConfig(SumcheckTranscriptConfig&& other) noexcept
: m_hasher(other.m_hasher), m_domain_separator_label(std::move(other.m_domain_separator_label)),
: m_hasher(std::move(other.m_hasher)), m_domain_separator_label(std::move(other.m_domain_separator_label)),
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have move for hasher?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's more correct for a move constructor. In this case copy is cheap but still.

const bool m_little_endian = true; ///< Encoding endianness (default: little-endian).
F m_seed_rng; ///< Seed for initializing the RNG.
Hash m_hasher; ///< Hash function used for randomness generation.
std::vector<std::byte> m_domain_separator_label; ///< Label for the domain separator in the transcript.
Copy link
Contributor

Choose a reason for hiding this comment

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

why not const?
doesn't it work with the move?

Copy link
Collaborator Author

@yshekel yshekel Mar 6, 2025

Choose a reason for hiding this comment

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

Yes it makes the move copy instead. Now I test it in one test. I tried different things to make it const but failed

@yshekel yshekel force-pushed the yshekel/fix_sumcheck_transcript_bug branch from 5077034 to 45cafa0 Compare March 6, 2025 10:20
@yshekel yshekel merged commit dc771f6 into main Mar 6, 2025
16 checks passed
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.

3 participants