Skip to content

Rewrite tiny doublesha256#1

Open
entropycoset wants to merge 2 commits into
mi4uu:mainfrom
entropycoset:rewrite_tiny_doublesha256
Open

Rewrite tiny doublesha256#1
entropycoset wants to merge 2 commits into
mi4uu:mainfrom
entropycoset:rewrite_tiny_doublesha256

Conversation

@entropycoset

@entropycoset entropycoset commented Jun 30, 2025

Copy link
Copy Markdown

Summary by Sourcery

Simplify the double SHA-256 implementation and improve test coverage for address hashing and validation.

Enhancements:

  • Nest Sha256::digest calls in double_sha256 to inline the hashing steps

Tests:

  • Add a unit test verifying the double SHA-256 hash of "abc" matches the expected value
  • Include extra invalid address cases (an extra character and empty string) in compatibility tests

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR streamlines the double_sha256 function by using a nested SHA-256 call, adds a unit test to verify its output, and broadens compatibility tests with additional invalid address cases.

Class diagram for Address double_sha256 refactor and new test

classDiagram
    class Address {
        +fn double_sha256(data: &[u8]) -> [u8; 32]
    }
    class tests {
        +fn test_calculate_double_sha()
    }
Loading

File-Level Changes

Change Details Files
Simplify double_sha256 implementation
  • Removed intermediate first_hash and second_hash variables
  • Replaced two separate digest calls with a nested Sha256::digest call
  • Converted digest output directly into a fixed-size array
src/ecc/address.rs
Add unit test for double_sha256
  • Inserted hash_to_str helper to format output as hex
  • Created test_calculate_double_sha to assert known hash for "abc"
src/ecc/address.rs
Extend compatibility tests with extra invalid addresses
  • Added an address with an extra character to invalid list
  • Added an empty string case to invalid list
tests/compatibility/ecc_compatibility.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @entropycoset - I've reviewed your changes - here's some feedback:

  • Consider using the hex crate’s encode function in test_calculate_double_sha instead of the manual write! loop to simplify and clarify the hex formatting.
  • The one-liner Sha256::digest(Sha256::digest(data)).into() is concise but adding a brief doc comment or retaining the intermediate variables could improve readability for future maintainers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using the `hex` crate’s `encode` function in `test_calculate_double_sha` instead of the manual `write!` loop to simplify and clarify the hex formatting.
- The one-liner `Sha256::digest(Sha256::digest(data)).into()` is concise but adding a brief doc comment or retaining the intermediate variables could improve readability for future maintainers.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant