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 contract class unmarshall for modern cairo compilers #656

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

baitcode
Copy link

@baitcode baitcode commented Jan 17, 2025

Fixes: #655

Added workaround for abi data that is not string, but json object.

  • added contract casm compiled by scarn 2.7.0 compiler
  • added tests to unmarshall contract class from new casm json format

Fix ClassHash calculation for casm compiled classes for modern cairo compilers

  • Added bytecode_segment_lengths field to CasmClass, allowing for backward compatibility
  • Added NestedUInts type to handle deserialisation of CasmClass
  • Added test to check that ClassHash now respects bytecode_segment_lengths and calculates correct value

Here is the snippet for hash values generation with starknet.py:

https://gist.github.com/baitcode/5adec0f74121d0ae3a09aaf573ff8665

* added contract casm compiled by scarn 2.7.0 compiler
* added tests to unmarshall contract class from new casm json format
…compilers

* Added bytecode_segment_lengths field to CasmClass, allowing for backward compatibility
* Added NestedUInts type to handle deserialisation of CasmClass
* Added test to check that ClassHash now respects bytecode_segment_lengths and calculates correct value
… of Declare transation

* Simplify nested string
Copy link
Collaborator

@thiagodeev thiagodeev left a comment

Choose a reason for hiding this comment

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

Thanks for your help, @baitcode!
I left some comments, mostly about testing

.tool-versions Outdated Show resolved Hide resolved
account/account.go Outdated Show resolved Hide resolved
contracts/contracts_test.go Outdated Show resolved Hide resolved
hash/hash_test.go Outdated Show resolved Hide resolved
hash/hash_test.go Show resolved Hide resolved
@baitcode
Copy link
Author

baitcode commented Feb 3, 2025

@thiagodeev Fixed!

Added argent account contract v0.4.0 to hash tests.

@baitcode baitcode requested a review from thiagodeev February 3, 2025 16:54
Copy link
Collaborator

@thiagodeev thiagodeev left a comment

Choose a reason for hiding this comment

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

Thanks @baitcode. Some new observations about testing

rpc/types_contract.go Show resolved Hide resolved
hash/hash_test.go Outdated Show resolved Hide resolved
contracts/contracts_test.go Outdated Show resolved Hide resolved
contracts/contracts.go Show resolved Hide resolved
@baitcode
Copy link
Author

baitcode commented Feb 7, 2025

@thiagodeev Thank you very much for the review. I've fixed all the comments.

Copy link
Collaborator

@thiagodeev thiagodeev left a comment

Choose a reason for hiding this comment

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

Thanks @baitcode! Nice work.
Just a few requests:


expectedEntryPoint := testCase.ExpectedCasmClass.EntryPointByType

// External
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can just use:

assert.Equal(t, casmClass.EntryPointByType.External, expectedEntryPoint.External)
assert.Equal(t, casmClass.EntryPointByType.Constructor, expectedEntryPoint.Constructor)
assert.Equal(t, casmClass.EntryPointByType.L1Handler, expectedEntryPoint.L1Handler)

Copy link
Author

Choose a reason for hiding this comment

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

I can't remember why exactly I decided to compare everything explicitly so will have to fix. Will leave a comment next time.

hash/hash.go Outdated
return felt.Zero.Add(
zero := &felt.Felt{}

return zero.Add(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need a new var, we can just pass new(felt.Felt) directly

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for catching!

contracts/contracts.go Show resolved Hide resolved
@baitcode baitcode requested a review from thiagodeev February 12, 2025 12:51
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.

Support for modern CASM format
2 participants