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

equihash: Add Rust API for Tromp solver #1083

Merged
merged 21 commits into from
Feb 14, 2025
Merged

equihash: Add Rust API for Tromp solver #1083

merged 21 commits into from
Feb 14, 2025

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Jan 4, 2024

No description provided.

@str4d str4d force-pushed the equihash-solver-tromp branch from cb60b5b to f3ea80e Compare January 4, 2024 18:47
Copy link

codecov bot commented Jan 4, 2024

Codecov Report

Attention: Patch coverage is 57.37705% with 26 lines in your changes missing coverage. Please review.

Project coverage is 54.37%. Comparing base (0432867) to head (f3d5a5c).
Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
components/equihash/src/tromp.rs 0.00% 26 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1083   +/-   ##
=======================================
  Coverage   54.36%   54.37%           
=======================================
  Files         175      176    +1     
  Lines       20325    20385   +60     
=======================================
+ Hits        11050    11084   +34     
- Misses       9275     9301   +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@str4d
Copy link
Contributor Author

str4d commented Apr 18, 2024

Force-pushed to clean up the commit history; no changes to @teor2345's changes, just regrouping them (and squashing some of the fixes into the original commits that didn't make sense to keep in standalone commits).

@str4d str4d force-pushed the equihash-solver-tromp branch from d33ec1d to 9dbdf18 Compare April 18, 2024 20:13
@str4d
Copy link
Contributor Author

str4d commented Apr 18, 2024

Force-pushed to GitHub-linkify an imported source link in a commit message.

@str4d str4d closed this Apr 18, 2024
@str4d str4d deleted the equihash-solver-tromp branch April 18, 2024 20:14
@str4d str4d restored the equihash-solver-tromp branch April 18, 2024 20:14
@str4d str4d reopened this Apr 18, 2024
@str4d
Copy link
Contributor Author

str4d commented Apr 18, 2024

And somehow I managed to click two wrong buttons in a row 🤦

.collect()
.collect();

// Just in case the solver returns solutions that become the same when compressed.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this should ever be the case. The compressed representation should not be lossy, it just packs the indices together to remove the effective padding bits that exist in the u32 representation.

Copy link
Contributor

@arya2 arya2 May 4, 2024

Choose a reason for hiding this comment

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

It may not have been observed, or there could be a subtle difference between the C code and the Rust code in compress_array().

Update: Yeah, something must be wrong if identical solutions were observed, I'll check for changes to the logic in equi_miner.c, everything else looks equivalent to the zcashd logic.

Update: Duplicate solutions were observed prior to a bug fix, is there any chance that the solver could produce duplicate uncompressed solutions?

@@ -70,13 +71,21 @@ unsafe fn worker(eq: *mut CEqui, p: verify::Params, curr_state: &State) -> Vec<V
let nsols = equi_nsols(eq);
let sols = equi_sols(eq);
let solution_len = 1 << p.k;
//println!("{nsols} solutions of length {solution_len} at {sols:?}");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm inclined to remove this and the other introduced debugging print statements, unless anyone else disagrees.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep the debug print statements and consider adding more.

@str4d str4d force-pushed the equihash-solver-tromp branch from 9dbdf18 to b201c10 Compare April 18, 2024 20:52
@str4d
Copy link
Contributor Author

str4d commented Apr 18, 2024

Force-pushed to clean up the feature flagging in the build script, and add C #ifdefs to prevent some warnings.

@str4d str4d mentioned this pull request Apr 18, 2024
@str4d str4d force-pushed the equihash-solver-tromp branch from b201c10 to be16706 Compare April 18, 2024 23:21
@str4d
Copy link
Contributor Author

str4d commented Apr 18, 2024

Rebased on current main. I will rebase this PR again once #1357 merges.

@str4d str4d force-pushed the equihash-solver-tromp branch from 6571aa9 to 76131db Compare April 19, 2024 02:28
@str4d
Copy link
Contributor Author

str4d commented Apr 19, 2024

Force-pushed to adjust the minimal-form compression method APIs and integrate them into the existing tests.

@str4d str4d marked this pull request as ready for review April 19, 2024 02:34
@arya2 arya2 self-requested a review June 20, 2024 15:05
Copy link
Contributor

@arya2 arya2 left a comment

Choose a reason for hiding this comment

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

This looks like it should work so far, and none of my suggestions are blockers, feel free to resolve any/all of them without making changes.

I'm still reviewing equi_miner.c in detail, but everything else looks equivalent to the logic in zcashd, at least for the Mainnet parameters.

Update: Collision errors are still being logged here (and DuplicateIdxs errors).

Comment on lines +37 to +38
)
.wrapping_shl(8 * (in_width - x - 1) as u32); // Big-endian
Copy link
Contributor

@arya2 arya2 Jul 5, 2024

Choose a reason for hiding this comment

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

This seems like an unnecessary change from the c++ logic, it should panic in minimal_from_indices() before it gets here when using parameters that would be affected by the change.

Suggested change
)
.wrapping_shl(8 * (in_width - x - 1) as u32); // Big-endian
) << (8 * (in_width - x - 1) as u32); // Big-endian

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible this is a problem if it's different than what the original code was doing?

Copy link
Contributor

@arya2 arya2 left a comment

Choose a reason for hiding this comment

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

@str4d Testing indicates that there are still some issues in equi_miner.c, but I think we should document this as an experimental feature and otherwise merge it as-is, because it usually works, the occasional unexpected errors are handled gracefully, the internal-miner feature in Zebra that uses it is already documented as experimental, we need to merge it to publish a version of zebrad that could support a Zebra-only Testnet, and zcashd is being deprecated soon enough that de-duplicating the code here with what zcashd is using may not be worthwhile.

We could try porting it over to Rust or fixing the occasional issues in the current C code once the resource-constrained steps needed to deploy NU7 are complete. Running this code via Zebra could produce some helpful debug output if we keep the debug print statements and perhaps add more of them.

If we don't want to document it as an experimental feature, a pair review of equi_miner.c could be helpful for figuring out what's causing the Collision and DuplicateIdxserrors.

Co-authored-by: Arya <aryasolhi@gmail.com>
arya2
arya2 previously approved these changes Nov 1, 2024
@mpguerra
Copy link

Do we want to merge this one? It's blocking us from restoring the internal-miner feature in zebra

Copy link
Contributor Author

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK f3d5a5c. I've made the changes I wanted for the release; the remaining issues are non-blocking and can be fixed over time.

@mpguerra mpguerra requested review from teor2345 and removed request for teor2345 February 13, 2025 09:07
@nuttycom nuttycom requested a review from arya2 February 13, 2025 14:08
Copy link
Contributor

@arya2 arya2 left a comment

Choose a reason for hiding this comment

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

Thank you!!

@str4d str4d merged commit 094e0eb into main Feb 14, 2025
35 checks passed
@str4d str4d deleted the equihash-solver-tromp branch February 14, 2025 02:36
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.

5 participants