Skip to content

Conversation

@brunocapelao
Copy link

Summary

Fix a bug in the hex_or_base64() function where digits (0-9) were not recognized as valid lowercase hex characters.

Problem

The original code used is_ascii_lowercase() to check for lowercase hex characters:

s.bytes().all(|b| b.is_ascii_hexdigit() && b.is_ascii_lowercase())

However, is_ascii_lowercase() returns false for digits 0-9, causing valid lowercase hex strings like "0a1b2c3d" to be incorrectly parsed as base64 instead of hex.

Solution

Use explicit pattern matching for valid lowercase hex characters (0-9, a-f):

s.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f'))

Testing

This bug was discovered while using hal-simplicity for Simplicity transactions on Liquid Testnet. After the fix, hex strings containing digits are correctly parsed.

The is_ascii_lowercase() method returns false for digits (0-9), causing
valid lowercase hex strings like '0a1b2c3d' to be incorrectly parsed as
base64 instead of hex.

This fix uses explicit pattern matching for valid lowercase hex
characters (0-9, a-f) to correctly identify hex-encoded strings.
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