feat(puzzle): generalize key_range#30
Merged
Merged
Conversation
- Add Puzzle::key_range() for bits 1-128 (u128) - Add Puzzle::key_range_big() for bits 1-256 (BigUint) - Remove b1000::key_range() and b1000::key_range_big() - Add build-time validation: bits must match private_key - Update CLI to use new Puzzle methods - Add tests for new methods Closes #20
Greptile SummaryMoved Key Changes:
Issues Found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI as CLI (cmd_range/show)
participant B1000 as b1000::get()
participant Puzzle as Puzzle struct
participant KeyRange as key_range_big()
User->>CLI: Request puzzle info
CLI->>B1000: get(puzzle_number)
B1000-->>CLI: Return &Puzzle
CLI->>Puzzle: Access bits field
Puzzle-->>CLI: Some(bits)
CLI->>KeyRange: p.key_range_big()
KeyRange->>KeyRange: Check bits.is_some()
KeyRange->>KeyRange: Validate 1..=256 range
KeyRange->>KeyRange: Calculate BigUint range
KeyRange-->>CLI: Some((start, end))
CLI-->>User: Display range with address
|
There was a problem hiding this comment.
1 issue found across 8 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src/puzzle.rs">
<violation number="1" location="src/puzzle.rs:143">
P1: Overflow when `bits == 128`: shifting `1u128 << 128` is undefined behavior (panic in debug, wrap in release). Handle the edge case explicitly since `u128::MAX` is the correct value for a 128-bit range.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
When bits == 128, the expression (1u128 << 128) overflows. Use u128::MAX directly for this edge case. Add test coverage for the bits == 128 boundary condition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Move
key_range()andkey_range_big()fromb1000module toPuzzlestruct, making them available for any puzzle with a known bit range.Closes #20
Changes
Puzzle::key_range()returningOption<RangeInclusive<u128>>(bits 1-128)Puzzle::key_range_big()returningOption<(BigUint, BigUint)>(bits 1-256)b1000::key_range()andb1000::key_range_big()(breaking change)bitsfield must matchprivate_keyfor solved puzzlescmd_range()andprint_puzzle_detail_table()to use new methodsBreaking Change
Testing
boha range 66,boha show b1000/66Co-Authored-By: Aei aei@oad.earth