Add Uint512Serializer for Cairo uint512 type support #1641
+238
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the missing
Uint512Serializerto support serialization and deserialization of 512-bit unsigned integers in Cairo contracts.Implementation
The
Uint512Serializerfollows the same architectural pattern as the existingUint256Serializerbut extends support to 512-bit values. A uint512 is represented in Cairo as a structure with four uint128 components:{limb0: Uint128, limb1: Uint128, limb2: Uint128, limb3: Uint128}Key Features
value = limb3×2^384 + limb2×2^256 + limb1×2^128 + limb0Usage Examples
Files Added/Modified
starknet_py/serialization/data_serializers/uint512_serializer.py- Main implementationstarknet_py/tests/unit/serialization/data_serializers/uint512_serializer_test.py- Comprehensive testsstarknet_py/cairo/felt.py- Addeduint512_range_checkfunctionstarknet_py/serialization/data_serializers/__init__.py- Export new serializerTesting
The implementation includes comprehensive tests covering:
All tests follow the same patterns as existing serializer tests to maintain consistency.
Fixes #1639.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.