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

RandomX commitments with double-hashing #265

Merged
merged 3 commits into from
Sep 8, 2023
Merged

RandomX commitments with double-hashing #265

merged 3 commits into from
Sep 8, 2023

Conversation

tevador
Copy link
Owner

@tevador tevador commented Apr 22, 2023

Related to this proposal: monero-project/monero#8827

The commitment is calculated from the hash and its input (i.e. the block header). The idea is that the output of randomx_calculate_hash will be appended to the block header and the difficulty will be calculated based on the output of randomx_calculate_commitment, which is very fast.

src/randomx.cpp Outdated Show resolved Hide resolved
SChernykh
SChernykh previously approved these changes Aug 16, 2023
@SChernykh
Copy link
Collaborator

Looks fine to me. What's the status of this PR? Is it the final version?

@tevador tevador marked this pull request as ready for review August 16, 2023 19:07
@tevador
Copy link
Owner Author

tevador commented Aug 16, 2023

I'm not planning any modifications to this PR unless something comes up during the review. The changes are fairly small, so it's mostly about the concept.

One thing to note is that batched hashing using the randomx_calculate_hash_next function will become slightly more complicated due to the need to recall the previous hash input when the v1 result is ready.

@SChernykh
Copy link
Collaborator

One thing to note is that batched hashing using the randomx_calculate_hash_next function will become slightly more complicated due to the need to recall the previous hash input when the v1 result is ready.

That wouldn't be an issue for mining software because it only needs to remember the previous nonce value (4 bytes). But yes, randomx_calculate_hash_next will need two more parameters for the previous input.

src/randomx.cpp Outdated
void randomx_calculate_hash_v2(const void* input, size_t inputSize, const void* v1_in, void* v2_out) {
assert(inputSize == 0 || input != nullptr);
assert(v1_in != nullptr);
assert(v2_out != nullptr);

Choose a reason for hiding this comment

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

Hi, this can help prevent user error when calling the library.
assert(v1_in != v2_out);

Copy link
Owner Author

Choose a reason for hiding this comment

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

It will work perfectly fine with v1_in == v2_out.

Choose a reason for hiding this comment

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

Thanks, good to know.

@tevador tevador changed the title RandomX v2 with double-hashing RandomX commitments with double-hashing Sep 8, 2023
@tevador
Copy link
Owner Author

tevador commented Sep 8, 2023

I renamed the new function to randomx_calculate_commitment because it provides a commitment to a RandomX hash value. The "v2" naming was not a good choice because this change is orthogonal to future VM changes that might need to be versioned.

@tevador tevador merged commit 1c603a2 into master Sep 8, 2023
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