Skip to content

Reject negative bigint hexlify values#77

Open
samsamtrum wants to merge 1 commit into
etherspot:masterfrom
samsamtrum:reject-negative-bigint-hexlify
Open

Reject negative bigint hexlify values#77
samsamtrum wants to merge 1 commit into
etherspot:masterfrom
samsamtrum:reject-negative-bigint-hexlify

Conversation

@samsamtrum

@samsamtrum samsamtrum commented Jun 21, 2026

Copy link
Copy Markdown

Negative bigint values currently produce malformed hex strings like 0x-1 or 0x0-10 in hexlifyValue.

This rejects negative bigint inputs before conversion, matching the existing unsigned checks for number inputs.

Summary by CodeRabbit

  • Bug Fixes

    • Added validation to reject invalid inputs during hexadecimal conversion operations.
  • Tests

    • Added comprehensive test coverage for hexadecimal conversion functionality.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5d84b4a0-cd1a-4147-9aca-bb47cb0b70c7

📥 Commits

Reviewing files that changed from the base of the PR and between 30f4b8d and c16782e.

📒 Files selected for processing (2)
  • src/sdk/common/utils/hexlify.ts
  • test/hexlify.test.ts

📝 Walkthrough

Walkthrough

hexlifyValue gains a guard in its bigint branch that throws an Error for negative bigint inputs. A new test file verifies correct zero-padded hex output for non-negative bigints (0n, 15n, 16n) and asserts that negative values (-1n, -16n) throw with a message matching /negative bigint value/.

Changes

Negative bigint guard in hexlifyValue

Layer / File(s) Summary
Negative bigint guard and test coverage
src/sdk/common/utils/hexlify.ts, test/hexlify.test.ts
hexlifyValue now throws an Error when a negative bigint is passed. The new test suite covers zero-padded hex output for 0n, 15n, and 16n, and verifies that −1n and −16n throw with the expected error message.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A bunny checked the numbers with care,
No negatives allowed in hex land, beware!
Zero, fifteen, sixteen — all neat,
Minus one tried to sneak in — delete! 🐇
The tests stood guard with a watchful eye,
Now only happy bigints hex-ify!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description explains the problem and solution but is missing required template sections like Types of changes and a proper Description section. Complete the pull request description by filling out the required sections including Types of changes (mark Bugfix) and expand the Description section with more detail.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: rejecting negative bigint values in the hexlify function.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/sdk/common/utils/hexlify.ts

Oops! Something went wrong! :(

ESLint: 8.28.0

ReferenceError: Cannot read config file: /.eslintrc.js
Error: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///.eslintrc.js:1:1
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:541:37)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:366:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1649:24)
at Module._compile (node:internal/modules/cjs/loader:1812:5)
at Object..js (node:internal/modules/cjs/loader:1961:10)
at Module.load (node:internal/modules/cjs/loader:1553:32)
at Module._load (node:internal/modules/cjs/loader:1355:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at Module.require (node:internal/modules/cjs/loader:1576:12)

test/hexlify.test.ts

Oops! Something went wrong! :(

ESLint: 8.28.0

ReferenceError: Cannot read config file: /.eslintrc.js
Error: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///.eslintrc.js:1:1
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:541:37)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:366:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1649:24)
at Module._compile (node:internal/modules/cjs/loader:1812:5)
at Object..js (node:internal/modules/cjs/loader:1961:10)
at Module.load (node:internal/modules/cjs/loader:1553:32)
at Module._load (node:internal/modules/cjs/loader:1355:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at Module.require (node:internal/modules/cjs/loader:1576:12)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant