Skip to content

fix: reject booleans in isinstance int checks - #161

Open
dinxsh wants to merge 5 commits into
ethereum:mainfrom
dinxsh:fix/reject-booleans-isinstance
Open

fix: reject booleans in isinstance int checks#161
dinxsh wants to merge 5 commits into
ethereum:mainfrom
dinxsh:fix/reject-booleans-isinstance

Conversation

@dinxsh

@dinxsh dinxsh commented May 3, 2026

Copy link
Copy Markdown

Fixes #30

Python's bool is a subclass of int, so isinstance(True, int) returns True. In cryptographic code this is dangerous - a boolean passed where an integer is expected can produce incorrect results silently.

Changes:

  • Adds is_integer() utility in py_ecc/utils.py that explicitly rejects booleans
  • Updates field arithmetic checks in field_elements.py, optimized_field_elements.py, ciphersuites.py to use it
  • Adds tests verifying booleans are rejected and integers accepted

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.

Cleanup isinstance checks for integers to disallow booleans

1 participant