-
Notifications
You must be signed in to change notification settings - Fork 756
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: CairoFelt252 class #1146
base: develop
Are you sure you want to change the base?
feat: CairoFelt252 class #1146
Conversation
@ivpavici please take a look if this is what you had in mind when the Cairo data types issue was created. Please confirm if that's correct, or something else needs to be done. |
Yep, it seems good. WP! 🎸 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General approach looks good to me.
Tests could be tweaked a bit. Noticed that some are almost equivalents, e.g. non-ascii check and exceeding max safe integer. Values from constants.ts could be used for some tests, such as using PRIME
where uint256 is mentioned.
@tabaktoni @ivpavici @PhilippeR26 There are some good points about potential behaviour changes mentioned in the test comments that we should probably decide on before the next major release such as hex validation and value bound checks. Another that might also make sense is number handling, currently positive and negative numbers are treated differently: |
@penovicp the tests are pretty much a verbatim copy of the existing ones for I wanted to make sure they are passing with this new class approach. I will obviously tweak and do some more passes over everything now that I know this is the direction that we want to take. |
-1 ? |
The linked issue #1116 lists the signed integer types as planned for future support after |
So, does it mean that currently only TypedData will use negative numbers, and all the rest of snjs is not use them (validate, requestParser, responseParser) ? Right? Also, I don't understand why to accept negative input on felt252. By definition, a felt252 do not accept negative numbers ; only i8,i16, i32, i64 and i128 are authorized in Cairo to handle negative numbers. |
For negative numbers the class could throw a validation error, or they could be serialised as I'm currently not advocating for a specific approach, just wanted to point out some of the class behaviour we might want to change now that it's being reworked. For a different example: how should the class behave for numbers with values larger than PRIME. |
Felt support storing negative as P-value. So we can throw a warning on negative with the recommendation of using iN |
I remember when felt where renamed felt252 in Cairo 1. Abdel asked to the community how to rename felt. One of the popular proposal was u252... |
src/utils/cairoDataTypes/felt252.ts
Outdated
import { BigNumberish, isBigInt, isBoolean, isHex, isStringWholeNumber } from '../num'; | ||
import { encodeShortString, isLongText, isShortText, isString } from '../shortString'; | ||
|
||
type ParsableTypes = BigNumberish | Boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be like this? instead of boolean constructor
type ParsableTypes = BigNumberish | Boolean; | |
type ParsableTypes = BigNumberish | boolean; |
- replace the previous utility function where needed
fbce638
to
e7595d5
Compare
Draft PR info!
This is a draft PR to check the validity of the approach.
Will update the description with proper info after confirmation, when the PR is ready.
Solves the Felt part of #1116
Motivation and Resolution
...
RPC version (if applicable)
...
Usage related changes
Development related changes
Checklist: