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

Make felt_from_number report errors properly #1012

Merged
merged 8 commits into from
May 20, 2023

Conversation

omerfirmak
Copy link
Contributor

@omerfirmak omerfirmak commented Apr 19, 2023

Make felt_from_number report errors properly

Description

fixed not reporting the parse error properly

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

@Oppen
Copy link
Contributor

Oppen commented Apr 19, 2023

Hi @omerfirmak, thanks for the PR. I'm not quite sure I understand it tho.
Is there a real world program that failed to parse due to lack of support for scientific notation?
Why is it converting the parsed input into a float? Do note this loses data. In fact, most of the prime field values lose a lot of information when doing this (everything above 2^64 loses low bits).

@omerfirmak
Copy link
Contributor Author

Hi @omerfirmak, thanks for the PR. I'm not quite sure I understand it tho. Is there a real world program that failed to parse due to lack of support for scientific notation? Why is it converting the parsed input into a float? Do note this loses data. In fact, most of the prime field values lose a lot of information when doing this (everything above 2^64 loses low bits).

for example

https://alpha-mainnet.starknet.io/feeder_gateway/get_class_by_hash?classHash=0x3297a93c52357144b7da71296d7e8231c3e0959f0a1d37222204f2f7712010e

search for starkware.starknet.common.syscalls.CALL_CONTRACT_SELECTOR

Do note this loses data. In fact, most of the prime field values lose a lot of information when doing this (everything above 2^64 loses low bits).

I wasnt aware, any alternatives that won't be causing any data loss?

@Oppen
Copy link
Contributor

Oppen commented Apr 20, 2023

search for starkware.starknet.common.syscalls.CALL_CONTRACT_SELECTOR

This is the only match I found, it's not in scientific notation here:

"starkware.starknet.common.syscalls.CALL_CONTRACT_SELECTOR": {"value": 20853273475220472486191784820, "type": "const"}

I wasnt aware, any alternatives that won't be causing any data loss?

I can see if I find some arbitrary precision decimal crates that we can use. Alternatively, I guess there's also the option of storing the mantissa as a separate number (would usize be enough?) and the digits as a BigUint or some scheme like that.

@omerfirmak
Copy link
Contributor Author

omerfirmak commented Apr 20, 2023

This is the only match I found, it's not in scientific notation here:

Oh damn, it must be my browser messing up the value somehow when pretty printing. If I dont pretty print it is a plain integer.

Sorry for the confusion.

@omerfirmak omerfirmak closed this Apr 20, 2023
@omerfirmak omerfirmak reopened this Apr 20, 2023
@omerfirmak
Copy link
Contributor Author

Dropping the scientific notation part of this PR and keeping the proper error reporting.

@omerfirmak omerfirmak force-pushed the fix-felt-from-num branch 2 times, most recently from ee0a5b3 to f6bf547 Compare April 20, 2023 07:33
@omerfirmak omerfirmak changed the title Fix felt_from_number Make felt_from_number report errors properly Apr 20, 2023
@Oppen
Copy link
Contributor

Oppen commented Apr 20, 2023

We would need to fix the changelog. The Hyperfine workflow failing is just a matter of permissions, it can't post the comment when the PR comes from outside this repo (it's a limitation of the action we use), so it doesn't matter. I checked manually that was the issue.

@codecov
Copy link

codecov bot commented Apr 20, 2023

Codecov Report

Merging #1012 (fbac71d) into main (92a81f7) will decrease coverage by 0.01%.
The diff coverage is 92.30%.

@@            Coverage Diff             @@
##             main    #1012      +/-   ##
==========================================
- Coverage   97.71%   97.71%   -0.01%     
==========================================
  Files          89       89              
  Lines       35725    35737      +12     
==========================================
+ Hits        34908    34919      +11     
- Misses        817      818       +1     
Impacted Files Coverage Δ
src/serde/deserialize_program.rs 97.41% <92.30%> (-0.07%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Oppen
Copy link
Contributor

Oppen commented Apr 20, 2023

It also seems like we're missing a test case hitting the error.

@Oppen
Copy link
Contributor

Oppen commented Apr 20, 2023

BTW @omerfirmak let me know if you need help with the CHANGELOG. The format is a bit ad-hoc.

@Oppen
Copy link
Contributor

Oppen commented Apr 25, 2023

Hi @omerfirmak. We'll need you to run cargo fmt on the PR and solve conflicts with the changelog. After that it's ready to go.

instead of returning Ok(None) in case of an error
@omerfirmak
Copy link
Contributor Author

Hi @omerfirmak. We'll need you to run cargo fmt on the PR and solve conflicts with the changelog. After that it's ready to go.

Done

@Oppen Oppen enabled auto-merge April 26, 2023 23:20
auto-merge was automatically disabled April 27, 2023 08:41

Head branch was pushed to by a user without write access

@omerfirmak
Copy link
Contributor Author

omerfirmak commented Apr 27, 2023

This in-repo CHANGELOG so annoying, it makes PRs race against each other to get merged first. Otherwise you get conflicts.

Commits and their messages are changelogs anyways, I suggest you to try enforcing better commit messages instead of an in-repo changelog.

@Oppen
Copy link
Contributor

Oppen commented Apr 27, 2023

This in-repo CHANGELOG so annoying, it makes PRs race against each other to get merged first. Otherwise you get conflicts.

Commits and their messages are changelogs anyways, I suggest you to try enforcing better commit messages instead of an in-repo changelog.

Yes. I personally want to go with that approach, but we try to keep things democratic in the team so I need to make my point more convincing before doing that, as there may be some drawbacks (say, whatever we use to generate the file afterwards should give some freedom to edits, otherwise it may not be great to read). This input actually helps for that :)

Do note even then the changelog would be in-repo, just not manually updated on each PR. Relying on commit messages for end users would not be great UX/DX.

@Oppen Oppen enabled auto-merge April 30, 2023 21:10
@Oppen Oppen disabled auto-merge April 30, 2023 22:18
@Oppen Oppen enabled auto-merge May 12, 2023 04:26
@Oppen Oppen added this pull request to the merge queue May 15, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks May 15, 2023
@Oppen Oppen enabled auto-merge May 20, 2023 01:29
@Oppen Oppen added this pull request to the merge queue May 20, 2023
Merged via the queue into lambdaclass:main with commit e173ec9 May 20, 2023
@omerfirmak omerfirmak deleted the fix-felt-from-num branch May 20, 2023 06:53
kariy pushed a commit to dojoengine/cairo-rs that referenced this pull request Jun 23, 2023
instead of returning Ok(None) in case of an error

Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>
Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
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.

4 participants