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

Add: Cairo0 Sqrt hint #316

Merged
merged 2 commits into from
Mar 20, 2024
Merged

Add: Cairo0 Sqrt hint #316

merged 2 commits into from
Mar 20, 2024

Conversation

Tomi-3-0
Copy link
Contributor

@Tomi-3-0 Tomi-3-0 commented Mar 19, 2024

feat: Implement Cairo0 "Sqrt" hint

This PR introduces a cairo0 hint named "Sqrt" to calculate the square root of a given value while ensuring it falls within a specified range ([0, 2**250)).

The calculation utilizes the Sqrt() function from the "github.com/holiman/uint256" library, setting z (root) to ⌊√x⌋ (value), the largest integer such that z² ≤ x, and returns z.

To ensure the value remains within the specified range, the FeltLt() function from "github.com/NethermindEth/cairo-vm-go/pkg/utils" is utilized.

Accompanying tests cover various scenarios:

  • Testing the square root of 25, which is expected to be 5.
  • Handling zero input value, which is expected to be 0
  • Verifying the square root of 50, expected to be 7.xxx.... (rounded to 7).
  • Validating the square root of -127, which is expected to fail as it falls outside of the range [0, 2**250)

Relevant link:
https://github.com/holiman/uint256/blob/v1.2.3/uint256.go#L1307

This was referenced Mar 19, 2024
Copy link
Contributor

@cicr99 cicr99 left a comment

Choose a reason for hiding this comment

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

lgtm!

@cicr99 cicr99 merged commit ce40eaf into NethermindEth:main Mar 20, 2024
4 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