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

fix(katana-primitives): fix legacy program conversion between RPC and inner types #1403

Merged
merged 3 commits into from
Jan 9, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 8, 2024

Resolves #1356

This PR fixes how legacy contract class is being converted between RPC types (from starknet-rs) and blockifier types (from cairo-vm).

There are some discrepancies for the compiled program types between what is defined by starknet-rs and cairo-vm by lambdaclass. The types from cairo-vm isn't really meant to be used for serialization. As such, it is not possible to convert between the types between these two crates without losing some of the data. For context, there are some fields that exist in starknet-rs definitions but not in cairo-vm's. Which results in the omission some fields during conversions.

I have defined some intermediary types that mirrors the types from those crates in order to be able to de/serialize them into each other. The intermediary types are then transmuted to their original counterpart (This is kinda unsafe as these types don't use a #[repr(..)] that would guarantee their memory layout, so they might have different layouts even if all the fields are in the same order and types. Though I'm not certain how likely that's gonna happen). Perhaps the use of the intermediary types should be better documented for future readers.

A simple test is added just to check that the conversions process is successful. The test doesn't however assert that the types are equal before and after the conversion due to the aforementioned reason.

I believe this is definitely not the most efficient way for doing this conversion. Improvements should be reserved in future PRs.

@kariy kariy linked an issue Jan 8, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (74c12c0) 67.10% compared to head (0d4994d) 67.42%.
Report is 1 commits behind head on main.

Files Patch % Lines
crates/katana/primitives/src/conversion/rpc.rs 99.52% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1403      +/-   ##
==========================================
+ Coverage   67.10%   67.42%   +0.31%     
==========================================
  Files         231      231              
  Lines       20858    21047     +189     
==========================================
+ Hits        13997    14191     +194     
+ Misses       6861     6856       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy
Copy link
Member Author

kariy commented Jan 8, 2024

I've spent an unnecessary amount of time trying to implement an approach that doesn't involve modifying our fork of blockifier/cairo-vm.

Will follow this up with a test for the non-legacy contract class conversions.

@kariy
Copy link
Member Author

kariy commented Jan 8, 2024

During the process of implementing this PR, a bug is found due to mistakenly inserting compiled class hashes instead of just class hash. The fix for it is in #1404.

@kariy kariy changed the title fix(katana-primitives): de/serialize into correct format fix(katana-primitives): fix legacy program conversion between RPC and inner types Jan 8, 2024
@kariy kariy changed the base branch from main to dev/katana January 9, 2024 04:51
@kariy kariy merged commit 00bce7c into dev/katana Jan 9, 2024
10 checks passed
@kariy kariy deleted the 1356-katana-migration-error-on-forked-katana branch January 9, 2024 04:52
@kariy kariy restored the 1356-katana-migration-error-on-forked-katana branch January 9, 2024 04:54
kariy added a commit that referenced this pull request Jan 10, 2024
kariy added a commit that referenced this pull request Jan 11, 2024
kariy added a commit that referenced this pull request Jan 11, 2024
kariy added a commit that referenced this pull request Jan 15, 2024
@kariy kariy deleted the 1356-katana-migration-error-on-forked-katana branch January 16, 2024 13:17
@kariy kariy mentioned this pull request Jan 16, 2024
kariy added a commit that referenced this pull request Jan 17, 2024
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