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: handling of cairo u512 type #1022

Merged
merged 5 commits into from
Mar 22, 2024
Merged

Conversation

PhilippeR26
Copy link
Collaborator

Motivation and Resolution

The new u512 Cairo type is now implemented.
Solve issue #1013.
According to https://github.com/starkware-libs/cairo/blob/07484c52791b76abcc18fd86265756904557d0d2/corelib/src/test/integer_test.cairo#L767

The raw format is :

{
    limb0: u128, // lower weight
    limb1: u128,
    limb2: u128,
    limb3: u128, // upper weight
};

Usage related changes

User send a BigNumberish, and receive a bigint.

await myContract0.my_function(553844998243714947043252949842317834769n);
await myContract1.my_function(cairo.uint512("0xa9d2d1501ad0a2eb5337a9d2d1501ad0a2eb5337a9d2d1501ad0a2eb5337a9d2d1501ad0a2eb5337a9d2d1501ad0a2eb5337")); 
await myContract2.my_function(12345678, '13456789765', '0xe23a40b543f', 1534566734334n);
const a2: Uint512 = {
  limb0: "0xeb5337d9a885be310x9365205a414fdd",
  limb1: "0x1fd465baff2ba9d2d1501ad0a2eb5337",
  limb2: "0x05f7cd1fd465baff2ba9d2d1501ad0a2",
  limb3: "0x2eb5337d9a885be319366b5205a414fd"
};

Development related changes

A new file is in utils/cairoDataTypes, inspired from the Cairo u256 type.

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

@PhilippeR26
Copy link
Collaborator Author

@haroune-mohammedi

For u512, Starknet.js is waiting a Bignumberish.

Copy link
Collaborator

@tabaktoni tabaktoni left a comment

Choose a reason for hiding this comment

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

Look like there is some issue on validate ?

@PhilippeR26
Copy link
Collaborator Author

Look like there is some issue on validate ?

Problem from pr #1007

Solved.

@PhilippeR26 PhilippeR26 requested a review from tabaktoni March 22, 2024 09:14
@tabaktoni tabaktoni changed the base branch from develop to next-version March 22, 2024 09:20
Copy link
Collaborator

@tabaktoni tabaktoni left a comment

Choose a reason for hiding this comment

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

LGTM!

@tabaktoni tabaktoni requested a review from ivpavici March 22, 2024 09:48
@tabaktoni tabaktoni merged commit 6623ea5 into starknet-io:next-version Mar 22, 2024
3 checks passed
@tabaktoni tabaktoni mentioned this pull request Mar 22, 2024
6 tasks
@haroune-mohammedi
Copy link
Contributor

@haroune-mohammedi

For u512, Starknet.js is waiting a Bignumberish.

Will be addressed here keep-starknet-strange/abi-wan-kanabi#68

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