From ffcc501cb69e2905452c6267a2216ada57c8d906 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 29 Oct 2024 11:56:30 +0100 Subject: [PATCH 01/18] Remove unused import --- starknet_py/tests/e2e/client/client_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index 8c9d17200..bc4ddc4a8 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -19,7 +19,6 @@ InvokeTransactionV3, L1HandlerTransaction, PriceUnit, - ResourceBounds, ResourceBoundsMapping, SierraContractClass, SierraEntryPointsByType, From c2db084f687f07028a0f4d18a3870537fc5753ff Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 29 Oct 2024 15:01:06 +0100 Subject: [PATCH 02/18] Add `get_compiled_casm` in `Client` and `FullNodeClient` --- starknet_py/net/client.py | 11 ++++++++++- starknet_py/net/full_node_client.py | 11 +++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/starknet_py/net/client.py b/starknet_py/net/client.py index 43126fc11..91372c84c 100644 --- a/starknet_py/net/client.py +++ b/starknet_py/net/client.py @@ -27,7 +27,7 @@ TransactionExecutionStatus, TransactionReceipt, TransactionStatus, - TransactionStatusResponse, + TransactionStatusResponse, CasmClass, ) from starknet_py.net.models.transaction import ( AccountTransaction, @@ -340,3 +340,12 @@ async def get_messages_status( :param l1_transaction_hash: Hash of the L1 transaction :return: Status of the messages """ + + @abstractmethod + async def get_compiled_casm(self, class_hash: int) -> CasmClass: + """ + Get the contract class definition in the given block associated with the given hash. + + :param class_hash: Hash of the contract class whose CASM will be returned + :return: CasmClass object + """ diff --git a/starknet_py/net/full_node_client.py b/starknet_py/net/full_node_client.py index d4af9a079..d70750af8 100644 --- a/starknet_py/net/full_node_client.py +++ b/starknet_py/net/full_node_client.py @@ -38,7 +38,7 @@ Transaction, TransactionReceipt, TransactionStatusResponse, - TransactionTrace, + TransactionTrace, CasmClass, ) from starknet_py.net.client_utils import ( _create_broadcasted_txn, @@ -68,7 +68,7 @@ from starknet_py.net.schemas.rpc.contract import ( DeprecatedContractClassSchema, SierraContractClassSchema, - SyncStatusSchema, + SyncStatusSchema, CasmClassSchema, ) from starknet_py.net.schemas.rpc.event import EventsChunkSchema from starknet_py.net.schemas.rpc.general import EstimatedFeeSchema @@ -705,6 +705,13 @@ async def get_contract_nonce( res = cast(str, res) return int(res, 16) + async def get_compiled_casm(self, class_hash: int) -> CasmClass: + res = await self._client.call( + method_name="getCompiledCasm", + params={"class_hash": class_hash}, + ) + return cast(CasmClass, CasmClassSchema().load(res)) + async def spec_version(self) -> str: """ Returns the version of the Starknet JSON-RPC specification being used. From 3feacddac0c2c9f382b1be7dd7ea191935257291 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 29 Oct 2024 15:03:25 +0100 Subject: [PATCH 03/18] Add `get_compiled_casm` in `Client` and `FullNodeClient` --- starknet_py/net/client.py | 3 ++- starknet_py/net/full_node_client.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/starknet_py/net/client.py b/starknet_py/net/client.py index 91372c84c..8dbf92566 100644 --- a/starknet_py/net/client.py +++ b/starknet_py/net/client.py @@ -9,6 +9,7 @@ BlockStateUpdate, BlockTransactionTrace, Call, + CasmClass, ContractStorageKeys, DeclareTransactionResponse, DeployAccountTransactionResponse, @@ -27,7 +28,7 @@ TransactionExecutionStatus, TransactionReceipt, TransactionStatus, - TransactionStatusResponse, CasmClass, + TransactionStatusResponse, ) from starknet_py.net.models.transaction import ( AccountTransaction, diff --git a/starknet_py/net/full_node_client.py b/starknet_py/net/full_node_client.py index d70750af8..5eb550116 100644 --- a/starknet_py/net/full_node_client.py +++ b/starknet_py/net/full_node_client.py @@ -11,6 +11,7 @@ BlockStateUpdate, BlockTransactionTrace, Call, + CasmClass, ContractStorageKeys, DeclareTransactionResponse, DeployAccountTransactionResponse, @@ -38,7 +39,7 @@ Transaction, TransactionReceipt, TransactionStatusResponse, - TransactionTrace, CasmClass, + TransactionTrace, ) from starknet_py.net.client_utils import ( _create_broadcasted_txn, @@ -66,9 +67,10 @@ StarknetBlockWithTxHashesSchema, ) from starknet_py.net.schemas.rpc.contract import ( + CasmClassSchema, DeprecatedContractClassSchema, SierraContractClassSchema, - SyncStatusSchema, CasmClassSchema, + SyncStatusSchema, ) from starknet_py.net.schemas.rpc.event import EventsChunkSchema from starknet_py.net.schemas.rpc.general import EstimatedFeeSchema From d2a26913fb9acc49f9a3ebe6e6fa1419838b681f Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 29 Oct 2024 18:45:47 +0100 Subject: [PATCH 04/18] Add schemas for deprecated, core and Starknet hints --- starknet_py/net/schemas/rpc/contract.py | 711 +++++++++++++++++++++++- 1 file changed, 705 insertions(+), 6 deletions(-) diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index 6d60ae1ef..96b4a9c4b 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -1,6 +1,7 @@ import json +from enum import Enum -from marshmallow import EXCLUDE, ValidationError, fields, post_load +from marshmallow import EXCLUDE, ValidationError, fields, post_load, validate from starknet_py.abi.v0.schemas import ContractAbiEntrySchema from starknet_py.net.client_models import ( @@ -150,7 +151,7 @@ def make_dataclass(self, data, **kwargs) -> DeprecatedCompiledContract: class CasmClassEntryPointSchema(Schema): selector = Felt(data_key="selector", required=True) - offset = fields.Integer(data_key="offset", required=True) + offset = NumberAsHex(data_key="offset", required=True) builtins = fields.List(fields.String(), data_key="builtins") @post_load @@ -180,14 +181,712 @@ def make_dataclass(self, data, **kwargs) -> CasmClassEntryPointsByType: return CasmClassEntryPointsByType(**data) +class CellRefSchema(Schema): + register = fields.String( + data_key="register", validate=validate.OneOf(["AP", "FP"]), required=True + ) + offset = fields.Integer(data_key="offset", required=True) + + +class AssertCurrentAccessIndicesIsEmpty(Enum): + ASSERT_CURRENT_ACCESS_INDICES_IS_EMPTY = "AssertCurrentAccessIndicesIsEmpty" + + +class AssertAllKeysUsed(Enum): + ASSERT_ALL_KEYS_USED = "AssertAllKeysUsed" + + +class AssertLeAssertThirdArcExcluded(Enum): + ASSERT_LE_ASSERT_THIRD_ARC_EXCLUDED = "AssertLeAssertThirdArcExcluded" + + +class AssertAllAccessesUsedInnerSchema(Schema): + n_used_accesses = fields.Nested(CellRefSchema(), required=True) + + +class AssertAllAccessesUsedSchema(Schema): + assert_all_accesses_used = fields.Nested( + AssertAllAccessesUsedInnerSchema(), + data_key="AssertAllAccessesUsed", + required=True, + ) + + +class DerefSchema(Schema): + deref = fields.Nested(CellRefSchema(), data_key="Deref", required=True) + + +class DoubleDerefItemField(fields.Field): + def _deserialize(self, value, attr, data, **kwargs): + if isinstance(value, dict): + return CellRefSchema().load(value) + elif isinstance(value, int): + return value + else: + raise ValidationError( + "Invalid value: must be a CellRef object or an integer" + ) + + def _serialize(self, value, attr, obj, **kwargs): + if isinstance(value, dict): + return CellRefSchema().dump(value) + elif isinstance(value, int): + return value + raise ValidationError("Invalid value type during serialization") + + +class DoubleDerefSchema(Schema): + double_deref = fields.List( + DoubleDerefItemField(), + data_key="DoubleDeref", + required=True, + validate=validate.Length(2), + ) + + +class ImmediateSchema(Schema): + immediate = NumberAsHex(data_key="Immediate", required=True) + + +class BinOpBField(fields.Field): + def _deserialize(self, value, attr, data, **kwargs): + try: + return DerefSchema().load(value) + except ValidationError as _e: + pass + try: + return ImmediateSchema().load(value) + except ValidationError as _e: + pass + + raise ValidationError( + f"Invalid value provided for 'b': {value}. Must be a Deref object or an Immediate object." + ) + + +class BinOpInnerSchema(Schema): + op = fields.String( + data_key="op", required=True, validate=validate.OneOf(["Add", "Mul"]) + ) + a = fields.Nested(CellRefSchema(), data_key="a", required=True) + b = BinOpBField(data_key="b", required=True) + + +class BinOpSchema(Schema): + bin_op = fields.Nested(BinOpInnerSchema(), data_key="BinOp", required=True) + + +class ResOperandField(fields.Field): + def _deserialize(self, value, attr, data, **kwargs): + if isinstance(value, dict): + if DerefSchema.deref.data_key in value: + return DerefSchema().load(value) + elif DoubleDerefSchema.double_deref.data_key in value: + return DoubleDerefSchema().load(value) + elif ImmediateSchema.immediate.data_key in value: + return ImmediateSchema().load(value) + elif BinOpSchema.bin_op.data_key in value: + return BinOpSchema().load(value) + + raise ValidationError(f"Invalid value provided for ResOperand: {value}.") + + +class AssertLtAssertValidInputInnerSchema(Schema): + a = ResOperandField(data_key="a", required=True) + b = ResOperandField(data_key="b", required=True) + + +class AssertLtAssertValidInputSchema(Schema): + assert_lt_assert_valid_input = fields.Nested( + AssertLtAssertValidInputInnerSchema(), + data_key="AssertLtAssertValidInput", + required=True, + ) + + +class Felt252DictReadInnerSchema(Schema): + dict_ptr = ResOperandField(data_key="dict_ptr", required=True) + key = ResOperandField(data_key="key", required=True) + value_dst = fields.Nested(CellRefSchema(), data_key="value_dst", required=True) + + +class Felt252DictReadSchema(Schema): + felt252_dict_read = fields.Nested( + Felt252DictReadInnerSchema(), data_key="Felt252DictRead", required=True + ) + + +class Felt252DictWriteInnerSchema(Schema): + dict_ptr = ResOperandField(data_key="dict_ptr", required=True) + key = ResOperandField(data_key="key", required=True) + value = ResOperandField(data_key="value", required=True) + + +class Felt252DictWriteSchema(Schema): + felt252_dict_write = fields.Nested( + Felt252DictWriteInnerSchema(), data_key="Felt252DictWrite", required=True + ) + + +class AllocSegmentInnerSchema(Schema): + dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + + +class AllocSegmentSchema(Schema): + alloc_segment = fields.Nested( + AllocSegmentInnerSchema(), data_key="AllocSegment", required=True + ) + + +class TestLessThanInnerSchema(Schema): + lhs = ResOperandField(data_key="lhs", required=True) + rhs = ResOperandField(data_key="rhs", required=True) + dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + + +class TestLessThanSchema(Schema): + test_less_than = fields.Nested( + TestLessThanInnerSchema(), data_key="TestLessThan", required=True + ) + + +class TestLessThanOrEqualInnerSchema(TestLessThanInnerSchema): + pass + + +class TestLessThanOrEqualSchema(Schema): + test_less_than_or_equal = fields.Nested( + TestLessThanOrEqualInnerSchema(), data_key="TestLessThanOrEqual", required=True + ) + + +class TestLessThenOrEqualAddressInnerSchema(TestLessThanSchema): + pass + + +class TestLessThenOrEqualAddressSchema(Schema): + test_less_than_or_equal_address = fields.Nested( + TestLessThenOrEqualAddressInnerSchema(), + data_key="TestLessThenOrEqualAddress", + required=True, + ) + + +class WideMul128InnerSchema(Schema): + lhs = ResOperandField(data_key="lhs", required=True) + rhs = ResOperandField(data_key="rhs", required=True) + high = fields.Nested(CellRefSchema(), data_key="high", required=True) + low = fields.Nested(CellRefSchema(), data_key="low", required=True) + + +class WideMul128Schema(Schema): + wide_mul128 = fields.Nested( + WideMul128InnerSchema(), data_key="WideMul128", required=True + ) + + +class DivModInnerSchema(Schema): + lhs = ResOperandField(data_key="lhs", required=True) + rhs = ResOperandField(data_key="rhs", required=True) + quotient = fields.Nested(CellRefSchema(), data_key="quotient", required=True) + remainder = fields.Nested(CellRefSchema(), data_key="remainder", required=True) + + +class DivModSchema(Schema): + div_mod = fields.Nested(DivModInnerSchema(), data_key="DivMod", required=True) + + +class Uint256DivModInnerSchema(Schema): + dividend_0 = ResOperandField(data_key="dividend0", required=True) + dividend_1 = ResOperandField(data_key="dividend1", required=True) + divisor_0 = ResOperandField(data_key="divisor0", required=True) + divisor_1 = ResOperandField(data_key="divisor1", required=True) + quotient_0 = fields.Nested(CellRefSchema(), data_key="quotient0", required=True) + quotient_1 = fields.Nested(CellRefSchema(), data_key="quotient1", required=True) + remainder_0 = fields.Nested(CellRefSchema(), data_key="remainder0", required=True) + remainder_1 = fields.Nested(CellRefSchema(), data_key="remainder1", required=True) + + +class Uint256DivModSchema(Schema): + uint256_div_mod = fields.Nested( + Uint256DivModInnerSchema(), data_key="Uint256DivMod", required=True + ) + + +class Uint512DivModByUint256InnerSchema(Schema): + dividend_0 = ResOperandField(data_key="dividend0", required=True) + dividend_1 = ResOperandField(data_key="dividend1", required=True) + dividend_2 = ResOperandField(data_key="dividend2", required=True) + dividend_3 = ResOperandField(data_key="dividend3", required=True) + divisor_0 = ResOperandField(data_key="divisor0", required=True) + divisor_1 = ResOperandField(data_key="divisor1", required=True) + quotient_0 = fields.Nested(CellRefSchema(), data_key="quotient0", required=True) + quotient_1 = fields.Nested(CellRefSchema(), data_key="quotient1", required=True) + quotient_2 = fields.Nested(CellRefSchema(), data_key="quotient2", required=True) + quotient_3 = fields.Nested(CellRefSchema(), data_key="quotient3", required=True) + remainder_0 = fields.Nested(CellRefSchema(), data_key="remainder0", required=True) + remainder_1 = fields.Nested(CellRefSchema(), data_key="remainder1", required=True) + + +class Uint512DivModByUint256Schema(Schema): + uint512_div_mod_by_uint256 = fields.Nested( + Uint512DivModByUint256InnerSchema(), + data_key="Uint512DivModByUint256", + required=True, + ) + + +class SquareRootInnerSchema(Schema): + value = ResOperandField(data_key="value", required=True) + dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + + +class SquareRootSchema(Schema): + square_root = fields.Nested( + SquareRootInnerSchema(), data_key="SquareRoot", required=True + ) + + +class Uint256SquareRootInnerSchema(Schema): + value_low = ResOperandField(data_key="value_low", required=True) + value_high = ResOperandField(data_key="value_high", required=True) + sqrt_0 = fields.Nested(CellRefSchema(), data_key="sqrt0", required=True) + sqrt_1 = fields.Nested(CellRefSchema(), data_key="sqrt1", required=True) + remainder_low = fields.Nested( + CellRefSchema(), data_key="remainder_low", required=True + ) + remainder_high = fields.Nested( + CellRefSchema(), data_key="remainder_high", required=True + ) + sqrt_mul_2_minus_remainder_ge_u128 = fields.Nested( + CellRefSchema(), data_key="sqrt_mul_2_minus_remainder_ge_u128", required=True + ) + + +class Uint256SquareRootSchema(Schema): + uint256_square_root = fields.Nested( + Uint256SquareRootInnerSchema(), data_key="Uint256SquareRoot", required=True + ) + + +class LinearSplitInnerSchema(Schema): + value = ResOperandField(data_key="value", required=True) + scalar = ResOperandField(data_key="scalar", required=True) + max_x = ResOperandField(data_key="max_x", required=True) + x = fields.Nested(CellRefSchema(), data_key="x", required=True) + y = fields.Nested(CellRefSchema(), data_key="y", required=True) + + +class LinearSplitSchema(Schema): + linear_split = fields.Nested( + LinearSplitInnerSchema(), data_key="LinearSplit", required=True + ) + + +class AllocFelt252DictInnerSchema(Schema): + segment_arena_ptr = ResOperandField(data_key="segment_arena_ptr", required=True) + + +class AllocFelt252DictSchema(Schema): + alloc_felt252_dict = fields.Nested( + AllocFelt252DictInnerSchema(), data_key="AllocFelt252Dict", required=True + ) + + +class Felt252DictEntryInitInnerSchema(Schema): + dict_ptr = ResOperandField(data_key="dict_ptr", required=True) + key = ResOperandField(data_key="key", required=True) + + +class Felt252DictEntryInitSchema(Schema): + felt252_dict_entry_init = fields.Nested( + Felt252DictEntryInitInnerSchema(), + data_key="Felt252DictEntryInit", + required=True, + ) + + +class Felt252DictEntryUpdateInnerSchema(Schema): + dict_ptr = ResOperandField(data_key="dict_ptr", required=True) + value = ResOperandField(data_key="value", required=True) + + +class Felt252DictEntryUpdateSchema(Schema): + felt252_dict_entry_update = fields.Nested( + Felt252DictEntryUpdateInnerSchema(), + data_key="Felt252DictEntryUpdate", + required=True, + ) + + +class GetSegmentArenaIndexInnerSchema(Schema): + dict_end_ptr = ResOperandField(data_key="dict_end_ptr", required=True) + dict_index = ResOperandField(data_key="dict_index", required=True) + + +class GetSegmentArenaIndexSchema(Schema): + get_segment_arena_index = fields.Nested( + GetSegmentArenaIndexInnerSchema(), + data_key="GetSegmentArenaIndex", + required=True, + ) + + +class InitSquashDataInnerSchema(Schema): + dict_access = ResOperandField(data_key="dict_access", required=True) + ptr_diff = ResOperandField(data_key="ptr_diff", required=True) + n_accesses = ResOperandField(data_key="n_accesses", required=True) + big_keys = fields.Nested(CellRefSchema(), data_key="big_keys", required=True) + first_key = fields.Nested(CellRefSchema(), data_key="first_key", required=True) + + +class InitSquashDataSchema(Schema): + init_squash_data = fields.Nested( + InitSquashDataInnerSchema(), data_key="InitSquashData", required=True + ) + + +class GetCurrentAccessIndexInnerSchema(Schema): + range_check_ptr = ResOperandField(data_key="range_check_ptr", required=True) + + +class GetCurrentAccessIndexSchema(Schema): + get_current_access_index = fields.Nested( + GetCurrentAccessIndexInnerSchema(), + data_key="GetCurrentAccessIndex", + required=True, + ) + + +class ShouldSkipSquashLoopInnerSchema(Schema): + should_skip_loop = fields.Nested( + CellRefSchema(), data_key="should_skip_loop", required=True + ) + + +class ShouldSkipSquashLoopSchema(Schema): + should_skip_squash_loop = fields.Nested( + ShouldSkipSquashLoopInnerSchema(), + data_key="ShouldSkipSquashLoop", + required=True, + ) + + +class GetCurrentAccessDeltaInnerSchema(Schema): + index_delta_minus_1 = fields.Nested( + CellRefSchema(), data_key="index_delta_minus1", required=True + ) + + +class GetCurrentAccessDeltaSchema(Schema): + get_current_access_delta = fields.Nested( + GetCurrentAccessDeltaInnerSchema(), + data_key="GetCurrentAccessDelta", + required=True, + ) + + +class ShouldContinueSquashLoopInnerSchema(Schema): + should_continue = fields.Nested( + CellRefSchema(), data_key="should_continue", required=True + ) + + +class ShouldContinueSquashLoopSchema(Schema): + should_continue_squash_loop = fields.Nested( + ShouldContinueSquashLoopInnerSchema(), + data_key="ShouldContinueSquashLoop", + required=True, + ) + + +class GetNextDictKeyInnerSchema(Schema): + next_key = fields.Nested(CellRefSchema(), data_key="next_key", required=True) + + +class GetNextDictKeySchema(Schema): + get_next_dict_key = fields.Nested( + GetNextDictKeyInnerSchema(), data_key="GetNextDictKey", required=True + ) + + +class AssertLeFindSmallArcsInnerSchema(Schema): + range_check_ptr = ResOperandField(data_key="range_check_ptr", required=True) + a = ResOperandField(data_key="a", required=True) + b = ResOperandField(data_key="b", required=True) + + +class AssertLeFindSmallArcsSchema(Schema): + assert_le_find_small_arcs = fields.Nested( + AssertLeFindSmallArcsInnerSchema(), + data_key="AssertLeFindSmallArcs", + required=True, + ) + + +class AssertLeIsFirstArcExcludedInnerSchema(Schema): + skip_exclude_a_flag = fields.Nested( + CellRefSchema(), data_key="skip_exclude_a_flag", required=True + ) + + +class AssertLeIsFirstArcExcludedSchema(Schema): + assert_le_is_first_arc_excluded = fields.Nested( + AssertLeIsFirstArcExcludedInnerSchema(), + data_key="AssertLeIsFirstArcExcluded", + required=True, + ) + + +class AssertLeIsSecondArcExcludedInnerSchema(Schema): + skip_exclude_b_minus_a = fields.Nested( + CellRefSchema(), data_key="skip_exclude_b_minus_a", required=True + ) + + +class AssertLeIsSecondArcExcludedSchema(Schema): + assert_le_is_second_arc_excluded = fields.Nested( + AssertLeIsSecondArcExcludedInnerSchema(), + data_key="AssertLeIsSecondArcExcluded", + required=True, + ) + + +class RandomEcPointInnerSchema(Schema): + x = fields.Nested(CellRefSchema(), data_key="x", required=True) + y = fields.Nested(CellRefSchema(), data_key="y", required=True) + + +class RandomEcPointSchema(Schema): + random_ec_point = fields.Nested( + RandomEcPointInnerSchema(), data_key="RandomEcPoint", required=True + ) + + +class FieldSqrtInnerSchema(Schema): + val = ResOperandField(data_key="val", required=True) + sqrt = fields.Nested(CellRefSchema(), data_key="sqrt", required=True) + + +class FieldSqrtSchema(Schema): + field_sqrt = fields.Nested( + FieldSqrtInnerSchema(), data_key="FieldSqrt", required=True + ) + + +class DebugPrintInnerSchema(Schema): + start = ResOperandField(data_key="start", required=True) + end = ResOperandField(data_key="end", required=True) + + +class DebugPrintSchema(Schema): + debug_print = fields.Nested( + DebugPrintInnerSchema(), data_key="DebugPrint", required=True + ) + + +class AllocConstantSizeInnerSchema(Schema): + size = ResOperandField(data_key="size", required=True) + dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + + +class AllocConstantSizeSchema(Schema): + alloc_constant_size = fields.Nested( + AllocConstantSizeInnerSchema(), data_key="AllocConstantSize", required=True + ) + + +class U256InvModNInnerSchema(Schema): + b_0 = ResOperandField(data_key="b0", required=True) + b_1 = ResOperandField(data_key="b1", required=True) + n_0 = ResOperandField(data_key="n0", required=True) + n_1 = ResOperandField(data_key="n1", required=True) + g_0_or_no_inv = fields.Nested( + CellRefSchema(), data_key="g0_or_no_inv", required=True + ) + g_1_option = fields.Nested(CellRefSchema(), data_key="g1_option", required=True) + s_or_r_0 = fields.Nested(CellRefSchema(), data_key="s_or_r0", required=True) + s_or_r_1 = fields.Nested(CellRefSchema(), data_key="s_or_r1", required=True) + t_or_k_0 = fields.Nested(CellRefSchema(), data_key="t_or_k0", required=True) + t_or_k_1 = fields.Nested(CellRefSchema(), data_key="t_or_k1", required=True) + + +class U256InvModNSchema(Schema): + u256_inv_mod_n = fields.Nested( + U256InvModNInnerSchema(), data_key="U256InvModN", required=True + ) + + +class EvalCircuitInnerSchema(Schema): + n_add_mods = ResOperandField(data_key="n_add_mods", required=True) + add_mod_builtin = ResOperandField(data_key="add_mod_builtin", required=True) + n_mul_mods = ResOperandField(data_key="n_mul_mods", required=True) + mul_mod_builtin = ResOperandField(data_key="mul_mod_builtin", required=True) + + +class EvalCircuitSchema(Schema): + eval_circuit = fields.Nested( + EvalCircuitInnerSchema(), data_key="EvalCircuit", required=True + ) + + +class SystemCallInnerSchema(Schema): + system = ResOperandField(data_key="system", required=True) + + +class SystemCallSchema(Schema): + system_call = fields.Nested( + SystemCallInnerSchema(), data_key="SystemCall", required=True + ) + + +class CheatcodeInnerSchema(Schema): + selector = NumberAsHex( + data_key="selector", required=True + ) # Assuming NUM_AS_HEX is represented as a string + input_start = ResOperandField(data_key="input_start", required=True) + input_end = ResOperandField(data_key="input_end", required=True) + output_start = fields.Nested( + CellRefSchema(), data_key="output_start", required=True + ) + output_end = fields.Nested(CellRefSchema(), data_key="output_end", required=True) + + +class CheatcodeSchema(Schema): + cheatcode = fields.Nested( + CheatcodeInnerSchema(), data_key="Cheatcode", required=True + ) + + +class HintField(fields.Field): + def _deserialize(self, value, attr, data, **kwargs): + if isinstance(value, str): + # Deprecated hint checks + if value in AssertCurrentAccessIndicesIsEmpty: + return value + elif value in AssertAllKeysUsed: + return value + elif value in AssertLeAssertThirdArcExcluded: + return value + + elif isinstance(value, dict): + # Deprecated hint + if AssertAllAccessesUsedSchema.assert_all_accesses_used.data_key in value: + return AssertAllAccessesUsedSchema().load(value) + elif ( + AssertLtAssertValidInputSchema.assert_lt_assert_valid_input.data_key + in value + ): + return AssertLtAssertValidInputSchema().load(value) + elif Felt252DictReadSchema.felt252_dict_read.data_key in value: + return Felt252DictReadSchema().load(value) + elif Felt252DictWriteSchema.felt252_dict_write.data_key in value: + return Felt252DictWriteSchema().load(value) + + # Core hint + elif AllocSegmentSchema.alloc_segment.data_key in value: + return AllocSegmentSchema().load(value) + elif TestLessThanSchema.test_less_than.data_key in value: + return TestLessThanSchema().load(value) + elif TestLessThanOrEqualSchema.test_less_than_or_equal.data_key in value: + return TestLessThanOrEqualSchema().load(value) + elif ( + TestLessThenOrEqualAddressSchema.test_less_than_or_equal_address.data_key + in value + ): + return TestLessThenOrEqualAddressSchema().load(value) + elif WideMul128Schema.wide_mul128.data_key in value: + return WideMul128Schema().load(value) + elif DivModSchema.div_mod.data_key in value: + return DivModSchema().load(value) + elif Uint256DivModSchema.uint256_div_mod.data_key in value: + return Uint256DivModSchema().load(value) + elif ( + Uint512DivModByUint256Schema.uint512_div_mod_by_uint256.data_key + in value + ): + return Uint512DivModByUint256Schema().load(value) + elif SquareRootSchema.square_root.data_key in value: + return SquareRootSchema().load(value) + elif Uint256SquareRootSchema.uint256_square_root.data_key in value: + return Uint256SquareRootSchema().load(value) + elif LinearSplitSchema.linear_split.data_key in value: + return LinearSplitSchema().load(value) + elif AllocFelt252DictSchema.alloc_felt252_dict.data_key in value: + return AllocFelt252DictSchema().load(value) + elif Felt252DictEntryInitSchema.felt252_dict_entry_init.data_key in value: + return Felt252DictEntryInitSchema().load(value) + elif ( + Felt252DictEntryUpdateSchema.felt252_dict_entry_update.data_key in value + ): + return Felt252DictEntryUpdateSchema().load(value) + elif GetSegmentArenaIndexSchema.get_segment_arena_index.data_key in value: + return GetSegmentArenaIndexSchema().load(value) + elif InitSquashDataSchema.init_squash_data.data_key in value: + return InitSquashDataSchema().load(value) + elif GetCurrentAccessIndexSchema.get_current_access_index.data_key in value: + return GetCurrentAccessIndexSchema().load(value) + elif ShouldSkipSquashLoopSchema.should_skip_squash_loop.data_key in value: + return ShouldSkipSquashLoopSchema().load(value) + elif GetCurrentAccessDeltaSchema.get_current_access_delta.data_key in value: + return GetCurrentAccessDeltaSchema().load(value) + elif ( + ShouldContinueSquashLoopSchema.should_continue_squash_loop.data_key + in value + ): + return ShouldContinueSquashLoopSchema().load(value) + elif GetNextDictKeySchema.get_next_dict_key.data_key in value: + return GetNextDictKeySchema().load(value) + elif ( + AssertLeFindSmallArcsSchema.assert_le_find_small_arcs.data_key in value + ): + return AssertLeFindSmallArcsSchema().load(value) + elif ( + AssertLeIsFirstArcExcludedSchema.assert_le_is_first_arc_excluded.data_key + in value + ): + return AssertLeIsFirstArcExcludedSchema().load(value) + elif ( + AssertLeIsSecondArcExcludedSchema.assert_le_is_second_arc_excluded.data_key + in value + ): + return AssertLeIsSecondArcExcludedSchema().load(value) + elif RandomEcPointSchema.random_ec_point.data_key in value: + return RandomEcPointSchema().load(value) + elif FieldSqrtSchema.field_sqrt.data_key in value: + return FieldSqrtSchema().load(value) + elif DebugPrintSchema.debug_print.data_key in value: + return DebugPrintSchema().load(value) + elif AllocConstantSizeSchema.alloc_constant_size.data_key in value: + return AllocConstantSizeSchema().load(value) + elif U256InvModNSchema.u256_inv_mod_n.data_key in value: + return U256InvModNSchema().load(value) + elif EvalCircuitSchema.eval_circuit.data_key in value: + return EvalCircuitSchema().load(value) + + # Starknet hint + elif SystemCallSchema.system_call.data_key in value: + return SystemCallSchema().load(value) + elif CheatcodeSchema.cheatcode.data_key in value: + return CheatcodeSchema().load(value) + + class CasmClassSchema(Schema): - prime = Felt(data_key="prime", required=True) + prime = NumberAsHex(data_key="prime", required=True) bytecode = fields.List(Felt(), data_key="bytecode", required=True) bytecode_segment_lengths = fields.List( - Felt(), data_key="bytecode_segment_lengths", load_default=None + fields.Integer(), data_key="bytecode_segment_lengths", load_default=None + ) + # TODO (#1498): Add more detailed `hints` type + hints = fields.List( + fields.List( + HintField(), + validate=validate.Length(equal=2), + ), + data_key="hints", + required=True, ) - hints = fields.List(fields.Raw(), data_key="hints", required=True) - pythonic_hints = fields.List(fields.Raw(), data_key="pythonic_hints", required=True) + # TODO (#1498): Ensure `pythonic_hints` are not needed anymore compiler_version = fields.String(data_key="compiler_version", required=True) entry_points_by_type = fields.Nested( CasmClassEntryPointsByTypeSchema(), From d0e20b766e9277161c08f99f4080830cbaa3cd63 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Tue, 29 Oct 2024 18:54:45 +0100 Subject: [PATCH 05/18] Remove todos; Add validation error --- starknet_py/net/schemas/rpc/contract.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index 96b4a9c4b..f2f117e55 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -870,6 +870,8 @@ def _deserialize(self, value, attr, data, **kwargs): elif CheatcodeSchema.cheatcode.data_key in value: return CheatcodeSchema().load(value) + raise ValidationError(f"Invalid value provided for Hint: {value}.") + class CasmClassSchema(Schema): prime = NumberAsHex(data_key="prime", required=True) @@ -877,7 +879,6 @@ class CasmClassSchema(Schema): bytecode_segment_lengths = fields.List( fields.Integer(), data_key="bytecode_segment_lengths", load_default=None ) - # TODO (#1498): Add more detailed `hints` type hints = fields.List( fields.List( HintField(), @@ -886,7 +887,6 @@ class CasmClassSchema(Schema): data_key="hints", required=True, ) - # TODO (#1498): Ensure `pythonic_hints` are not needed anymore compiler_version = fields.String(data_key="compiler_version", required=True) entry_points_by_type = fields.Nested( CasmClassEntryPointsByTypeSchema(), From 28229b78c4be1567a67601184c4c978a77f08e86 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 00:51:00 +0100 Subject: [PATCH 06/18] Add dataclasses --- .DS_Store | Bin 0 -> 6148 bytes starknet_py/net/client_models.py | 551 +++++++++++++++++++++++- starknet_py/net/schemas/rpc/contract.py | 6 +- starknet_py/tests/e2e/.DS_Store | Bin 0 -> 6148 bytes 4 files changed, 536 insertions(+), 21 deletions(-) create mode 100644 .DS_Store create mode 100644 starknet_py/tests/e2e/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0Xawc&+i894{ zEh4(SY!@Ok5t+aZbu#_#u{@0mP=P;Cz`hR!Zden$K>u`L@D>0#Lf8#+?GNs z1tJ2|paO%c*;j#RxYL3B88BUFRN&VNJODzB6{Y|H literal 0 HcmV?d00001 From f1e68ee8852df0eeda54a9aa3d2e988364ea671b Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 00:52:42 +0100 Subject: [PATCH 07/18] Remove unnecessary file --- starknet_py/tests/e2e/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 starknet_py/tests/e2e/.DS_Store diff --git a/starknet_py/tests/e2e/.DS_Store b/starknet_py/tests/e2e/.DS_Store deleted file mode 100644 index 0bd4f384102fbd9af534feff57f69a7f3b38211a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKISv9b4733uBpOP}e1RWC2wt!spa9XJMM6Nm74PC{jE@EuI%v>Xawc&+i894{ zEh4(SY!@Ok5t+aZbu#_#u{@0mP=P;Cz`hR!Zden$K>u`L@D>0#Lf8#+?GNs z1tJ2|paO%c*;j#RxYL3B88BUFRN&VNJODzB6{Y|H From 31c25530b8e1f005c109e5751a19703bb62cac67 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 00:54:32 +0100 Subject: [PATCH 08/18] Remove unnecessary file --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 4 Nov 2024 10:16:22 +0100 Subject: [PATCH 09/18] Move enums to `client_models.py` --- starknet_py/net/client_models.py | 17 +++++++++---- starknet_py/net/schemas/rpc/contract.py | 34 ++++++++----------------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index 7b6a9d427..792cf084e 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -26,11 +26,6 @@ ) from starknet_py.abi.v2.shape import AbiDictEntry as AbiDictEntryV2 from starknet_py.abi.v2.shape import AbiDictList as AbiDictListV2 -from starknet_py.net.schemas.rpc.contract import ( - AssertAllKeysUsed, - AssertCurrentAccessIndicesIsEmpty, - AssertLeAssertThirdArcExcluded, -) from starknet_py.utils.constructor_args_translator import _is_abi_v2 # pylint: disable=too-many-lines @@ -1176,6 +1171,18 @@ class MessageStatus: failure_reason: Optional[str] = None +class AssertCurrentAccessIndicesIsEmpty(Enum): + ASSERT_CURRENT_ACCESS_INDICES_IS_EMPTY = "AssertCurrentAccessIndicesIsEmpty" + + +class AssertAllKeysUsed(Enum): + ASSERT_ALL_KEYS_USED = "AssertAllKeysUsed" + + +class AssertLeAssertThirdArcExcluded(Enum): + ASSERT_LE_ASSERT_THIRD_ARC_EXCLUDED = "AssertLeAssertThirdArcExcluded" + + @dataclass class CellRef: register: Literal["AP", "FP"] diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index 1e6d63e47..99366e121 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -1,10 +1,12 @@ import json -from enum import Enum from marshmallow import EXCLUDE, ValidationError, fields, post_load, validate from starknet_py.abi.v0.schemas import ContractAbiEntrySchema from starknet_py.net.client_models import ( + AssertAllKeysUsed, + AssertCurrentAccessIndicesIsEmpty, + AssertLeAssertThirdArcExcluded, CasmClass, CasmClassEntryPoint, CasmClassEntryPointsByType, @@ -188,18 +190,6 @@ class CellRefSchema(Schema): offset = fields.Integer(data_key="offset", required=True) -class AssertCurrentAccessIndicesIsEmpty(Enum): - ASSERT_CURRENT_ACCESS_INDICES_IS_EMPTY = "AssertCurrentAccessIndicesIsEmpty" - - -class AssertAllKeysUsed(Enum): - ASSERT_ALL_KEYS_USED = "AssertAllKeysUsed" - - -class AssertLeAssertThirdArcExcluded(Enum): - ASSERT_LE_ASSERT_THIRD_ARC_EXCLUDED = "AssertLeAssertThirdArcExcluded" - - class AssertAllAccessesUsedInnerSchema(Schema): n_used_accesses = fields.Nested(CellRefSchema(), required=True) @@ -250,14 +240,11 @@ class ImmediateSchema(Schema): class BinOpBField(fields.Field): def _deserialize(self, value, attr, data, **kwargs): - try: - return DerefSchema().load(value) - except ValidationError as _e: - pass - try: - return ImmediateSchema().load(value) - except ValidationError as _e: - pass + if isinstance(value, dict): + if DerefSchema.deref.data_key in value: + return DerefSchema().load(value) + elif ImmediateSchema.immediate.data_key in value: + return ImmediateSchema().load(value) raise ValidationError( f"Invalid value provided for 'b': {value}. Must be a Deref object or an Immediate object." @@ -878,9 +865,8 @@ class CasmClassSchema(Schema): fields.Integer(), data_key="bytecode_segment_lengths", load_default=None ) hints = fields.List( - fields.List( - HintField(), - validate=validate.Length(equal=2), + fields.Tuple( + (fields.Integer(), HintField()), ), data_key="hints", required=True, From 0cdcb8911726b61f1735a8d72013986b811fcbbd Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 12:14:07 +0100 Subject: [PATCH 10/18] Refactor serialization and deserialization in schemas --- starknet_py/net/client_models.py | 526 +---------------------- starknet_py/net/models/compiled_casm.py | 528 ++++++++++++++++++++++++ starknet_py/net/schemas/rpc/contract.py | 299 ++++++++------ 3 files changed, 699 insertions(+), 654 deletions(-) create mode 100644 starknet_py/net/models/compiled_casm.py diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index 792cf084e..e06a671be 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -26,6 +26,7 @@ ) from starknet_py.abi.v2.shape import AbiDictEntry as AbiDictEntryV2 from starknet_py.abi.v2.shape import AbiDictList as AbiDictListV2 +from starknet_py.net.models.compiled_casm import Hint from starknet_py.utils.constructor_args_translator import _is_abi_v2 # pylint: disable=too-many-lines @@ -1171,531 +1172,6 @@ class MessageStatus: failure_reason: Optional[str] = None -class AssertCurrentAccessIndicesIsEmpty(Enum): - ASSERT_CURRENT_ACCESS_INDICES_IS_EMPTY = "AssertCurrentAccessIndicesIsEmpty" - - -class AssertAllKeysUsed(Enum): - ASSERT_ALL_KEYS_USED = "AssertAllKeysUsed" - - -class AssertLeAssertThirdArcExcluded(Enum): - ASSERT_LE_ASSERT_THIRD_ARC_EXCLUDED = "AssertLeAssertThirdArcExcluded" - - -@dataclass -class CellRef: - register: Literal["AP", "FP"] - offset: int - - -@dataclass -class AssertAllAccessesUsedInner: - n_used_accesses: CellRef - - -@dataclass -class AssertAllAccessesUsed: - assert_all_accesses_used: AssertAllAccessesUsedInner - - -@dataclass -class Deref: - deref: CellRef - - -@dataclass -class DoubleDeref: - double_deref: Tuple[CellRef, int] - - -@dataclass -class Immediate: - immediate: int - - -@dataclass -class BinOpInner: - op: Literal["Add", "Mul"] - a: CellRef - b: Union[Deref, Immediate] - - -@dataclass -class BinOp: - bin_op: BinOpInner - - -ResOperand = Union[Deref, DoubleDeref, Immediate, BinOp] - - -@dataclass -class AssertLtAssertValidInputInner: - a: ResOperand - b: ResOperand - - -@dataclass -class AssertLtAssertValidInput: - assert_lt_assert_valid_input: AssertLtAssertValidInputInner - - -@dataclass -class Felt252DictReadInner: - dict_ptr: ResOperand - key: ResOperand - value_dst: CellRef - - -@dataclass -class Felt252DictRead: - felt252_dict_read: Felt252DictReadInner - - -@dataclass -class Felt252DictWriteInner: - dict_ptr: ResOperand - key: ResOperand - value: ResOperand - - -@dataclass -class Felt252DictWrite: - felt252_dict_write: Felt252DictWriteInner - - -@dataclass -class AllocSegmentInner: - dst: CellRef - - -@dataclass -class AllocSegment: - alloc_segment: AllocSegmentInner - - -@dataclass -class TestLessThanInner: - lhs: ResOperand - rhs: ResOperand - dst: CellRef - - -@dataclass -class TestLessThan: - test_less_than: TestLessThanInner - - -@dataclass -class TestLessThanOrEqualInner(TestLessThanInner): - pass - - -@dataclass -class TestLessThanOrEqual: - test_less_than_or_equal: TestLessThanOrEqualInner - - -@dataclass -class TestLessThenOrEqualAddressInner(TestLessThanInner): - pass - - -@dataclass -class TestLessThenOrEqualAddress: - test_less_than_or_equal_address: TestLessThenOrEqualAddressInner - - -@dataclass -class WideMul128Inner: - lhs: ResOperand - rhs: ResOperand - high: CellRef - low: CellRef - - -@dataclass -class WideMul128: - wide_mul128: WideMul128Inner - - -@dataclass -class DivModInner: - lhs: ResOperand - rhs: ResOperand - quotient: CellRef - remainder: CellRef - - -@dataclass -class DivMod: - div_mod: DivModInner - - -@dataclass -class Uint256DivModInner: - # pylint: disable=too-many-instance-attributes - dividend_0: ResOperand - dividend_1: ResOperand - divisor_0: ResOperand - divisor_1: ResOperand - quotient_0: CellRef - quotient_1: CellRef - remainder_0: CellRef - remainder_1: CellRef - - -@dataclass -class Uint256DivMod: - uint256_div_mod: Uint256DivModInner - - -@dataclass -class Uint512DivModByUint256Inner: - # pylint: disable=too-many-instance-attributes - dividend_0: ResOperand - dividend_1: ResOperand - dividend_2: ResOperand - dividend_3: ResOperand - divisor_0: ResOperand - divisor_1: ResOperand - quotient_0: CellRef - quotient_1: CellRef - quotient_2: CellRef - quotient_3: CellRef - remainder_0: CellRef - remainder_1: CellRef - - -@dataclass -class Uint512DivModByUint256: - uint512_div_mod_by_uint256: Uint512DivModByUint256Inner - - -@dataclass -class SquareRootInner: - value: ResOperand - dst: CellRef - - -@dataclass -class SquareRoot: - square_root: SquareRootInner - - -@dataclass -class Uint256SquareRootInner: - value_low: ResOperand - value_high: ResOperand - sqrt_0: CellRef - sqrt_1: CellRef - remainder_low: CellRef - remainder_high: CellRef - sqrt_mul_2_minus_remainder_ge_u128: CellRef - - -@dataclass -class Uint256SquareRoot: - uint256_square_root: Uint256SquareRootInner - - -@dataclass -class LinearSplitInner: - value: ResOperand - scalar: ResOperand - max_x: ResOperand - x: CellRef - y: CellRef - - -@dataclass -class LinearSplit: - linear_split: LinearSplitInner - - -@dataclass -class AllocFelt252DictInner: - segment_arena_ptr: ResOperand - - -@dataclass -class AllocFelt252Dict: - alloc_felt252_dict: AllocFelt252DictInner - - -@dataclass -class Felt252DictEntryInitInner: - dict_ptr: ResOperand - key: ResOperand - - -@dataclass -class Felt252DictEntryInit: - felt252_dict_entry_init: Felt252DictEntryInitInner - - -@dataclass -class Felt252DictEntryUpdateInner: - dict_ptr: ResOperand - value: ResOperand - - -@dataclass -class Felt252DictEntryUpdate: - felt252_dict_entry_update: Felt252DictEntryUpdateInner - - -@dataclass -class GetSegmentArenaIndexInner: - dict_end_ptr: ResOperand - dict_index: ResOperand - - -@dataclass -class GetSegmentArenaIndex: - get_segment_arena_index: GetSegmentArenaIndexInner - - -@dataclass -class InitSquashDataInner: - dict_access: ResOperand - ptr_diff: ResOperand - n_accesses: ResOperand - big_keys: CellRef - first_key: CellRef - - -@dataclass -class InitSquashData: - init_squash_data: InitSquashDataInner - - -@dataclass -class GetCurrentAccessIndexInner: - range_check_ptr: ResOperand - - -@dataclass -class GetCurrentAccessIndex: - get_current_access_index: GetCurrentAccessIndexInner - - -@dataclass -class ShouldSkipSquashLoopInner: - should_skip_loop: CellRef - - -@dataclass -class ShouldSkipSquashLoop: - should_skip_squash_loop: ShouldSkipSquashLoopInner - - -@dataclass -class GetCurrentAccessDeltaInner: - index_delta_minus_1: CellRef - - -@dataclass -class GetCurrentAccessDelta: - get_current_access_delta: GetCurrentAccessDeltaInner - - -@dataclass -class ShouldContinueSquashLoopInner: - should_continue: CellRef - - -@dataclass -class ShouldContinueSquashLoop: - should_continue_squash_loop: ShouldContinueSquashLoopInner - - -@dataclass -class GetNextDictKeyInner: - next_key: CellRef - - -@dataclass -class GetNextDictKey: - get_next_dict_key: GetNextDictKeyInner - - -@dataclass -class AssertLeFindSmallArcsInner: - range_check_ptr: ResOperand - a: ResOperand - b: ResOperand - - -@dataclass -class AssertLeFindSmallArcs: - assert_le_find_small_arcs: AssertLeFindSmallArcsInner - - -@dataclass -class AssertLeIsFirstArcExcludedInner: - skip_exclude_a_flag: CellRef - - -@dataclass -class AssertLeIsFirstArcExcluded: - assert_le_is_first_arc_excluded: AssertLeIsFirstArcExcludedInner - - -@dataclass -class AssertLeIsSecondArcExcludedInner: - skip_exclude_b_minus_a: CellRef - - -@dataclass -class AssertLeIsSecondArcExcluded: - assert_le_is_second_arc_excluded: AssertLeIsSecondArcExcludedInner - - -@dataclass -class RandomEcPointInner: - x: CellRef - y: CellRef - - -@dataclass -class RandomEcPoint: - random_ec_point: RandomEcPointInner - - -@dataclass -class FieldSqrtInner: - val: ResOperand - sqrt: CellRef - - -@dataclass -class FieldSqrt: - field_sqrt: FieldSqrtInner - - -@dataclass -class DebugPrintInner: - start: ResOperand - end: ResOperand - - -@dataclass -class DebugPrint: - debug_print: DebugPrintInner - - -@dataclass -class AllocConstantSizeInner: - size: ResOperand - dst: CellRef - - -@dataclass -class AllocConstantSize: - alloc_constant_size: AllocConstantSizeInner - - -@dataclass -class U256InvModNInner: - # pylint: disable=too-many-instance-attributes - b_0: ResOperand - b_1: ResOperand - n_0: ResOperand - n_1: ResOperand - g_0_or_no_inv: CellRef - g_1_option: CellRef - s_or_r_0: CellRef - s_or_r_1: CellRef - t_or_k_0: CellRef - t_or_k_1: CellRef - - -@dataclass -class U256InvModN: - u256_inv_mod_n: U256InvModNInner - - -@dataclass -class EvalCircuitInner: - n_add_mods: ResOperand - add_mod_builtin: ResOperand - n_mul_mods: ResOperand - mul_mod_builtin: ResOperand - - -@dataclass -class EvalCircuit: - eval_circuit: EvalCircuitInner - - -@dataclass -class SystemCallInner: - system: ResOperand - - -@dataclass -class SystemCall: - system_call: SystemCallInner - - -@dataclass -class CheatcodeInner: - selector: int - input_start: ResOperand - input_end: ResOperand - output_start: CellRef - output_end: CellRef - - -@dataclass -class Cheatcode: - cheatcode: CheatcodeInner - - -Hint = Union[ - AssertCurrentAccessIndicesIsEmpty, - AssertAllKeysUsed, - AssertLeAssertThirdArcExcluded, - AssertAllAccessesUsed, - AssertLtAssertValidInput, - Felt252DictRead, - Felt252DictWrite, - AllocSegment, - TestLessThan, - TestLessThanOrEqual, - TestLessThenOrEqualAddress, - WideMul128, - DivMod, - Uint256DivMod, - Uint512DivModByUint256, - SquareRoot, - Uint256SquareRoot, - LinearSplit, - AllocFelt252Dict, - Felt252DictEntryInit, - Felt252DictEntryUpdate, - GetSegmentArenaIndex, - InitSquashData, - GetCurrentAccessIndex, - ShouldSkipSquashLoop, - GetCurrentAccessDelta, - ShouldContinueSquashLoop, - GetNextDictKey, - AssertLeFindSmallArcs, - AssertLeIsFirstArcExcluded, - AssertLeIsSecondArcExcluded, - RandomEcPoint, - FieldSqrt, - DebugPrint, - AllocConstantSize, - U256InvModN, - EvalCircuit, - SystemCall, - Cheatcode, -] - - @dataclass class CasmClass: """ diff --git a/starknet_py/net/models/compiled_casm.py b/starknet_py/net/models/compiled_casm.py new file mode 100644 index 000000000..81f8c5d46 --- /dev/null +++ b/starknet_py/net/models/compiled_casm.py @@ -0,0 +1,528 @@ +from dataclasses import dataclass +from enum import Enum +from typing import Literal, Tuple, Union + + +class AssertCurrentAccessIndicesIsEmpty(Enum): + ASSERT_CURRENT_ACCESS_INDICES_IS_EMPTY = "AssertCurrentAccessIndicesIsEmpty" + + +class AssertAllKeysUsed(Enum): + ASSERT_ALL_KEYS_USED = "AssertAllKeysUsed" + + +class AssertLeAssertThirdArcExcluded(Enum): + ASSERT_LE_ASSERT_THIRD_ARC_EXCLUDED = "AssertLeAssertThirdArcExcluded" + + +@dataclass +class CellRef: + register: Literal["AP", "FP"] + offset: int + + +@dataclass +class AssertAllAccessesUsedInner: + n_used_accesses: CellRef + + +@dataclass +class AssertAllAccessesUsed: + assert_all_accesses_used: AssertAllAccessesUsedInner + + +@dataclass +class Deref: + deref: CellRef + + +@dataclass +class DoubleDeref: + double_deref: Tuple[CellRef, int] + + +@dataclass +class Immediate: + immediate: int + + +@dataclass +class BinOpInner: + op: Literal["Add", "Mul"] + a: CellRef + b: Union[Deref, Immediate] + + +@dataclass +class BinOp: + bin_op: BinOpInner + + +ResOperand = Union[Deref, DoubleDeref, Immediate, BinOp] + + +@dataclass +class AssertLtAssertValidInputInner: + a: ResOperand + b: ResOperand + + +@dataclass +class AssertLtAssertValidInput: + assert_lt_assert_valid_input: AssertLtAssertValidInputInner + + +@dataclass +class Felt252DictReadInner: + dict_ptr: ResOperand + key: ResOperand + value_dst: CellRef + + +@dataclass +class Felt252DictRead: + felt252_dict_read: Felt252DictReadInner + + +@dataclass +class Felt252DictWriteInner: + dict_ptr: ResOperand + key: ResOperand + value: ResOperand + + +@dataclass +class Felt252DictWrite: + felt252_dict_write: Felt252DictWriteInner + + +@dataclass +class AllocSegmentInner: + dst: CellRef + + +@dataclass +class AllocSegment: + alloc_segment: AllocSegmentInner + + +@dataclass +class TestLessThanInner: + lhs: ResOperand + rhs: ResOperand + dst: CellRef + + +@dataclass +class TestLessThan: + test_less_than: TestLessThanInner + + +@dataclass +class TestLessThanOrEqualInner(TestLessThanInner): + pass + + +@dataclass +class TestLessThanOrEqual: + test_less_than_or_equal: TestLessThanOrEqualInner + + +@dataclass +class TestLessThenOrEqualAddressInner(TestLessThanInner): + pass + + +@dataclass +class TestLessThenOrEqualAddress: + test_less_than_or_equal_address: TestLessThenOrEqualAddressInner + + +@dataclass +class WideMul128Inner: + lhs: ResOperand + rhs: ResOperand + high: CellRef + low: CellRef + + +@dataclass +class WideMul128: + wide_mul128: WideMul128Inner + + +@dataclass +class DivModInner: + lhs: ResOperand + rhs: ResOperand + quotient: CellRef + remainder: CellRef + + +@dataclass +class DivMod: + div_mod: DivModInner + + +@dataclass +class Uint256DivModInner: + # pylint: disable=too-many-instance-attributes + dividend_0: ResOperand + dividend_1: ResOperand + divisor_0: ResOperand + divisor_1: ResOperand + quotient_0: CellRef + quotient_1: CellRef + remainder_0: CellRef + remainder_1: CellRef + + +@dataclass +class Uint256DivMod: + uint256_div_mod: Uint256DivModInner + + +@dataclass +class Uint512DivModByUint256Inner: + # pylint: disable=too-many-instance-attributes + dividend_0: ResOperand + dividend_1: ResOperand + dividend_2: ResOperand + dividend_3: ResOperand + divisor_0: ResOperand + divisor_1: ResOperand + quotient_0: CellRef + quotient_1: CellRef + quotient_2: CellRef + quotient_3: CellRef + remainder_0: CellRef + remainder_1: CellRef + + +@dataclass +class Uint512DivModByUint256: + uint512_div_mod_by_uint256: Uint512DivModByUint256Inner + + +@dataclass +class SquareRootInner: + value: ResOperand + dst: CellRef + + +@dataclass +class SquareRoot: + square_root: SquareRootInner + + +@dataclass +class Uint256SquareRootInner: + value_low: ResOperand + value_high: ResOperand + sqrt_0: CellRef + sqrt_1: CellRef + remainder_low: CellRef + remainder_high: CellRef + sqrt_mul_2_minus_remainder_ge_u128: CellRef + + +@dataclass +class Uint256SquareRoot: + uint256_square_root: Uint256SquareRootInner + + +@dataclass +class LinearSplitInner: + value: ResOperand + scalar: ResOperand + max_x: ResOperand + x: CellRef + y: CellRef + + +@dataclass +class LinearSplit: + linear_split: LinearSplitInner + + +@dataclass +class AllocFelt252DictInner: + segment_arena_ptr: ResOperand + + +@dataclass +class AllocFelt252Dict: + alloc_felt252_dict: AllocFelt252DictInner + + +@dataclass +class Felt252DictEntryInitInner: + dict_ptr: ResOperand + key: ResOperand + + +@dataclass +class Felt252DictEntryInit: + felt252_dict_entry_init: Felt252DictEntryInitInner + + +@dataclass +class Felt252DictEntryUpdateInner: + dict_ptr: ResOperand + value: ResOperand + + +@dataclass +class Felt252DictEntryUpdate: + felt252_dict_entry_update: Felt252DictEntryUpdateInner + + +@dataclass +class GetSegmentArenaIndexInner: + dict_end_ptr: ResOperand + dict_index: ResOperand + + +@dataclass +class GetSegmentArenaIndex: + get_segment_arena_index: GetSegmentArenaIndexInner + + +@dataclass +class InitSquashDataInner: + dict_access: ResOperand + ptr_diff: ResOperand + n_accesses: ResOperand + big_keys: CellRef + first_key: CellRef + + +@dataclass +class InitSquashData: + init_squash_data: InitSquashDataInner + + +@dataclass +class GetCurrentAccessIndexInner: + range_check_ptr: ResOperand + + +@dataclass +class GetCurrentAccessIndex: + get_current_access_index: GetCurrentAccessIndexInner + + +@dataclass +class ShouldSkipSquashLoopInner: + should_skip_loop: CellRef + + +@dataclass +class ShouldSkipSquashLoop: + should_skip_squash_loop: ShouldSkipSquashLoopInner + + +@dataclass +class GetCurrentAccessDeltaInner: + index_delta_minus_1: CellRef + + +@dataclass +class GetCurrentAccessDelta: + get_current_access_delta: GetCurrentAccessDeltaInner + + +@dataclass +class ShouldContinueSquashLoopInner: + should_continue: CellRef + + +@dataclass +class ShouldContinueSquashLoop: + should_continue_squash_loop: ShouldContinueSquashLoopInner + + +@dataclass +class GetNextDictKeyInner: + next_key: CellRef + + +@dataclass +class GetNextDictKey: + get_next_dict_key: GetNextDictKeyInner + + +@dataclass +class AssertLeFindSmallArcsInner: + range_check_ptr: ResOperand + a: ResOperand + b: ResOperand + + +@dataclass +class AssertLeFindSmallArcs: + assert_le_find_small_arcs: AssertLeFindSmallArcsInner + + +@dataclass +class AssertLeIsFirstArcExcludedInner: + skip_exclude_a_flag: CellRef + + +@dataclass +class AssertLeIsFirstArcExcluded: + assert_le_is_first_arc_excluded: AssertLeIsFirstArcExcludedInner + + +@dataclass +class AssertLeIsSecondArcExcludedInner: + skip_exclude_b_minus_a: CellRef + + +@dataclass +class AssertLeIsSecondArcExcluded: + assert_le_is_second_arc_excluded: AssertLeIsSecondArcExcludedInner + + +@dataclass +class RandomEcPointInner: + x: CellRef + y: CellRef + + +@dataclass +class RandomEcPoint: + random_ec_point: RandomEcPointInner + + +@dataclass +class FieldSqrtInner: + val: ResOperand + sqrt: CellRef + + +@dataclass +class FieldSqrt: + field_sqrt: FieldSqrtInner + + +@dataclass +class DebugPrintInner: + start: ResOperand + end: ResOperand + + +@dataclass +class DebugPrint: + debug_print: DebugPrintInner + + +@dataclass +class AllocConstantSizeInner: + size: ResOperand + dst: CellRef + + +@dataclass +class AllocConstantSize: + alloc_constant_size: AllocConstantSizeInner + + +@dataclass +class U256InvModNInner: + # pylint: disable=too-many-instance-attributes + b_0: ResOperand + b_1: ResOperand + n_0: ResOperand + n_1: ResOperand + g_0_or_no_inv: CellRef + g_1_option: CellRef + s_or_r_0: CellRef + s_or_r_1: CellRef + t_or_k_0: CellRef + t_or_k_1: CellRef + + +@dataclass +class U256InvModN: + u256_inv_mod_n: U256InvModNInner + + +@dataclass +class EvalCircuitInner: + n_add_mods: ResOperand + add_mod_builtin: ResOperand + n_mul_mods: ResOperand + mul_mod_builtin: ResOperand + + +@dataclass +class EvalCircuit: + eval_circuit: EvalCircuitInner + + +@dataclass +class SystemCallInner: + system: ResOperand + + +@dataclass +class SystemCall: + system_call: SystemCallInner + + +@dataclass +class CheatcodeInner: + selector: int + input_start: ResOperand + input_end: ResOperand + output_start: CellRef + output_end: CellRef + + +@dataclass +class Cheatcode: + cheatcode: CheatcodeInner + + +Hint = Union[ + AssertCurrentAccessIndicesIsEmpty, + AssertAllKeysUsed, + AssertLeAssertThirdArcExcluded, + AssertAllAccessesUsed, + AssertLtAssertValidInput, + Felt252DictRead, + Felt252DictWrite, + AllocSegment, + TestLessThan, + TestLessThanOrEqual, + TestLessThenOrEqualAddress, + WideMul128, + DivMod, + Uint256DivMod, + Uint512DivModByUint256, + SquareRoot, + Uint256SquareRoot, + LinearSplit, + AllocFelt252Dict, + Felt252DictEntryInit, + Felt252DictEntryUpdate, + GetSegmentArenaIndex, + InitSquashData, + GetCurrentAccessIndex, + ShouldSkipSquashLoop, + GetCurrentAccessDelta, + ShouldContinueSquashLoop, + GetNextDictKey, + AssertLeFindSmallArcs, + AssertLeIsFirstArcExcluded, + AssertLeIsSecondArcExcluded, + RandomEcPoint, + FieldSqrt, + DebugPrint, + AllocConstantSize, + U256InvModN, + EvalCircuit, + SystemCall, + Cheatcode, +] diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index 99366e121..e1ed1e113 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -1,12 +1,10 @@ import json +from typing import Any, Optional from marshmallow import EXCLUDE, ValidationError, fields, post_load, validate from starknet_py.abi.v0.schemas import ContractAbiEntrySchema from starknet_py.net.client_models import ( - AssertAllKeysUsed, - AssertCurrentAccessIndicesIsEmpty, - AssertLeAssertThirdArcExcluded, CasmClass, CasmClassEntryPoint, CasmClassEntryPointsByType, @@ -21,6 +19,51 @@ SierraEntryPointsByType, SyncStatus, ) +from starknet_py.net.models.compiled_casm import ( + AllocConstantSize, + AllocFelt252Dict, + AllocSegment, + AssertAllAccessesUsed, + AssertAllKeysUsed, + AssertCurrentAccessIndicesIsEmpty, + AssertLeAssertThirdArcExcluded, + AssertLeFindSmallArcs, + AssertLeIsFirstArcExcluded, + AssertLeIsSecondArcExcluded, + AssertLtAssertValidInput, + BinOp, + Cheatcode, + DebugPrint, + Deref, + DivMod, + DoubleDeref, + EvalCircuit, + Felt252DictEntryInit, + Felt252DictEntryUpdate, + Felt252DictRead, + Felt252DictWrite, + FieldSqrt, + GetCurrentAccessDelta, + GetCurrentAccessIndex, + GetNextDictKey, + GetSegmentArenaIndex, + Immediate, + InitSquashData, + LinearSplit, + RandomEcPoint, + ShouldContinueSquashLoop, + ShouldSkipSquashLoop, + SquareRoot, + SystemCall, + TestLessThan, + TestLessThanOrEqual, + TestLessThenOrEqualAddress, + U256InvModN, + Uint256DivMod, + Uint256SquareRoot, + Uint512DivModByUint256, + WideMul128, +) from starknet_py.net.schemas.common import Felt, NumberAsHex from starknet_py.utils.schema import Schema @@ -206,31 +249,9 @@ class DerefSchema(Schema): deref = fields.Nested(CellRefSchema(), data_key="Deref", required=True) -class DoubleDerefItemField(fields.Field): - def _deserialize(self, value, attr, data, **kwargs): - if isinstance(value, dict): - return CellRefSchema().load(value) - elif isinstance(value, int): - return value - else: - raise ValidationError( - "Invalid value: must be a CellRef object or an integer" - ) - - def _serialize(self, value, attr, obj, **kwargs): - if isinstance(value, dict): - return CellRefSchema().dump(value) - elif isinstance(value, int): - return value - raise ValidationError("Invalid value type during serialization") - - class DoubleDerefSchema(Schema): - double_deref = fields.List( - DoubleDerefItemField(), - data_key="DoubleDeref", - required=True, - validate=validate.Length(2), + double_deref = fields.Tuple( + (CellRefSchema(), fields.Integer()), data_key="DoubleDeref", required=True ) @@ -239,6 +260,14 @@ class ImmediateSchema(Schema): class BinOpBField(fields.Field): + def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs): + if isinstance(value, Deref): + return DerefSchema().dump(value) + elif isinstance(value, Immediate): + return ImmediateSchema().dump(value) + + raise ValidationError(f"Invalid value type during serialization: {value}.") + def _deserialize(self, value, attr, data, **kwargs): if isinstance(value, dict): if DerefSchema.deref.data_key in value: @@ -247,7 +276,7 @@ def _deserialize(self, value, attr, data, **kwargs): return ImmediateSchema().load(value) raise ValidationError( - f"Invalid value provided for 'b': {value}. Must be a Deref object or an Immediate object." + f"Invalid value provided for 'b': {value}. Must be a Deref or an Immediate object." ) @@ -264,6 +293,18 @@ class BinOpSchema(Schema): class ResOperandField(fields.Field): + def _serialize(self, value, attr, obj, **kwargs): + if isinstance(value, Deref): + return DerefSchema().dump(value) + elif isinstance(value, DoubleDeref): + return DoubleDerefSchema().dump(value) + elif isinstance(value, Immediate): + return ImmediateSchema().dump(value) + elif isinstance(value, BinOp): + return BinOpSchema().dump(value) + + raise ValidationError(f"Invalid value type during serialization: {value}.") + def _deserialize(self, value, attr, data, **kwargs): if isinstance(value, dict): if DerefSchema.deref.data_key in value: @@ -746,7 +787,6 @@ class CheatcodeSchema(Schema): class HintField(fields.Field): def _deserialize(self, value, attr, data, **kwargs): if isinstance(value, str): - # Deprecated hint checks if value in AssertCurrentAccessIndicesIsEmpty: return value elif value in AssertAllKeysUsed: @@ -754,109 +794,110 @@ def _deserialize(self, value, attr, data, **kwargs): elif value in AssertLeAssertThirdArcExcluded: return value - elif isinstance(value, dict): - # Deprecated hint - if AssertAllAccessesUsedSchema.assert_all_accesses_used.data_key in value: - return AssertAllAccessesUsedSchema().load(value) - elif ( - AssertLtAssertValidInputSchema.assert_lt_assert_valid_input.data_key - in value - ): - return AssertLtAssertValidInputSchema().load(value) - elif Felt252DictReadSchema.felt252_dict_read.data_key in value: - return Felt252DictReadSchema().load(value) - elif Felt252DictWriteSchema.felt252_dict_write.data_key in value: - return Felt252DictWriteSchema().load(value) - - # Core hint - elif AllocSegmentSchema.alloc_segment.data_key in value: - return AllocSegmentSchema().load(value) - elif TestLessThanSchema.test_less_than.data_key in value: - return TestLessThanSchema().load(value) - elif TestLessThanOrEqualSchema.test_less_than_or_equal.data_key in value: - return TestLessThanOrEqualSchema().load(value) - elif ( - TestLessThenOrEqualAddressSchema.test_less_than_or_equal_address.data_key - in value - ): - return TestLessThenOrEqualAddressSchema().load(value) - elif WideMul128Schema.wide_mul128.data_key in value: - return WideMul128Schema().load(value) - elif DivModSchema.div_mod.data_key in value: - return DivModSchema().load(value) - elif Uint256DivModSchema.uint256_div_mod.data_key in value: - return Uint256DivModSchema().load(value) - elif ( - Uint512DivModByUint256Schema.uint512_div_mod_by_uint256.data_key - in value - ): - return Uint512DivModByUint256Schema().load(value) - elif SquareRootSchema.square_root.data_key in value: - return SquareRootSchema().load(value) - elif Uint256SquareRootSchema.uint256_square_root.data_key in value: - return Uint256SquareRootSchema().load(value) - elif LinearSplitSchema.linear_split.data_key in value: - return LinearSplitSchema().load(value) - elif AllocFelt252DictSchema.alloc_felt252_dict.data_key in value: - return AllocFelt252DictSchema().load(value) - elif Felt252DictEntryInitSchema.felt252_dict_entry_init.data_key in value: - return Felt252DictEntryInitSchema().load(value) - elif ( - Felt252DictEntryUpdateSchema.felt252_dict_entry_update.data_key in value - ): - return Felt252DictEntryUpdateSchema().load(value) - elif GetSegmentArenaIndexSchema.get_segment_arena_index.data_key in value: - return GetSegmentArenaIndexSchema().load(value) - elif InitSquashDataSchema.init_squash_data.data_key in value: - return InitSquashDataSchema().load(value) - elif GetCurrentAccessIndexSchema.get_current_access_index.data_key in value: - return GetCurrentAccessIndexSchema().load(value) - elif ShouldSkipSquashLoopSchema.should_skip_squash_loop.data_key in value: - return ShouldSkipSquashLoopSchema().load(value) - elif GetCurrentAccessDeltaSchema.get_current_access_delta.data_key in value: - return GetCurrentAccessDeltaSchema().load(value) - elif ( - ShouldContinueSquashLoopSchema.should_continue_squash_loop.data_key - in value - ): - return ShouldContinueSquashLoopSchema().load(value) - elif GetNextDictKeySchema.get_next_dict_key.data_key in value: - return GetNextDictKeySchema().load(value) - elif ( - AssertLeFindSmallArcsSchema.assert_le_find_small_arcs.data_key in value - ): - return AssertLeFindSmallArcsSchema().load(value) - elif ( - AssertLeIsFirstArcExcludedSchema.assert_le_is_first_arc_excluded.data_key - in value - ): - return AssertLeIsFirstArcExcludedSchema().load(value) - elif ( - AssertLeIsSecondArcExcludedSchema.assert_le_is_second_arc_excluded.data_key - in value - ): - return AssertLeIsSecondArcExcludedSchema().load(value) - elif RandomEcPointSchema.random_ec_point.data_key in value: - return RandomEcPointSchema().load(value) - elif FieldSqrtSchema.field_sqrt.data_key in value: - return FieldSqrtSchema().load(value) - elif DebugPrintSchema.debug_print.data_key in value: - return DebugPrintSchema().load(value) - elif AllocConstantSizeSchema.alloc_constant_size.data_key in value: - return AllocConstantSizeSchema().load(value) - elif U256InvModNSchema.u256_inv_mod_n.data_key in value: - return U256InvModNSchema().load(value) - elif EvalCircuitSchema.eval_circuit.data_key in value: - return EvalCircuitSchema().load(value) - - # Starknet hint - elif SystemCallSchema.system_call.data_key in value: - return SystemCallSchema().load(value) - elif CheatcodeSchema.cheatcode.data_key in value: - return CheatcodeSchema().load(value) + elif isinstance(value, dict) and len(value.keys()) == 1: + key_to_schema_mapping = { + AssertAllAccessesUsedSchema.assert_all_accesses_used.data_key: AssertAllAccessesUsedSchema, + AssertLtAssertValidInputSchema.assert_lt_assert_valid_input.data_key: AssertLtAssertValidInputSchema, + Felt252DictReadSchema.felt252_dict_read.data_key: Felt252DictReadSchema, + Felt252DictWriteSchema.felt252_dict_write.data_key: Felt252DictWriteSchema, + AllocSegmentSchema.alloc_segment.data_key: AllocSegmentSchema, + TestLessThanSchema.test_less_than.data_key: TestLessThanSchema, + TestLessThanOrEqualSchema.test_less_than_or_equal.data_key: TestLessThanOrEqualSchema, + TestLessThenOrEqualAddressSchema.test_less_than_or_equal_address.data_key: TestLessThenOrEqualAddressSchema, + WideMul128Schema.wide_mul128.data_key: WideMul128Schema, + DivModSchema.div_mod.data_key: DivModSchema, + Uint256DivModSchema.uint256_div_mod.data_key: Uint256DivModSchema, + Uint512DivModByUint256Schema.uint512_div_mod_by_uint256.data_key: Uint512DivModByUint256Schema, + SquareRootSchema.square_root.data_key: SquareRootSchema, + Uint256SquareRootSchema.uint256_square_root.data_key: Uint256SquareRootSchema, + LinearSplitSchema.linear_split.data_key: LinearSplitSchema, + AllocFelt252DictSchema.alloc_felt252_dict.data_key: AllocFelt252DictSchema, + Felt252DictEntryInitSchema.felt252_dict_entry_init.data_key: Felt252DictEntryInitSchema, + Felt252DictEntryUpdateSchema.felt252_dict_entry_update.data_key: Felt252DictEntryUpdateSchema, + GetSegmentArenaIndexSchema.get_segment_arena_index.data_key: GetSegmentArenaIndexSchema, + InitSquashDataSchema.init_squash_data.data_key: InitSquashDataSchema, + GetCurrentAccessIndexSchema.get_current_access_index.data_key: GetCurrentAccessIndexSchema, + ShouldSkipSquashLoopSchema.should_skip_squash_loop.data_key: ShouldSkipSquashLoopSchema, + GetCurrentAccessDeltaSchema.get_current_access_delta.data_key: GetCurrentAccessDeltaSchema, + ShouldContinueSquashLoopSchema.should_continue_squash_loop.data_key: ShouldContinueSquashLoopSchema, + GetNextDictKeySchema.get_next_dict_key.data_key: GetNextDictKeySchema, + AssertLeFindSmallArcsSchema.assert_le_find_small_arcs.data_key: AssertLeFindSmallArcsSchema, + AssertLeIsFirstArcExcludedSchema.assert_le_is_first_arc_excluded.data_key: AssertLeIsFirstArcExcludedSchema, + AssertLeIsSecondArcExcludedSchema.assert_le_is_second_arc_excluded.data_key: AssertLeIsSecondArcExcludedSchema, + RandomEcPointSchema.random_ec_point.data_key: RandomEcPointSchema, + FieldSqrtSchema.field_sqrt.data_key: FieldSqrtSchema, + DebugPrintSchema.debug_print.data_key: DebugPrintSchema, + AllocConstantSizeSchema.alloc_constant_size.data_key: AllocConstantSizeSchema, + U256InvModNSchema.u256_inv_mod_n.data_key: U256InvModNSchema, + EvalCircuitSchema.eval_circuit.data_key: EvalCircuitSchema, + SystemCallSchema.system_call.data_key: SystemCallSchema, + CheatcodeSchema.cheatcode.data_key: CheatcodeSchema, + } + + for data_key, schema_cls in key_to_schema_mapping.items(): + if data_key in value: + return schema_cls().load(value) raise ValidationError(f"Invalid value provided for Hint: {value}.") + def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs): + if isinstance(value, AssertCurrentAccessIndicesIsEmpty): + return str(value.value) + elif isinstance(value, AssertAllKeysUsed): + return str(value.value) + elif isinstance(value, AssertLeAssertThirdArcExcluded): + return str(value.value) + + model_to_schema_mapping = { + AllocConstantSize: AllocConstantSizeSchema, + AllocFelt252Dict: AllocFelt252DictSchema, + AllocSegment: AllocSegmentSchema, + AssertAllAccessesUsed: AssertAllAccessesUsedSchema, + AssertLeFindSmallArcs: AssertLeFindSmallArcsSchema, + AssertLeIsFirstArcExcluded: AssertLeIsFirstArcExcludedSchema, + AssertLeIsSecondArcExcluded: AssertLeIsSecondArcExcludedSchema, + AssertLtAssertValidInput: AssertLtAssertValidInputSchema, + BinOp: BinOpSchema, + Cheatcode: CheatcodeSchema, + DebugPrint: DebugPrintSchema, + Deref: DerefSchema, + DivMod: DivModSchema, + DoubleDeref: DoubleDerefSchema, + EvalCircuit: EvalCircuitSchema, + Felt252DictEntryInit: Felt252DictEntryInitSchema, + Felt252DictEntryUpdate: Felt252DictEntryUpdateSchema, + Felt252DictRead: Felt252DictReadSchema, + Felt252DictWrite: Felt252DictWriteSchema, + FieldSqrt: FieldSqrtSchema, + GetCurrentAccessDelta: GetCurrentAccessDeltaSchema, + GetCurrentAccessIndex: GetCurrentAccessIndexSchema, + GetNextDictKey: GetNextDictKeySchema, + GetSegmentArenaIndex: GetSegmentArenaIndexSchema, + Immediate: ImmediateSchema, + InitSquashData: InitSquashDataSchema, + LinearSplit: LinearSplitSchema, + RandomEcPoint: RandomEcPointSchema, + ShouldContinueSquashLoop: ShouldContinueSquashLoopSchema, + ShouldSkipSquashLoop: ShouldSkipSquashLoopSchema, + SquareRoot: SquareRootSchema, + SystemCall: SystemCallSchema, + TestLessThan: TestLessThanSchema, + TestLessThanOrEqual: TestLessThanOrEqualSchema, + TestLessThenOrEqualAddress: TestLessThenOrEqualAddressSchema, + U256InvModN: U256InvModNSchema, + Uint256DivMod: Uint256DivModSchema, + Uint256SquareRoot: Uint256SquareRootSchema, + Uint512DivModByUint256: Uint512DivModByUint256Schema, + WideMul128: WideMul128Schema, + } + + for model, schema_cls in model_to_schema_mapping.items(): + if isinstance(value, model): + schema = schema_cls() + return schema.dump(value) + + raise ValidationError(f"Invalid value type during serialization: {value}.") + class CasmClassSchema(Schema): prime = NumberAsHex(data_key="prime", required=True) From 1cce72210a1e1c1db01d66d6aebe4563cb35c186 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 16:31:58 +0100 Subject: [PATCH 11/18] Minor refactor of serialize/deserialize methods --- starknet_py/net/schemas/rpc/contract.py | 39 ++++++++++++++++--------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index e1ed1e113..108c64526 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -234,7 +234,9 @@ class CellRefSchema(Schema): class AssertAllAccessesUsedInnerSchema(Schema): - n_used_accesses = fields.Nested(CellRefSchema(), required=True) + n_used_accesses = fields.Nested( + CellRefSchema(), data_key="n_used_accesses", required=True + ) class AssertAllAccessesUsedSchema(Schema): @@ -266,7 +268,9 @@ def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs): elif isinstance(value, Immediate): return ImmediateSchema().dump(value) - raise ValidationError(f"Invalid value type during serialization: {value}.") + raise ValidationError( + f"Invalid value provided for {self.__class__.__name__}: {value}." + ) def _deserialize(self, value, attr, data, **kwargs): if isinstance(value, dict): @@ -303,7 +307,9 @@ def _serialize(self, value, attr, obj, **kwargs): elif isinstance(value, BinOp): return BinOpSchema().dump(value) - raise ValidationError(f"Invalid value type during serialization: {value}.") + raise ValidationError( + f"Invalid value provided for {self.__class__.__name__}: {value}." + ) def _deserialize(self, value, attr, data, **kwargs): if isinstance(value, dict): @@ -788,11 +794,11 @@ class HintField(fields.Field): def _deserialize(self, value, attr, data, **kwargs): if isinstance(value, str): if value in AssertCurrentAccessIndicesIsEmpty: - return value + return AssertCurrentAccessIndicesIsEmpty(value) elif value in AssertAllKeysUsed: - return value + return AssertAllKeysUsed(value) elif value in AssertLeAssertThirdArcExcluded: - return value + return AssertLeAssertThirdArcExcluded(value) elif isinstance(value, dict) and len(value.keys()) == 1: key_to_schema_mapping = { @@ -834,9 +840,11 @@ def _deserialize(self, value, attr, data, **kwargs): CheatcodeSchema.cheatcode.data_key: CheatcodeSchema, } - for data_key, schema_cls in key_to_schema_mapping.items(): - if data_key in value: - return schema_cls().load(value) + key = list(value.keys())[0] + schema_cls = key_to_schema_mapping.get(key) + + if schema_cls is not None: + return schema_cls().load(value) raise ValidationError(f"Invalid value provided for Hint: {value}.") @@ -891,12 +899,15 @@ def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs): WideMul128: WideMul128Schema, } - for model, schema_cls in model_to_schema_mapping.items(): - if isinstance(value, model): - schema = schema_cls() - return schema.dump(value) + schema_cls = model_to_schema_mapping.get(type(value)) + + if schema_cls is not None: + schema = schema_cls() + return schema.dump(value) - raise ValidationError(f"Invalid value type during serialization: {value}.") + raise ValidationError( + f"Invalid value provided for {self.__class__.__name__}: {value}." + ) class CasmClassSchema(Schema): From 65c3e7b95f21ef906377557e63099b31ecc2592f Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 16:36:09 +0100 Subject: [PATCH 12/18] Format --- starknet_py/net/client_models.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index cc561de6c..7022e91dd 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -907,6 +907,21 @@ class CasmClassEntryPointsByType: l1_handler: List[CasmClassEntryPoint] +@dataclass +class CasmClass: + """ + Dataclass representing class compiled to Cairo assembly. + """ + + prime: int + bytecode: List[int] + hints: List[Tuple[int, Hint]] + pythonic_hints: List[Any] + compiler_version: str + entry_points_by_type: CasmClassEntryPointsByType + bytecode_segment_lengths: Optional[List[int]] + + @dataclass class TransactionStatusResponse: """ @@ -1160,18 +1175,3 @@ class MessageStatus: transaction_hash: int finality_status: TransactionFinalityStatus failure_reason: Optional[str] = None - - -@dataclass -class CasmClass: - """ - Dataclass representing class compiled to Cairo assembly. - """ - - prime: int - bytecode: List[int] - hints: List[Tuple[int, Hint]] - pythonic_hints: List[Any] - compiler_version: str - entry_points_by_type: CasmClassEntryPointsByType - bytecode_segment_lengths: Optional[List[int]] From 69497d7d6e67dd5178882094067e87eddd6c3eb2 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 16:37:53 +0100 Subject: [PATCH 13/18] Remove `pythonic_hints` from `CasmClass` --- starknet_py/net/client_models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index 7022e91dd..019e85d3d 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -916,7 +916,6 @@ class CasmClass: prime: int bytecode: List[int] hints: List[Tuple[int, Hint]] - pythonic_hints: List[Any] compiler_version: str entry_points_by_type: CasmClassEntryPointsByType bytecode_segment_lengths: Optional[List[int]] From cbb6042451ea09763651dc3b5f09febf83e60ebb Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 16:42:49 +0100 Subject: [PATCH 14/18] Format --- starknet_py/net/client_models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index 019e85d3d..5bfea5e1d 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -812,6 +812,7 @@ class SierraEntryPointsByType: @dataclass class _SierraContract: + contract_class_version: str sierra_program: List[int] entry_points_by_type: SierraEntryPointsByType From 242180631bcd0cbeb8df20124539d1be030f42fa Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 16:49:40 +0100 Subject: [PATCH 15/18] Add todo for `get_compiled_casm` test --- starknet_py/tests/e2e/client/client_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/starknet_py/tests/e2e/client/client_test.py b/starknet_py/tests/e2e/client/client_test.py index bc4ddc4a8..ac9c6de83 100644 --- a/starknet_py/tests/e2e/client/client_test.py +++ b/starknet_py/tests/e2e/client/client_test.py @@ -132,6 +132,12 @@ async def test_get_messages_status(): pass +@pytest.mark.asyncio +async def test_get_compiled_casm(): + # TODO (#1498): Add test for get_compiled_casm + pass + + @pytest.mark.asyncio async def test_get_transaction_receipt( client, invoke_transaction_hash, block_with_invoke_number From 0c2cc36de8b5dbf475237bad0e7a67f594a6dc83 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 17:21:07 +0100 Subject: [PATCH 16/18] Add `make_dataclass()` to schemas --- starknet_py/net/client_models.py | 2 +- starknet_py/net/schemas/rpc/contract.py | 350 ++++++++++++++++++++++++ 2 files changed, 351 insertions(+), 1 deletion(-) diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index 5bfea5e1d..df7351231 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -11,7 +11,7 @@ from abc import ABC from dataclasses import dataclass, field from enum import Enum -from typing import Any, Iterable, List, Literal, Optional, Tuple, Union, cast +from typing import Iterable, List, Literal, Optional, Tuple, Union, cast from marshmallow import EXCLUDE diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index 108c64526..a91b6c399 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -21,48 +21,86 @@ ) from starknet_py.net.models.compiled_casm import ( AllocConstantSize, + AllocConstantSizeInner, AllocFelt252Dict, + AllocFelt252DictInner, AllocSegment, + AllocSegmentInner, AssertAllAccessesUsed, + AssertAllAccessesUsedInner, AssertAllKeysUsed, AssertCurrentAccessIndicesIsEmpty, AssertLeAssertThirdArcExcluded, AssertLeFindSmallArcs, + AssertLeFindSmallArcsInner, AssertLeIsFirstArcExcluded, + AssertLeIsFirstArcExcludedInner, AssertLeIsSecondArcExcluded, + AssertLeIsSecondArcExcludedInner, AssertLtAssertValidInput, + AssertLtAssertValidInputInner, BinOp, + BinOpInner, + CellRef, Cheatcode, + CheatcodeInner, DebugPrint, + DebugPrintInner, Deref, DivMod, + DivModInner, DoubleDeref, EvalCircuit, + EvalCircuitInner, Felt252DictEntryInit, + Felt252DictEntryInitInner, Felt252DictEntryUpdate, + Felt252DictEntryUpdateInner, Felt252DictRead, + Felt252DictReadInner, Felt252DictWrite, + Felt252DictWriteInner, FieldSqrt, + FieldSqrtInner, GetCurrentAccessDelta, + GetCurrentAccessDeltaInner, GetCurrentAccessIndex, + GetCurrentAccessIndexInner, GetNextDictKey, + GetNextDictKeyInner, GetSegmentArenaIndex, + GetSegmentArenaIndexInner, Immediate, InitSquashData, + InitSquashDataInner, LinearSplit, + LinearSplitInner, RandomEcPoint, + RandomEcPointInner, ShouldContinueSquashLoop, + ShouldContinueSquashLoopInner, ShouldSkipSquashLoop, + ShouldSkipSquashLoopInner, SquareRoot, + SquareRootInner, SystemCall, + SystemCallInner, TestLessThan, + TestLessThanInner, TestLessThanOrEqual, + TestLessThanOrEqualInner, TestLessThenOrEqualAddress, + TestLessThenOrEqualAddressInner, U256InvModN, + U256InvModNInner, Uint256DivMod, + Uint256DivModInner, Uint256SquareRoot, + Uint256SquareRootInner, Uint512DivModByUint256, + Uint512DivModByUint256Inner, WideMul128, + WideMul128Inner, ) from starknet_py.net.schemas.common import Felt, NumberAsHex from starknet_py.utils.schema import Schema @@ -232,12 +270,20 @@ class CellRefSchema(Schema): ) offset = fields.Integer(data_key="offset", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> CellRef: + return CellRef(**data) + class AssertAllAccessesUsedInnerSchema(Schema): n_used_accesses = fields.Nested( CellRefSchema(), data_key="n_used_accesses", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertAllAccessesUsedInner: + return AssertAllAccessesUsedInner(**data) + class AssertAllAccessesUsedSchema(Schema): assert_all_accesses_used = fields.Nested( @@ -246,20 +292,36 @@ class AssertAllAccessesUsedSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertAllAccessesUsed: + return AssertAllAccessesUsed(**data) + class DerefSchema(Schema): deref = fields.Nested(CellRefSchema(), data_key="Deref", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Deref: + return Deref(**data) + class DoubleDerefSchema(Schema): double_deref = fields.Tuple( (CellRefSchema(), fields.Integer()), data_key="DoubleDeref", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> DoubleDeref: + return DoubleDeref(**data) + class ImmediateSchema(Schema): immediate = NumberAsHex(data_key="Immediate", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Immediate: + return Immediate(**data) + class BinOpBField(fields.Field): def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs): @@ -291,10 +353,18 @@ class BinOpInnerSchema(Schema): a = fields.Nested(CellRefSchema(), data_key="a", required=True) b = BinOpBField(data_key="b", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> BinOpInner: + return BinOpInner(**data) + class BinOpSchema(Schema): bin_op = fields.Nested(BinOpInnerSchema(), data_key="BinOp", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> BinOp: + return BinOp(**data) + class ResOperandField(fields.Field): def _serialize(self, value, attr, obj, **kwargs): @@ -329,6 +399,10 @@ class AssertLtAssertValidInputInnerSchema(Schema): a = ResOperandField(data_key="a", required=True) b = ResOperandField(data_key="b", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLtAssertValidInputInner: + return AssertLtAssertValidInputInner(**data) + class AssertLtAssertValidInputSchema(Schema): assert_lt_assert_valid_input = fields.Nested( @@ -337,66 +411,114 @@ class AssertLtAssertValidInputSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLtAssertValidInput: + return AssertLtAssertValidInput(**data) + class Felt252DictReadInnerSchema(Schema): dict_ptr = ResOperandField(data_key="dict_ptr", required=True) key = ResOperandField(data_key="key", required=True) value_dst = fields.Nested(CellRefSchema(), data_key="value_dst", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictReadInner: + return Felt252DictReadInner(**data) + class Felt252DictReadSchema(Schema): felt252_dict_read = fields.Nested( Felt252DictReadInnerSchema(), data_key="Felt252DictRead", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictRead: + return Felt252DictRead(**data) + class Felt252DictWriteInnerSchema(Schema): dict_ptr = ResOperandField(data_key="dict_ptr", required=True) key = ResOperandField(data_key="key", required=True) value = ResOperandField(data_key="value", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictWriteInner: + return Felt252DictWriteInner(**data) + class Felt252DictWriteSchema(Schema): felt252_dict_write = fields.Nested( Felt252DictWriteInnerSchema(), data_key="Felt252DictWrite", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictWrite: + return Felt252DictWrite(**data) + class AllocSegmentInnerSchema(Schema): dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> AllocSegmentInner: + return AllocSegmentInner(**data) + class AllocSegmentSchema(Schema): alloc_segment = fields.Nested( AllocSegmentInnerSchema(), data_key="AllocSegment", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> AllocSegment: + return AllocSegment(**data) + class TestLessThanInnerSchema(Schema): lhs = ResOperandField(data_key="lhs", required=True) rhs = ResOperandField(data_key="rhs", required=True) dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> TestLessThanInner: + return TestLessThanInner(**data) + class TestLessThanSchema(Schema): test_less_than = fields.Nested( TestLessThanInnerSchema(), data_key="TestLessThan", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> TestLessThan: + return TestLessThan(**data) + class TestLessThanOrEqualInnerSchema(TestLessThanInnerSchema): pass + @post_load + def make_dataclass(self, data, **kwargs) -> TestLessThanOrEqualInner: + return TestLessThanOrEqualInner(**data) + class TestLessThanOrEqualSchema(Schema): test_less_than_or_equal = fields.Nested( TestLessThanOrEqualInnerSchema(), data_key="TestLessThanOrEqual", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> TestLessThanOrEqual: + return TestLessThanOrEqual(**data) + class TestLessThenOrEqualAddressInnerSchema(TestLessThanInnerSchema): pass + @post_load + def make_dataclass(self, data, **kwargs) -> TestLessThenOrEqualAddressInner: + return TestLessThenOrEqualAddressInner(**data) + class TestLessThenOrEqualAddressSchema(Schema): test_less_than_or_equal_address = fields.Nested( @@ -405,6 +527,10 @@ class TestLessThenOrEqualAddressSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> TestLessThenOrEqualAddress: + return TestLessThenOrEqualAddress(**data) + class WideMul128InnerSchema(Schema): lhs = ResOperandField(data_key="lhs", required=True) @@ -412,12 +538,20 @@ class WideMul128InnerSchema(Schema): high = fields.Nested(CellRefSchema(), data_key="high", required=True) low = fields.Nested(CellRefSchema(), data_key="low", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> WideMul128Inner: + return WideMul128Inner(**data) + class WideMul128Schema(Schema): wide_mul128 = fields.Nested( WideMul128InnerSchema(), data_key="WideMul128", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> WideMul128: + return WideMul128(**data) + class DivModInnerSchema(Schema): lhs = ResOperandField(data_key="lhs", required=True) @@ -425,10 +559,18 @@ class DivModInnerSchema(Schema): quotient = fields.Nested(CellRefSchema(), data_key="quotient", required=True) remainder = fields.Nested(CellRefSchema(), data_key="remainder", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> DivModInner: + return DivModInner(**data) + class DivModSchema(Schema): div_mod = fields.Nested(DivModInnerSchema(), data_key="DivMod", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> DivMod: + return DivMod(**data) + class Uint256DivModInnerSchema(Schema): dividend_0 = ResOperandField(data_key="dividend0", required=True) @@ -440,12 +582,20 @@ class Uint256DivModInnerSchema(Schema): remainder_0 = fields.Nested(CellRefSchema(), data_key="remainder0", required=True) remainder_1 = fields.Nested(CellRefSchema(), data_key="remainder1", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Uint256DivModInner: + return Uint256DivModInner(**data) + class Uint256DivModSchema(Schema): uint256_div_mod = fields.Nested( Uint256DivModInnerSchema(), data_key="Uint256DivMod", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> Uint256DivMod: + return Uint256DivMod(**data) + class Uint512DivModByUint256InnerSchema(Schema): dividend_0 = ResOperandField(data_key="dividend0", required=True) @@ -461,6 +611,10 @@ class Uint512DivModByUint256InnerSchema(Schema): remainder_0 = fields.Nested(CellRefSchema(), data_key="remainder0", required=True) remainder_1 = fields.Nested(CellRefSchema(), data_key="remainder1", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Uint512DivModByUint256Inner: + return Uint512DivModByUint256Inner(**data) + class Uint512DivModByUint256Schema(Schema): uint512_div_mod_by_uint256 = fields.Nested( @@ -469,17 +623,29 @@ class Uint512DivModByUint256Schema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> Uint512DivModByUint256: + return Uint512DivModByUint256(**data) + class SquareRootInnerSchema(Schema): value = ResOperandField(data_key="value", required=True) dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> SquareRootInner: + return SquareRootInner(**data) + class SquareRootSchema(Schema): square_root = fields.Nested( SquareRootInnerSchema(), data_key="SquareRoot", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> SquareRoot: + return SquareRoot(**data) + class Uint256SquareRootInnerSchema(Schema): value_low = ResOperandField(data_key="value_low", required=True) @@ -496,12 +662,20 @@ class Uint256SquareRootInnerSchema(Schema): CellRefSchema(), data_key="sqrt_mul_2_minus_remainder_ge_u128", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> Uint256SquareRootInner: + return Uint256SquareRootInner(**data) + class Uint256SquareRootSchema(Schema): uint256_square_root = fields.Nested( Uint256SquareRootInnerSchema(), data_key="Uint256SquareRoot", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> Uint256SquareRoot: + return Uint256SquareRoot(**data) + class LinearSplitInnerSchema(Schema): value = ResOperandField(data_key="value", required=True) @@ -510,27 +684,47 @@ class LinearSplitInnerSchema(Schema): x = fields.Nested(CellRefSchema(), data_key="x", required=True) y = fields.Nested(CellRefSchema(), data_key="y", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> LinearSplitInner: + return LinearSplitInner(**data) + class LinearSplitSchema(Schema): linear_split = fields.Nested( LinearSplitInnerSchema(), data_key="LinearSplit", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> LinearSplit: + return LinearSplit(**data) + class AllocFelt252DictInnerSchema(Schema): segment_arena_ptr = ResOperandField(data_key="segment_arena_ptr", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> AllocFelt252DictInner: + return AllocFelt252DictInner(**data) + class AllocFelt252DictSchema(Schema): alloc_felt252_dict = fields.Nested( AllocFelt252DictInnerSchema(), data_key="AllocFelt252Dict", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> AllocFelt252Dict: + return AllocFelt252Dict(**data) + class Felt252DictEntryInitInnerSchema(Schema): dict_ptr = ResOperandField(data_key="dict_ptr", required=True) key = ResOperandField(data_key="key", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictEntryInitInner: + return Felt252DictEntryInitInner(**data) + class Felt252DictEntryInitSchema(Schema): felt252_dict_entry_init = fields.Nested( @@ -539,11 +733,19 @@ class Felt252DictEntryInitSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictEntryInit: + return Felt252DictEntryInit(**data) + class Felt252DictEntryUpdateInnerSchema(Schema): dict_ptr = ResOperandField(data_key="dict_ptr", required=True) value = ResOperandField(data_key="value", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictEntryUpdateInner: + return Felt252DictEntryUpdateInner(**data) + class Felt252DictEntryUpdateSchema(Schema): felt252_dict_entry_update = fields.Nested( @@ -552,11 +754,19 @@ class Felt252DictEntryUpdateSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> Felt252DictEntryUpdate: + return Felt252DictEntryUpdate(**data) + class GetSegmentArenaIndexInnerSchema(Schema): dict_end_ptr = ResOperandField(data_key="dict_end_ptr", required=True) dict_index = ResOperandField(data_key="dict_index", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> GetSegmentArenaIndexInner: + return GetSegmentArenaIndexInner(**data) + class GetSegmentArenaIndexSchema(Schema): get_segment_arena_index = fields.Nested( @@ -565,6 +775,10 @@ class GetSegmentArenaIndexSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> GetSegmentArenaIndex: + return GetSegmentArenaIndex(**data) + class InitSquashDataInnerSchema(Schema): dict_access = ResOperandField(data_key="dict_access", required=True) @@ -573,16 +787,28 @@ class InitSquashDataInnerSchema(Schema): big_keys = fields.Nested(CellRefSchema(), data_key="big_keys", required=True) first_key = fields.Nested(CellRefSchema(), data_key="first_key", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> InitSquashDataInner: + return InitSquashDataInner(**data) + class InitSquashDataSchema(Schema): init_squash_data = fields.Nested( InitSquashDataInnerSchema(), data_key="InitSquashData", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> InitSquashData: + return InitSquashData(**data) + class GetCurrentAccessIndexInnerSchema(Schema): range_check_ptr = ResOperandField(data_key="range_check_ptr", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> GetCurrentAccessIndexInner: + return GetCurrentAccessIndexInner(**data) + class GetCurrentAccessIndexSchema(Schema): get_current_access_index = fields.Nested( @@ -591,12 +817,20 @@ class GetCurrentAccessIndexSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> GetCurrentAccessIndex: + return GetCurrentAccessIndex(**data) + class ShouldSkipSquashLoopInnerSchema(Schema): should_skip_loop = fields.Nested( CellRefSchema(), data_key="should_skip_loop", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> ShouldSkipSquashLoopInner: + return ShouldSkipSquashLoopInner(**data) + class ShouldSkipSquashLoopSchema(Schema): should_skip_squash_loop = fields.Nested( @@ -605,12 +839,20 @@ class ShouldSkipSquashLoopSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> ShouldSkipSquashLoop: + return ShouldSkipSquashLoop(**data) + class GetCurrentAccessDeltaInnerSchema(Schema): index_delta_minus_1 = fields.Nested( CellRefSchema(), data_key="index_delta_minus1", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> GetCurrentAccessDeltaInner: + return GetCurrentAccessDeltaInner(**data) + class GetCurrentAccessDeltaSchema(Schema): get_current_access_delta = fields.Nested( @@ -619,12 +861,20 @@ class GetCurrentAccessDeltaSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> GetCurrentAccessDelta: + return GetCurrentAccessDelta(**data) + class ShouldContinueSquashLoopInnerSchema(Schema): should_continue = fields.Nested( CellRefSchema(), data_key="should_continue", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> ShouldContinueSquashLoopInner: + return ShouldContinueSquashLoopInner(**data) + class ShouldContinueSquashLoopSchema(Schema): should_continue_squash_loop = fields.Nested( @@ -633,22 +883,38 @@ class ShouldContinueSquashLoopSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> ShouldContinueSquashLoop: + return ShouldContinueSquashLoop(**data) + class GetNextDictKeyInnerSchema(Schema): next_key = fields.Nested(CellRefSchema(), data_key="next_key", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> GetNextDictKeyInner: + return GetNextDictKeyInner(**data) + class GetNextDictKeySchema(Schema): get_next_dict_key = fields.Nested( GetNextDictKeyInnerSchema(), data_key="GetNextDictKey", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> GetNextDictKey: + return GetNextDictKey(**data) + class AssertLeFindSmallArcsInnerSchema(Schema): range_check_ptr = ResOperandField(data_key="range_check_ptr", required=True) a = ResOperandField(data_key="a", required=True) b = ResOperandField(data_key="b", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLeFindSmallArcsInner: + return AssertLeFindSmallArcsInner(**data) + class AssertLeFindSmallArcsSchema(Schema): assert_le_find_small_arcs = fields.Nested( @@ -657,12 +923,20 @@ class AssertLeFindSmallArcsSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLeFindSmallArcs: + return AssertLeFindSmallArcs(**data) + class AssertLeIsFirstArcExcludedInnerSchema(Schema): skip_exclude_a_flag = fields.Nested( CellRefSchema(), data_key="skip_exclude_a_flag", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLeIsFirstArcExcludedInner: + return AssertLeIsFirstArcExcludedInner(**data) + class AssertLeIsFirstArcExcludedSchema(Schema): assert_le_is_first_arc_excluded = fields.Nested( @@ -671,12 +945,20 @@ class AssertLeIsFirstArcExcludedSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLeIsFirstArcExcluded: + return AssertLeIsFirstArcExcluded(**data) + class AssertLeIsSecondArcExcludedInnerSchema(Schema): skip_exclude_b_minus_a = fields.Nested( CellRefSchema(), data_key="skip_exclude_b_minus_a", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLeIsSecondArcExcludedInner: + return AssertLeIsSecondArcExcludedInner(**data) + class AssertLeIsSecondArcExcludedSchema(Schema): assert_le_is_second_arc_excluded = fields.Nested( @@ -685,50 +967,86 @@ class AssertLeIsSecondArcExcludedSchema(Schema): required=True, ) + @post_load + def make_dataclass(self, data, **kwargs) -> AssertLeIsSecondArcExcluded: + return AssertLeIsSecondArcExcluded(**data) + class RandomEcPointInnerSchema(Schema): x = fields.Nested(CellRefSchema(), data_key="x", required=True) y = fields.Nested(CellRefSchema(), data_key="y", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> RandomEcPointInner: + return RandomEcPointInner(**data) + class RandomEcPointSchema(Schema): random_ec_point = fields.Nested( RandomEcPointInnerSchema(), data_key="RandomEcPoint", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> RandomEcPoint: + return RandomEcPoint(**data) + class FieldSqrtInnerSchema(Schema): val = ResOperandField(data_key="val", required=True) sqrt = fields.Nested(CellRefSchema(), data_key="sqrt", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> FieldSqrtInner: + return FieldSqrtInner(**data) + class FieldSqrtSchema(Schema): field_sqrt = fields.Nested( FieldSqrtInnerSchema(), data_key="FieldSqrt", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> FieldSqrt: + return FieldSqrt(**data) + class DebugPrintInnerSchema(Schema): start = ResOperandField(data_key="start", required=True) end = ResOperandField(data_key="end", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> DebugPrintInner: + return DebugPrintInner(**data) + class DebugPrintSchema(Schema): debug_print = fields.Nested( DebugPrintInnerSchema(), data_key="DebugPrint", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> DebugPrint: + return DebugPrint(**data) + class AllocConstantSizeInnerSchema(Schema): size = ResOperandField(data_key="size", required=True) dst = fields.Nested(CellRefSchema(), data_key="dst", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> AllocConstantSizeInner: + return AllocConstantSizeInner(**data) + class AllocConstantSizeSchema(Schema): alloc_constant_size = fields.Nested( AllocConstantSizeInnerSchema(), data_key="AllocConstantSize", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> AllocConstantSize: + return AllocConstantSize(**data) + class U256InvModNInnerSchema(Schema): b_0 = ResOperandField(data_key="b0", required=True) @@ -744,12 +1062,20 @@ class U256InvModNInnerSchema(Schema): t_or_k_0 = fields.Nested(CellRefSchema(), data_key="t_or_k0", required=True) t_or_k_1 = fields.Nested(CellRefSchema(), data_key="t_or_k1", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> U256InvModNInner: + return U256InvModNInner(**data) + class U256InvModNSchema(Schema): u256_inv_mod_n = fields.Nested( U256InvModNInnerSchema(), data_key="U256InvModN", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> U256InvModN: + return U256InvModN(**data) + class EvalCircuitInnerSchema(Schema): n_add_mods = ResOperandField(data_key="n_add_mods", required=True) @@ -757,22 +1083,38 @@ class EvalCircuitInnerSchema(Schema): n_mul_mods = ResOperandField(data_key="n_mul_mods", required=True) mul_mod_builtin = ResOperandField(data_key="mul_mod_builtin", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> EvalCircuitInner: + return EvalCircuitInner(**data) + class EvalCircuitSchema(Schema): eval_circuit = fields.Nested( EvalCircuitInnerSchema(), data_key="EvalCircuit", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> EvalCircuit: + return EvalCircuit(**data) + class SystemCallInnerSchema(Schema): system = ResOperandField(data_key="system", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> SystemCallInner: + return SystemCallInner(**data) + class SystemCallSchema(Schema): system_call = fields.Nested( SystemCallInnerSchema(), data_key="SystemCall", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> SystemCall: + return SystemCall(**data) + class CheatcodeInnerSchema(Schema): selector = NumberAsHex(data_key="selector", required=True) @@ -783,12 +1125,20 @@ class CheatcodeInnerSchema(Schema): ) output_end = fields.Nested(CellRefSchema(), data_key="output_end", required=True) + @post_load + def make_dataclass(self, data, **kwargs) -> CheatcodeInner: + return CheatcodeInner(**data) + class CheatcodeSchema(Schema): cheatcode = fields.Nested( CheatcodeInnerSchema(), data_key="Cheatcode", required=True ) + @post_load + def make_dataclass(self, data, **kwargs) -> Cheatcode: + return Cheatcode(**data) + class HintField(fields.Field): def _deserialize(self, value, attr, data, **kwargs): From 2c9c73641c035075e32d99c070b8bc476b266ea8 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Mon, 4 Nov 2024 18:06:42 +0100 Subject: [PATCH 17/18] Fix cyclic imports test --- starknet_py/common.py | 2 +- starknet_py/hash/casm_class_hash.py | 3 ++- starknet_py/net/client.py | 2 +- starknet_py/net/client_models.py | 17 +---------------- starknet_py/net/full_node_client.py | 2 +- starknet_py/net/models/compiled_casm.py | 18 +++++++++++++++++- starknet_py/net/schemas/rpc/contract.py | 6 ++++-- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/starknet_py/common.py b/starknet_py/common.py index 7fcc75106..ac38cbc07 100644 --- a/starknet_py/common.py +++ b/starknet_py/common.py @@ -4,11 +4,11 @@ from marshmallow import EXCLUDE, ValidationError from starknet_py.net.client_models import ( - CasmClass, DeprecatedCompiledContract, DeprecatedContractClass, SierraCompiledContract, ) +from starknet_py.net.models.compiled_casm import CasmClass from starknet_py.net.schemas.rpc.contract import ( CasmClassSchema, ContractClassSchema, diff --git a/starknet_py/hash/casm_class_hash.py b/starknet_py/hash/casm_class_hash.py index f60f583ec..44080ce19 100644 --- a/starknet_py/hash/casm_class_hash.py +++ b/starknet_py/hash/casm_class_hash.py @@ -10,7 +10,8 @@ BytecodeSegmentStructure, NestedIntList, ) -from starknet_py.net.client_models import CasmClass, CasmClassEntryPoint +from starknet_py.net.client_models import CasmClassEntryPoint +from starknet_py.net.models.compiled_casm import CasmClass CASM_CLASS_VERSION = "COMPILED_CLASS_V1" diff --git a/starknet_py/net/client.py b/starknet_py/net/client.py index 1223bf8ab..1ed389ec7 100644 --- a/starknet_py/net/client.py +++ b/starknet_py/net/client.py @@ -9,7 +9,6 @@ BlockStateUpdate, BlockTransactionTrace, Call, - CasmClass, ContractStorageKeys, DeclareTransactionResponse, DeployAccountTransactionResponse, @@ -30,6 +29,7 @@ TransactionStatus, TransactionStatusResponse, ) +from starknet_py.net.models.compiled_casm import CasmClass from starknet_py.net.models.transaction import ( AccountTransaction, Declare, diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index df7351231..3509898a5 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -11,7 +11,7 @@ from abc import ABC from dataclasses import dataclass, field from enum import Enum -from typing import Iterable, List, Literal, Optional, Tuple, Union, cast +from typing import Iterable, List, Literal, Optional, Union, cast from marshmallow import EXCLUDE @@ -26,7 +26,6 @@ ) from starknet_py.abi.v2.shape import AbiDictEntry as AbiDictEntryV2 from starknet_py.abi.v2.shape import AbiDictList as AbiDictListV2 -from starknet_py.net.models.compiled_casm import Hint from starknet_py.utils.constructor_args_translator import _is_abi_v2 # pylint: disable=too-many-lines @@ -908,20 +907,6 @@ class CasmClassEntryPointsByType: l1_handler: List[CasmClassEntryPoint] -@dataclass -class CasmClass: - """ - Dataclass representing class compiled to Cairo assembly. - """ - - prime: int - bytecode: List[int] - hints: List[Tuple[int, Hint]] - compiler_version: str - entry_points_by_type: CasmClassEntryPointsByType - bytecode_segment_lengths: Optional[List[int]] - - @dataclass class TransactionStatusResponse: """ diff --git a/starknet_py/net/full_node_client.py b/starknet_py/net/full_node_client.py index a7b4a4fb1..88e170ed1 100644 --- a/starknet_py/net/full_node_client.py +++ b/starknet_py/net/full_node_client.py @@ -11,7 +11,6 @@ BlockStateUpdate, BlockTransactionTrace, Call, - CasmClass, ContractStorageKeys, DeclareTransactionResponse, DeployAccountTransactionResponse, @@ -48,6 +47,7 @@ encode_l1_message, ) from starknet_py.net.http_client import RpcHttpClient +from starknet_py.net.models.compiled_casm import CasmClass from starknet_py.net.models.transaction import ( AccountTransaction, Declare, diff --git a/starknet_py/net/models/compiled_casm.py b/starknet_py/net/models/compiled_casm.py index 81f8c5d46..222592f52 100644 --- a/starknet_py/net/models/compiled_casm.py +++ b/starknet_py/net/models/compiled_casm.py @@ -1,6 +1,8 @@ from dataclasses import dataclass from enum import Enum -from typing import Literal, Tuple, Union +from typing import List, Literal, Optional, Tuple, Union + +from starknet_py.net.client_models import CasmClassEntryPointsByType class AssertCurrentAccessIndicesIsEmpty(Enum): @@ -526,3 +528,17 @@ class Cheatcode: SystemCall, Cheatcode, ] + + +@dataclass +class CasmClass: + """ + Dataclass representing class compiled to Cairo assembly. + """ + + prime: int + bytecode: List[int] + hints: List[Tuple[int, Hint]] + compiler_version: str + entry_points_by_type: CasmClassEntryPointsByType + bytecode_segment_lengths: Optional[List[int]] diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index a91b6c399..d504dc55c 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -5,7 +5,6 @@ from starknet_py.abi.v0.schemas import ContractAbiEntrySchema from starknet_py.net.client_models import ( - CasmClass, CasmClassEntryPoint, CasmClassEntryPointsByType, DeployedContract, @@ -41,6 +40,7 @@ AssertLtAssertValidInputInner, BinOp, BinOpInner, + CasmClass, CellRef, Cheatcode, CheatcodeInner, @@ -307,7 +307,9 @@ def make_dataclass(self, data, **kwargs) -> Deref: class DoubleDerefSchema(Schema): double_deref = fields.Tuple( - (CellRefSchema(), fields.Integer()), data_key="DoubleDeref", required=True + (fields.Nested(CellRefSchema()), fields.Integer()), + data_key="DoubleDeref", + required=True, ) @post_load From ebaa859ad1788191504728cc25b066f71f91cd01 Mon Sep 17 00:00:00 2001 From: Fiiranek Date: Thu, 7 Nov 2024 17:35:20 +0100 Subject: [PATCH 18/18] Fix circular imports --- starknet_py/common.py | 2 +- starknet_py/hash/casm_class_hash.py | 3 +- starknet_py/net/client.py | 2 +- starknet_py/net/client_models.py | 541 ++++++++++++++++++++++- starknet_py/net/full_node_client.py | 2 +- starknet_py/net/models/compiled_casm.py | 544 ------------------------ starknet_py/net/schemas/rpc/contract.py | 26 +- 7 files changed, 556 insertions(+), 564 deletions(-) delete mode 100644 starknet_py/net/models/compiled_casm.py diff --git a/starknet_py/common.py b/starknet_py/common.py index ac38cbc07..7fcc75106 100644 --- a/starknet_py/common.py +++ b/starknet_py/common.py @@ -4,11 +4,11 @@ from marshmallow import EXCLUDE, ValidationError from starknet_py.net.client_models import ( + CasmClass, DeprecatedCompiledContract, DeprecatedContractClass, SierraCompiledContract, ) -from starknet_py.net.models.compiled_casm import CasmClass from starknet_py.net.schemas.rpc.contract import ( CasmClassSchema, ContractClassSchema, diff --git a/starknet_py/hash/casm_class_hash.py b/starknet_py/hash/casm_class_hash.py index 44080ce19..f60f583ec 100644 --- a/starknet_py/hash/casm_class_hash.py +++ b/starknet_py/hash/casm_class_hash.py @@ -10,8 +10,7 @@ BytecodeSegmentStructure, NestedIntList, ) -from starknet_py.net.client_models import CasmClassEntryPoint -from starknet_py.net.models.compiled_casm import CasmClass +from starknet_py.net.client_models import CasmClass, CasmClassEntryPoint CASM_CLASS_VERSION = "COMPILED_CLASS_V1" diff --git a/starknet_py/net/client.py b/starknet_py/net/client.py index 1ed389ec7..1223bf8ab 100644 --- a/starknet_py/net/client.py +++ b/starknet_py/net/client.py @@ -9,6 +9,7 @@ BlockStateUpdate, BlockTransactionTrace, Call, + CasmClass, ContractStorageKeys, DeclareTransactionResponse, DeployAccountTransactionResponse, @@ -29,7 +30,6 @@ TransactionStatus, TransactionStatusResponse, ) -from starknet_py.net.models.compiled_casm import CasmClass from starknet_py.net.models.transaction import ( AccountTransaction, Declare, diff --git a/starknet_py/net/client_models.py b/starknet_py/net/client_models.py index 3509898a5..2fbc24306 100644 --- a/starknet_py/net/client_models.py +++ b/starknet_py/net/client_models.py @@ -11,7 +11,7 @@ from abc import ABC from dataclasses import dataclass, field from enum import Enum -from typing import Iterable, List, Literal, Optional, Union, cast +from typing import Iterable, List, Literal, Optional, Tuple, Union, cast from marshmallow import EXCLUDE @@ -1160,3 +1160,542 @@ class MessageStatus: transaction_hash: int finality_status: TransactionFinalityStatus failure_reason: Optional[str] = None + + +class AssertCurrentAccessIndicesIsEmpty(Enum): + ASSERT_CURRENT_ACCESS_INDICES_IS_EMPTY = "AssertCurrentAccessIndicesIsEmpty" + + +class AssertAllKeysUsed(Enum): + ASSERT_ALL_KEYS_USED = "AssertAllKeysUsed" + + +class AssertLeAssertThirdArcExcluded(Enum): + ASSERT_LE_ASSERT_THIRD_ARC_EXCLUDED = "AssertLeAssertThirdArcExcluded" + + +@dataclass +class CellRef: + register: Literal["AP", "FP"] + offset: int + + +@dataclass +class AssertAllAccessesUsedInner: + n_used_accesses: CellRef + + +@dataclass +class AssertAllAccessesUsed: + assert_all_accesses_used: AssertAllAccessesUsedInner + + +@dataclass +class Deref: + deref: CellRef + + +@dataclass +class DoubleDeref: + double_deref: Tuple[CellRef, int] + + +@dataclass +class Immediate: + immediate: int + + +@dataclass +class BinOpInner: + op: Literal["Add", "Mul"] + a: CellRef + b: Union[Deref, Immediate] + + +@dataclass +class BinOp: + bin_op: BinOpInner + + +ResOperand = Union[Deref, DoubleDeref, Immediate, BinOp] + + +@dataclass +class AssertLtAssertValidInputInner: + a: ResOperand + b: ResOperand + + +@dataclass +class AssertLtAssertValidInput: + assert_lt_assert_valid_input: AssertLtAssertValidInputInner + + +@dataclass +class Felt252DictReadInner: + dict_ptr: ResOperand + key: ResOperand + value_dst: CellRef + + +@dataclass +class Felt252DictRead: + felt252_dict_read: Felt252DictReadInner + + +@dataclass +class Felt252DictWriteInner: + dict_ptr: ResOperand + key: ResOperand + value: ResOperand + + +@dataclass +class Felt252DictWrite: + felt252_dict_write: Felt252DictWriteInner + + +@dataclass +class AllocSegmentInner: + dst: CellRef + + +@dataclass +class AllocSegment: + alloc_segment: AllocSegmentInner + + +@dataclass +class TestLessThanInner: + lhs: ResOperand + rhs: ResOperand + dst: CellRef + + +@dataclass +class TestLessThan: + test_less_than: TestLessThanInner + + +@dataclass +class TestLessThanOrEqualInner(TestLessThanInner): + pass + + +@dataclass +class TestLessThanOrEqual: + test_less_than_or_equal: TestLessThanOrEqualInner + + +@dataclass +class TestLessThenOrEqualAddressInner(TestLessThanInner): + pass + + +@dataclass +class TestLessThenOrEqualAddress: + test_less_than_or_equal_address: TestLessThenOrEqualAddressInner + + +@dataclass +class WideMul128Inner: + lhs: ResOperand + rhs: ResOperand + high: CellRef + low: CellRef + + +@dataclass +class WideMul128: + wide_mul128: WideMul128Inner + + +@dataclass +class DivModInner: + lhs: ResOperand + rhs: ResOperand + quotient: CellRef + remainder: CellRef + + +@dataclass +class DivMod: + div_mod: DivModInner + + +@dataclass +class Uint256DivModInner: + # pylint: disable=too-many-instance-attributes + dividend_0: ResOperand + dividend_1: ResOperand + divisor_0: ResOperand + divisor_1: ResOperand + quotient_0: CellRef + quotient_1: CellRef + remainder_0: CellRef + remainder_1: CellRef + + +@dataclass +class Uint256DivMod: + uint256_div_mod: Uint256DivModInner + + +@dataclass +class Uint512DivModByUint256Inner: + # pylint: disable=too-many-instance-attributes + dividend_0: ResOperand + dividend_1: ResOperand + dividend_2: ResOperand + dividend_3: ResOperand + divisor_0: ResOperand + divisor_1: ResOperand + quotient_0: CellRef + quotient_1: CellRef + quotient_2: CellRef + quotient_3: CellRef + remainder_0: CellRef + remainder_1: CellRef + + +@dataclass +class Uint512DivModByUint256: + uint512_div_mod_by_uint256: Uint512DivModByUint256Inner + + +@dataclass +class SquareRootInner: + value: ResOperand + dst: CellRef + + +@dataclass +class SquareRoot: + square_root: SquareRootInner + + +@dataclass +class Uint256SquareRootInner: + value_low: ResOperand + value_high: ResOperand + sqrt_0: CellRef + sqrt_1: CellRef + remainder_low: CellRef + remainder_high: CellRef + sqrt_mul_2_minus_remainder_ge_u128: CellRef + + +@dataclass +class Uint256SquareRoot: + uint256_square_root: Uint256SquareRootInner + + +@dataclass +class LinearSplitInner: + value: ResOperand + scalar: ResOperand + max_x: ResOperand + x: CellRef + y: CellRef + + +@dataclass +class LinearSplit: + linear_split: LinearSplitInner + + +@dataclass +class AllocFelt252DictInner: + segment_arena_ptr: ResOperand + + +@dataclass +class AllocFelt252Dict: + alloc_felt252_dict: AllocFelt252DictInner + + +@dataclass +class Felt252DictEntryInitInner: + dict_ptr: ResOperand + key: ResOperand + + +@dataclass +class Felt252DictEntryInit: + felt252_dict_entry_init: Felt252DictEntryInitInner + + +@dataclass +class Felt252DictEntryUpdateInner: + dict_ptr: ResOperand + value: ResOperand + + +@dataclass +class Felt252DictEntryUpdate: + felt252_dict_entry_update: Felt252DictEntryUpdateInner + + +@dataclass +class GetSegmentArenaIndexInner: + dict_end_ptr: ResOperand + dict_index: ResOperand + + +@dataclass +class GetSegmentArenaIndex: + get_segment_arena_index: GetSegmentArenaIndexInner + + +@dataclass +class InitSquashDataInner: + dict_access: ResOperand + ptr_diff: ResOperand + n_accesses: ResOperand + big_keys: CellRef + first_key: CellRef + + +@dataclass +class InitSquashData: + init_squash_data: InitSquashDataInner + + +@dataclass +class GetCurrentAccessIndexInner: + range_check_ptr: ResOperand + + +@dataclass +class GetCurrentAccessIndex: + get_current_access_index: GetCurrentAccessIndexInner + + +@dataclass +class ShouldSkipSquashLoopInner: + should_skip_loop: CellRef + + +@dataclass +class ShouldSkipSquashLoop: + should_skip_squash_loop: ShouldSkipSquashLoopInner + + +@dataclass +class GetCurrentAccessDeltaInner: + index_delta_minus_1: CellRef + + +@dataclass +class GetCurrentAccessDelta: + get_current_access_delta: GetCurrentAccessDeltaInner + + +@dataclass +class ShouldContinueSquashLoopInner: + should_continue: CellRef + + +@dataclass +class ShouldContinueSquashLoop: + should_continue_squash_loop: ShouldContinueSquashLoopInner + + +@dataclass +class GetNextDictKeyInner: + next_key: CellRef + + +@dataclass +class GetNextDictKey: + get_next_dict_key: GetNextDictKeyInner + + +@dataclass +class AssertLeFindSmallArcsInner: + range_check_ptr: ResOperand + a: ResOperand + b: ResOperand + + +@dataclass +class AssertLeFindSmallArcs: + assert_le_find_small_arcs: AssertLeFindSmallArcsInner + + +@dataclass +class AssertLeIsFirstArcExcludedInner: + skip_exclude_a_flag: CellRef + + +@dataclass +class AssertLeIsFirstArcExcluded: + assert_le_is_first_arc_excluded: AssertLeIsFirstArcExcludedInner + + +@dataclass +class AssertLeIsSecondArcExcludedInner: + skip_exclude_b_minus_a: CellRef + + +@dataclass +class AssertLeIsSecondArcExcluded: + assert_le_is_second_arc_excluded: AssertLeIsSecondArcExcludedInner + + +@dataclass +class RandomEcPointInner: + x: CellRef + y: CellRef + + +@dataclass +class RandomEcPoint: + random_ec_point: RandomEcPointInner + + +@dataclass +class FieldSqrtInner: + val: ResOperand + sqrt: CellRef + + +@dataclass +class FieldSqrt: + field_sqrt: FieldSqrtInner + + +@dataclass +class DebugPrintInner: + start: ResOperand + end: ResOperand + + +@dataclass +class DebugPrint: + debug_print: DebugPrintInner + + +@dataclass +class AllocConstantSizeInner: + size: ResOperand + dst: CellRef + + +@dataclass +class AllocConstantSize: + alloc_constant_size: AllocConstantSizeInner + + +@dataclass +class U256InvModNInner: + # pylint: disable=too-many-instance-attributes + b_0: ResOperand + b_1: ResOperand + n_0: ResOperand + n_1: ResOperand + g_0_or_no_inv: CellRef + g_1_option: CellRef + s_or_r_0: CellRef + s_or_r_1: CellRef + t_or_k_0: CellRef + t_or_k_1: CellRef + + +@dataclass +class U256InvModN: + u256_inv_mod_n: U256InvModNInner + + +@dataclass +class EvalCircuitInner: + n_add_mods: ResOperand + add_mod_builtin: ResOperand + n_mul_mods: ResOperand + mul_mod_builtin: ResOperand + + +@dataclass +class EvalCircuit: + eval_circuit: EvalCircuitInner + + +@dataclass +class SystemCallInner: + system: ResOperand + + +@dataclass +class SystemCall: + system_call: SystemCallInner + + +@dataclass +class CheatcodeInner: + selector: int + input_start: ResOperand + input_end: ResOperand + output_start: CellRef + output_end: CellRef + + +@dataclass +class Cheatcode: + cheatcode: CheatcodeInner + + +Hint = Union[ + AssertCurrentAccessIndicesIsEmpty, + AssertAllKeysUsed, + AssertLeAssertThirdArcExcluded, + AssertAllAccessesUsed, + AssertLtAssertValidInput, + Felt252DictRead, + Felt252DictWrite, + AllocSegment, + TestLessThan, + TestLessThanOrEqual, + TestLessThenOrEqualAddress, + WideMul128, + DivMod, + Uint256DivMod, + Uint512DivModByUint256, + SquareRoot, + Uint256SquareRoot, + LinearSplit, + AllocFelt252Dict, + Felt252DictEntryInit, + Felt252DictEntryUpdate, + GetSegmentArenaIndex, + InitSquashData, + GetCurrentAccessIndex, + ShouldSkipSquashLoop, + GetCurrentAccessDelta, + ShouldContinueSquashLoop, + GetNextDictKey, + AssertLeFindSmallArcs, + AssertLeIsFirstArcExcluded, + AssertLeIsSecondArcExcluded, + RandomEcPoint, + FieldSqrt, + DebugPrint, + AllocConstantSize, + U256InvModN, + EvalCircuit, + SystemCall, + Cheatcode, +] + + +@dataclass +class CasmClass: + """ + Dataclass representing class compiled to Cairo assembly. + """ + + prime: int + bytecode: List[int] + hints: List[Tuple[int, Hint]] + compiler_version: str + entry_points_by_type: CasmClassEntryPointsByType + bytecode_segment_lengths: Optional[List[int]] diff --git a/starknet_py/net/full_node_client.py b/starknet_py/net/full_node_client.py index 88e170ed1..a7b4a4fb1 100644 --- a/starknet_py/net/full_node_client.py +++ b/starknet_py/net/full_node_client.py @@ -11,6 +11,7 @@ BlockStateUpdate, BlockTransactionTrace, Call, + CasmClass, ContractStorageKeys, DeclareTransactionResponse, DeployAccountTransactionResponse, @@ -47,7 +48,6 @@ encode_l1_message, ) from starknet_py.net.http_client import RpcHttpClient -from starknet_py.net.models.compiled_casm import CasmClass from starknet_py.net.models.transaction import ( AccountTransaction, Declare, diff --git a/starknet_py/net/models/compiled_casm.py b/starknet_py/net/models/compiled_casm.py deleted file mode 100644 index 222592f52..000000000 --- a/starknet_py/net/models/compiled_casm.py +++ /dev/null @@ -1,544 +0,0 @@ -from dataclasses import dataclass -from enum import Enum -from typing import List, Literal, Optional, Tuple, Union - -from starknet_py.net.client_models import CasmClassEntryPointsByType - - -class AssertCurrentAccessIndicesIsEmpty(Enum): - ASSERT_CURRENT_ACCESS_INDICES_IS_EMPTY = "AssertCurrentAccessIndicesIsEmpty" - - -class AssertAllKeysUsed(Enum): - ASSERT_ALL_KEYS_USED = "AssertAllKeysUsed" - - -class AssertLeAssertThirdArcExcluded(Enum): - ASSERT_LE_ASSERT_THIRD_ARC_EXCLUDED = "AssertLeAssertThirdArcExcluded" - - -@dataclass -class CellRef: - register: Literal["AP", "FP"] - offset: int - - -@dataclass -class AssertAllAccessesUsedInner: - n_used_accesses: CellRef - - -@dataclass -class AssertAllAccessesUsed: - assert_all_accesses_used: AssertAllAccessesUsedInner - - -@dataclass -class Deref: - deref: CellRef - - -@dataclass -class DoubleDeref: - double_deref: Tuple[CellRef, int] - - -@dataclass -class Immediate: - immediate: int - - -@dataclass -class BinOpInner: - op: Literal["Add", "Mul"] - a: CellRef - b: Union[Deref, Immediate] - - -@dataclass -class BinOp: - bin_op: BinOpInner - - -ResOperand = Union[Deref, DoubleDeref, Immediate, BinOp] - - -@dataclass -class AssertLtAssertValidInputInner: - a: ResOperand - b: ResOperand - - -@dataclass -class AssertLtAssertValidInput: - assert_lt_assert_valid_input: AssertLtAssertValidInputInner - - -@dataclass -class Felt252DictReadInner: - dict_ptr: ResOperand - key: ResOperand - value_dst: CellRef - - -@dataclass -class Felt252DictRead: - felt252_dict_read: Felt252DictReadInner - - -@dataclass -class Felt252DictWriteInner: - dict_ptr: ResOperand - key: ResOperand - value: ResOperand - - -@dataclass -class Felt252DictWrite: - felt252_dict_write: Felt252DictWriteInner - - -@dataclass -class AllocSegmentInner: - dst: CellRef - - -@dataclass -class AllocSegment: - alloc_segment: AllocSegmentInner - - -@dataclass -class TestLessThanInner: - lhs: ResOperand - rhs: ResOperand - dst: CellRef - - -@dataclass -class TestLessThan: - test_less_than: TestLessThanInner - - -@dataclass -class TestLessThanOrEqualInner(TestLessThanInner): - pass - - -@dataclass -class TestLessThanOrEqual: - test_less_than_or_equal: TestLessThanOrEqualInner - - -@dataclass -class TestLessThenOrEqualAddressInner(TestLessThanInner): - pass - - -@dataclass -class TestLessThenOrEqualAddress: - test_less_than_or_equal_address: TestLessThenOrEqualAddressInner - - -@dataclass -class WideMul128Inner: - lhs: ResOperand - rhs: ResOperand - high: CellRef - low: CellRef - - -@dataclass -class WideMul128: - wide_mul128: WideMul128Inner - - -@dataclass -class DivModInner: - lhs: ResOperand - rhs: ResOperand - quotient: CellRef - remainder: CellRef - - -@dataclass -class DivMod: - div_mod: DivModInner - - -@dataclass -class Uint256DivModInner: - # pylint: disable=too-many-instance-attributes - dividend_0: ResOperand - dividend_1: ResOperand - divisor_0: ResOperand - divisor_1: ResOperand - quotient_0: CellRef - quotient_1: CellRef - remainder_0: CellRef - remainder_1: CellRef - - -@dataclass -class Uint256DivMod: - uint256_div_mod: Uint256DivModInner - - -@dataclass -class Uint512DivModByUint256Inner: - # pylint: disable=too-many-instance-attributes - dividend_0: ResOperand - dividend_1: ResOperand - dividend_2: ResOperand - dividend_3: ResOperand - divisor_0: ResOperand - divisor_1: ResOperand - quotient_0: CellRef - quotient_1: CellRef - quotient_2: CellRef - quotient_3: CellRef - remainder_0: CellRef - remainder_1: CellRef - - -@dataclass -class Uint512DivModByUint256: - uint512_div_mod_by_uint256: Uint512DivModByUint256Inner - - -@dataclass -class SquareRootInner: - value: ResOperand - dst: CellRef - - -@dataclass -class SquareRoot: - square_root: SquareRootInner - - -@dataclass -class Uint256SquareRootInner: - value_low: ResOperand - value_high: ResOperand - sqrt_0: CellRef - sqrt_1: CellRef - remainder_low: CellRef - remainder_high: CellRef - sqrt_mul_2_minus_remainder_ge_u128: CellRef - - -@dataclass -class Uint256SquareRoot: - uint256_square_root: Uint256SquareRootInner - - -@dataclass -class LinearSplitInner: - value: ResOperand - scalar: ResOperand - max_x: ResOperand - x: CellRef - y: CellRef - - -@dataclass -class LinearSplit: - linear_split: LinearSplitInner - - -@dataclass -class AllocFelt252DictInner: - segment_arena_ptr: ResOperand - - -@dataclass -class AllocFelt252Dict: - alloc_felt252_dict: AllocFelt252DictInner - - -@dataclass -class Felt252DictEntryInitInner: - dict_ptr: ResOperand - key: ResOperand - - -@dataclass -class Felt252DictEntryInit: - felt252_dict_entry_init: Felt252DictEntryInitInner - - -@dataclass -class Felt252DictEntryUpdateInner: - dict_ptr: ResOperand - value: ResOperand - - -@dataclass -class Felt252DictEntryUpdate: - felt252_dict_entry_update: Felt252DictEntryUpdateInner - - -@dataclass -class GetSegmentArenaIndexInner: - dict_end_ptr: ResOperand - dict_index: ResOperand - - -@dataclass -class GetSegmentArenaIndex: - get_segment_arena_index: GetSegmentArenaIndexInner - - -@dataclass -class InitSquashDataInner: - dict_access: ResOperand - ptr_diff: ResOperand - n_accesses: ResOperand - big_keys: CellRef - first_key: CellRef - - -@dataclass -class InitSquashData: - init_squash_data: InitSquashDataInner - - -@dataclass -class GetCurrentAccessIndexInner: - range_check_ptr: ResOperand - - -@dataclass -class GetCurrentAccessIndex: - get_current_access_index: GetCurrentAccessIndexInner - - -@dataclass -class ShouldSkipSquashLoopInner: - should_skip_loop: CellRef - - -@dataclass -class ShouldSkipSquashLoop: - should_skip_squash_loop: ShouldSkipSquashLoopInner - - -@dataclass -class GetCurrentAccessDeltaInner: - index_delta_minus_1: CellRef - - -@dataclass -class GetCurrentAccessDelta: - get_current_access_delta: GetCurrentAccessDeltaInner - - -@dataclass -class ShouldContinueSquashLoopInner: - should_continue: CellRef - - -@dataclass -class ShouldContinueSquashLoop: - should_continue_squash_loop: ShouldContinueSquashLoopInner - - -@dataclass -class GetNextDictKeyInner: - next_key: CellRef - - -@dataclass -class GetNextDictKey: - get_next_dict_key: GetNextDictKeyInner - - -@dataclass -class AssertLeFindSmallArcsInner: - range_check_ptr: ResOperand - a: ResOperand - b: ResOperand - - -@dataclass -class AssertLeFindSmallArcs: - assert_le_find_small_arcs: AssertLeFindSmallArcsInner - - -@dataclass -class AssertLeIsFirstArcExcludedInner: - skip_exclude_a_flag: CellRef - - -@dataclass -class AssertLeIsFirstArcExcluded: - assert_le_is_first_arc_excluded: AssertLeIsFirstArcExcludedInner - - -@dataclass -class AssertLeIsSecondArcExcludedInner: - skip_exclude_b_minus_a: CellRef - - -@dataclass -class AssertLeIsSecondArcExcluded: - assert_le_is_second_arc_excluded: AssertLeIsSecondArcExcludedInner - - -@dataclass -class RandomEcPointInner: - x: CellRef - y: CellRef - - -@dataclass -class RandomEcPoint: - random_ec_point: RandomEcPointInner - - -@dataclass -class FieldSqrtInner: - val: ResOperand - sqrt: CellRef - - -@dataclass -class FieldSqrt: - field_sqrt: FieldSqrtInner - - -@dataclass -class DebugPrintInner: - start: ResOperand - end: ResOperand - - -@dataclass -class DebugPrint: - debug_print: DebugPrintInner - - -@dataclass -class AllocConstantSizeInner: - size: ResOperand - dst: CellRef - - -@dataclass -class AllocConstantSize: - alloc_constant_size: AllocConstantSizeInner - - -@dataclass -class U256InvModNInner: - # pylint: disable=too-many-instance-attributes - b_0: ResOperand - b_1: ResOperand - n_0: ResOperand - n_1: ResOperand - g_0_or_no_inv: CellRef - g_1_option: CellRef - s_or_r_0: CellRef - s_or_r_1: CellRef - t_or_k_0: CellRef - t_or_k_1: CellRef - - -@dataclass -class U256InvModN: - u256_inv_mod_n: U256InvModNInner - - -@dataclass -class EvalCircuitInner: - n_add_mods: ResOperand - add_mod_builtin: ResOperand - n_mul_mods: ResOperand - mul_mod_builtin: ResOperand - - -@dataclass -class EvalCircuit: - eval_circuit: EvalCircuitInner - - -@dataclass -class SystemCallInner: - system: ResOperand - - -@dataclass -class SystemCall: - system_call: SystemCallInner - - -@dataclass -class CheatcodeInner: - selector: int - input_start: ResOperand - input_end: ResOperand - output_start: CellRef - output_end: CellRef - - -@dataclass -class Cheatcode: - cheatcode: CheatcodeInner - - -Hint = Union[ - AssertCurrentAccessIndicesIsEmpty, - AssertAllKeysUsed, - AssertLeAssertThirdArcExcluded, - AssertAllAccessesUsed, - AssertLtAssertValidInput, - Felt252DictRead, - Felt252DictWrite, - AllocSegment, - TestLessThan, - TestLessThanOrEqual, - TestLessThenOrEqualAddress, - WideMul128, - DivMod, - Uint256DivMod, - Uint512DivModByUint256, - SquareRoot, - Uint256SquareRoot, - LinearSplit, - AllocFelt252Dict, - Felt252DictEntryInit, - Felt252DictEntryUpdate, - GetSegmentArenaIndex, - InitSquashData, - GetCurrentAccessIndex, - ShouldSkipSquashLoop, - GetCurrentAccessDelta, - ShouldContinueSquashLoop, - GetNextDictKey, - AssertLeFindSmallArcs, - AssertLeIsFirstArcExcluded, - AssertLeIsSecondArcExcluded, - RandomEcPoint, - FieldSqrt, - DebugPrint, - AllocConstantSize, - U256InvModN, - EvalCircuit, - SystemCall, - Cheatcode, -] - - -@dataclass -class CasmClass: - """ - Dataclass representing class compiled to Cairo assembly. - """ - - prime: int - bytecode: List[int] - hints: List[Tuple[int, Hint]] - compiler_version: str - entry_points_by_type: CasmClassEntryPointsByType - bytecode_segment_lengths: Optional[List[int]] diff --git a/starknet_py/net/schemas/rpc/contract.py b/starknet_py/net/schemas/rpc/contract.py index d504dc55c..6a1283d96 100644 --- a/starknet_py/net/schemas/rpc/contract.py +++ b/starknet_py/net/schemas/rpc/contract.py @@ -5,20 +5,6 @@ from starknet_py.abi.v0.schemas import ContractAbiEntrySchema from starknet_py.net.client_models import ( - CasmClassEntryPoint, - CasmClassEntryPointsByType, - DeployedContract, - DeprecatedCompiledContract, - DeprecatedContractClass, - EntryPoint, - EntryPointsByType, - SierraCompiledContract, - SierraContractClass, - SierraEntryPoint, - SierraEntryPointsByType, - SyncStatus, -) -from starknet_py.net.models.compiled_casm import ( AllocConstantSize, AllocConstantSizeInner, AllocFelt252Dict, @@ -41,15 +27,22 @@ BinOp, BinOpInner, CasmClass, + CasmClassEntryPoint, + CasmClassEntryPointsByType, CellRef, Cheatcode, CheatcodeInner, DebugPrint, DebugPrintInner, + DeployedContract, + DeprecatedCompiledContract, + DeprecatedContractClass, Deref, DivMod, DivModInner, DoubleDeref, + EntryPoint, + EntryPointsByType, EvalCircuit, EvalCircuitInner, Felt252DictEntryInit, @@ -81,8 +74,13 @@ ShouldContinueSquashLoopInner, ShouldSkipSquashLoop, ShouldSkipSquashLoopInner, + SierraCompiledContract, + SierraContractClass, + SierraEntryPoint, + SierraEntryPointsByType, SquareRoot, SquareRootInner, + SyncStatus, SystemCall, SystemCallInner, TestLessThan,