Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sha and hash to field #5

Merged
merged 17 commits into from
Oct 17, 2024

Conversation

petscheit
Copy link
Contributor

Pull Request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Testing
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this introduce a breaking change?

  • Yes
  • No

Other information

@petscheit petscheit marked this pull request as ready for review October 15, 2024 13:39
src/basic_field_ops.cairo Outdated Show resolved Hide resolved
src/hash_to_field.cairo Outdated Show resolved Hide resolved
src/hash_to_field.cairo Outdated Show resolved Hide resolved
src/hash_to_field.cairo Show resolved Hide resolved
src/hash_to_field.cairo Outdated Show resolved Hide resolved
src/sha.cairo Outdated Show resolved Hide resolved
src/sha.cairo Show resolved Hide resolved
tests/fustat_programs/test_hash_to_field.cairo Outdated Show resolved Hide resolved
Comment on lines +53 to +64
def hex_to_chunks_32(hex_string: str):
# Remove '0x' prefix if present
if hex_string.startswith(('0x', '0X')):
hex_string = hex_string[2:]

# if we have an odd number of characters, prepend a 0
if len(hex_string) % 2 == 1:
hex_string = '0' + hex_string

# Now split into 8-character (32-bit) chunks
chunks = [int(hex_string[i:i+8], 16) for i in range(0, len(hex_string), 8)]
return chunks
Copy link
Owner

Choose a reason for hiding this comment

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

Use garaga.hints.io.bigint_split

It Works with bytes as well.

chunks = io.bigint_split(hasher.digest(), 8, 2**32)[::-1]

Copy link
Contributor Author

@petscheit petscheit Oct 16, 2024

Choose a reason for hiding this comment

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

super neat these functions!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test keeps breaking, as I have variable length inputs, and need to compute n_limbs which keeps going wrong.

@petscheit petscheit force-pushed the feat/sha_and_hash_to_field branch from 2965790 to 342a217 Compare October 16, 2024 13:08
@petscheit petscheit force-pushed the feat/sha_and_hash_to_field branch from 342a217 to 21457b9 Compare October 16, 2024 14:13
@feltroidprime feltroidprime merged commit dc02aa3 into feltroidprime:main Oct 17, 2024
2 checks passed
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.

2 participants