Skip to content

obfuscate's negative-offset refusal quotes the offset through _message_text (closes #2874) - #2908

Merged
pmazzocchi merged 1 commit into
btclib-org:mainfrom
dodoshell:iss-2874-obfuscation-offset
Nov 2, 2026
Merged

pmazzocchi merged 1 commit into
btclib-org:mainfrom
dodoshell:iss-2874-obfuscation-offset

Conversation

@dodoshell

@dodoshell dodoshell commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

obfuscation.obfuscate quoted a negative offset with str(), so an offset of -10**4400 raised the builtin ValueError of str()'s digit limit instead of BTClibValueError. The refusal now quotes the offset through utils._message_text, as the non-integer refusal above it has done since #2865.

Closes #2874

How it was verified

tests/huge_int_message_test.py gains an obfuscation offset case at -_HUGE. It fails on main with the builtin ValueError and passes with the fix.

Checks

  • uv run pre-commit run --all-files is clean (ruff, mypy strict,
    markdownlint, the copyright notice, uv.lock)
  • uv run pytest passes
  • I have read and understood every line of this change, and can
    answer a review of it without the model

The pre-commit box is unticked because the hook set can't run in full on my Windows machine: the hooks that check Python files pass, and the markdown and line-ending hooks are left to CI.

Summary by CodeRabbit

  • Bug Fixes
    • Error messages for extremely large negative offsets now describe the value by its sign and bit length instead of displaying the full number, making the refusal message easier to read.

…e_text (closes btclib-org#2874)

obfuscation.obfuscate built "negative offset: {offset}" with str(), so
an offset of -10**4400 raised the builtin ValueError of str()'s digit
limit instead of BTClibValueError. The message now quotes the offset
through utils._message_text, as the non-integer refusal above it has
done since btclib-org#2865.

tests/huge_int_message_test.py gains an "obfuscation offset" case at
-_HUGE.

Signed-off-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4664cbe0-43bb-43f9-9a56-da8da1cd4290
Commits

Reviewing files that changed from the base of the PR and between 7f305e2 and fe5cf2a.

Files selected for processing: 2
  • src/btclib/obfuscation.py
  • tests/huge_int_message_test.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The negative-offset refusal message now formats the offset with _message_text. The test suite adds a case for a very large negative offset.

Changes: Negative offset handling

Layer / File(s) Summary
Format and test negative offsets
src/btclib/obfuscation.py, tests/huge_int_message_test.py
The refusal message formats the offset with _message_text. The test suite exercises this path with -_HUGE.

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: fametrano

Merge Risk: Minimal · up to fe5cf

No actionable merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: formatting the negative offset through _message_text. It is specific and related to the changeset.
Linked Issues check Passed Issue #2874 has two coding requirements. Both are met at the reviewed head.

1. The message quotes the offset through utils._message_text. In src/btclib/obfuscation.py, the negative-offset refusal…
Out of Scope Changes check Passed The whole-PR diff against the merge base 7f305e2 changes two files.

- src/btclib/obfuscation.py: one line changed, the negative-offset refusal. This is the change the issue requests.
- `tests/hug…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #2874 has two coding requirements. Both are met at the reviewed head.

  1. The message quotes the offset through utils._message_text. In src/btclib/obfuscation.py, the negative-offset refusal changed from f"negative offset: {offset}" to f"negative offset: {_message_text(offset)}". _message_text is already imported in that module and is already used by the non-integer refusal above it. A negative -10**4400 therefore no longer reaches str().

  2. tests/huge_int_message_test.py gains a case for a negative obfuscation offset of -_HUGE. The diff adds ("obfuscation offset", -_HUGE, lambda v: obfuscation.obfuscate(b"\x00", bytes(8), v)) to _CASES, and adds the obfuscation import. The shared parametrized test asserts that the call raises BTClibValueError with the message a negative int of 16610 bits. This matches the issue's requested call obfuscation.obfuscate(b"\x00", bytes(8), v) with v = -_HUGE.

The test is not run in this review. The PR author reports that it fails on main and passes with the change. The pattern matches the existing negative cases in the same table, such as coin height and halving interval, so the expected message format is consistent with the existing code.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base 7f305e2 changes two files.

  • src/btclib/obfuscation.py: one line changed, the negative-offset refusal. This is the change the issue requests.
  • tests/huge_int_message_test.py: adds the obfuscation import and one _CASES entry for obfuscation offset. This is the test the issue requests.

The PR description and the linked issue name only these two changes. No unrelated code, configuration, dependency, or documentation change appears in the diff. The uv.lock file is not changed.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@pmazzocchi

Copy link
Copy Markdown
Contributor

Claimed: a /btclib-pr session of @pmazzocchi is reviewing this pull request locally before deciding on its approval.

@pmazzocchi pmazzocchi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve fe5cf2a, following @pmazzocchi's decision to approve the pull requests a local review clears.

A fresh local reviewer, run in Claude Code (Codex is not installed on this machine), answered CLEARED fe5cf2aa69b9 on the merge with main 7f305e2; no rebase since. It ran obfuscate's refusal from the parent and the head on -(10**4300) and -10**5000: the parent raises the builtin ValueError of the 4300-digit limit, the head raises BTClibValueError with a negative int of … bits, and -1, the 4300-digit boundary and an IntEnum read the same on both. The review bot does not run on a fork's pull request, so there is no ACK; every check passed or was skipped, including the whole suite (run 41503667610), and no thread is open. Not checked: the inputs through an installed btclib, since the local install was refused, and Python 3.11.

@pmazzocchi
pmazzocchi merged commit 95dbf35 into btclib-org:main Nov 2, 2026
21 checks passed
@pmazzocchi

Copy link
Copy Markdown
Contributor

Thank you, @dodoshell: this landed as 95dbf35, and ISS #2874 is closed.

Your change makes obfuscate refuse a negative offset too long for str() with BTClibValueError, as every other refusal does, instead of leaking the builtin ValueError of Python's 4300-digit limit. Quoting values through utils._message_text is how the library keeps an error message from failing on the very value it reports, and your test case pins it at -_HUGE so that it stays that way. Nothing was added on top: the squash message only drops the "since #2865" history, since the tree's prose says what is true now.

@pmazzocchi

Copy link
Copy Markdown
Contributor

Released: the /btclib-pr session is done with this pull request.

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.

obfuscation.obfuscate raises ValueError for a negative offset too long to print

2 participants