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

Rpo256: Add RpoDigest conversions #311

Merged
merged 1 commit into from
May 6, 2024
Merged

Conversation

hackaugusto
Copy link
Contributor

Describe your changes

While writing the issues for the proposed trait implementations I noticed some missing conversions. This adds a bunch.

Note: This is a backwards incompatible change, because now there are multiple conversions for arrays. However, I think the new code is actually shorter and easier to use.

Checklist before requesting a review

  • Repo forked and branch created from next according to naming convention.
  • Commit messages and codestyle follow conventions.
  • Relevant issues are linked in the PR description.
  • Tests added for new functionality.
  • Documentation/comments updated according to changes.

@@ -287,8 +287,7 @@ fn test_empty_leaf_hash() {
#[test]
fn test_smt_get_value() {
let key_1: RpoDigest = RpoDigest::from([ONE, ONE, ONE, ONE]);
let key_2: RpoDigest =
RpoDigest::from([2_u32.into(), 2_u32.into(), 2_u32.into(), 2_u32.into()]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is an example were backwards compatibility is broken. The compiler doesn't know the type .into() should go to, because there are new valid targets (bool, u8, u16, u32).

The fix is to remove the .into(). IMO the result is more readable.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! One comment: we should probably make similar changes for RpxDigest as we try to keep them equivalent.

@hackaugusto hackaugusto force-pushed the hacka-rpo-digest-conversions branch from b53e4b7 to 977ebc4 Compare May 6, 2024 06:26
Copy link

sonarcloud bot commented May 6, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@hackaugusto
Copy link
Contributor Author

we should probably make similar changes for RpxDigest as we try to keep them equivalent.

synchronized the files

@hackaugusto hackaugusto merged commit ae22edc into next May 6, 2024
11 checks passed
@hackaugusto hackaugusto deleted the hacka-rpo-digest-conversions branch May 6, 2024 21:58
Comment on lines +121 to +124
#[derive(Copy, Clone, Debug)]
pub enum RpxDigestError {
InvalidInteger,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I noticed: I don't think this or the RpoDigestError are exported from the crate. This probably doesn't cause any immediate issues, but may be a good idea to export them.

@hackaugusto hackaugusto mentioned this pull request May 7, 2024
bobbinth pushed a commit that referenced this pull request May 11, 2024
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.

2 participants