Skip to content

Commit

Permalink
Cairo v0.11.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed Mar 20, 2023
1 parent d34583c commit f260522
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 72 deletions.
2 changes: 1 addition & 1 deletion scripts/requirements-gen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ pytest-asyncio
PyYAML
typeguard<3.0.0
sympy
Web3
Web3<6.0.0
2 changes: 1 addition & 1 deletion src/starkware/cairo/lang/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.0a2
0.11.0
7 changes: 7 additions & 0 deletions src/starkware/cairo/lang/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
"starkware.crypto.signature": ["pedersen_params.json"],
"starkware.starknet": ["common/*.cairo", "definitions/*.yml"],
"starkware.starknet.business_logic.execution": ["os_resources.json"],
"starkware.starknet.compiler.v1": [
"corelib/*.cairo",
"corelib/src/*.cairo",
"corelib/src/starknet/*.cairo",
"bin/starknet-sierra-compile",
"bin/starknet-compile",
],
"starkware.starknet.core.os": ["*/*.cairo", "*.cairo", "*.json"],
"starkware.starknet.core.test_contract": ["*.cairo", "*.json"],
"starkware.starknet.security": ["whitelists/*.json"],
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/cairo/sharp/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"prover_url": "https://testnet.provingservice.io",
"verifier_address": "0x87b653D97B4e507A19a4A16bbF7434dcEf853AaA",
"verifier_address": "0x8f97970aC5a9aa8D130d35146F5b59c4aef57963",
"steps_limit": 1000000
}
1 change: 0 additions & 1 deletion src/starkware/starknet/business_logic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ python_lib(starknet_business_logic_utils_lib
cairo_function_runner_lib
cairo_vm_lib
starknet_abi_lib
starknet_business_logic_fact_state_lib
starknet_business_logic_patricia_state_lib
starknet_business_logic_state_lib
starknet_contract_class_lib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ python_lib(starknet_execute_entry_point_base_lib
execute_entry_point_base.py

LIBS
starknet_business_logic_fact_state_lib
starknet_business_logic_state_lib
starknet_contract_class_lib
starknet_general_config_lib
Expand All @@ -51,7 +50,6 @@ python_lib(starknet_execute_entry_point_lib
everest_definitions_lib
segment_arena_builtin_lib
starknet_abi_lib
starknet_business_logic_fact_state_lib
starknet_business_logic_state_lib
starknet_business_logic_utils_lib
starknet_contract_class_lib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
CallInfo,
CallResult,
CallType,
ExecutionResourcesManager,
OrderedEvent,
OrderedL2ToL1Message,
TransactionExecutionContext,
)
from starkware.starknet.business_logic.fact_state.state import ExecutionResourcesManager
from starkware.starknet.business_logic.state.state import ContractStorageState, StateSyncifier
from starkware.starknet.business_logic.state.state_api import State, SyncState
from starkware.starknet.business_logic.utils import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from starkware.starknet.business_logic.execution.objects import (
CallInfo,
CallType,
ExecutionResourcesManager,
TransactionExecutionContext,
)
from starkware.starknet.business_logic.fact_state.state import ExecutionResourcesManager
from starkware.starknet.business_logic.state.state_api import SyncState
from starkware.starknet.definitions.general_config import StarknetGeneralConfig
from starkware.starknet.services.api.contract_class.contract_class import EntryPointType
Expand Down
28 changes: 27 additions & 1 deletion src/starkware/starknet/business_logic/execution/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import operator
from dataclasses import field
from enum import Enum, auto
from typing import FrozenSet, Iterable, Iterator, List, Mapping, Optional, Set, cast
from typing import Dict, FrozenSet, Iterable, Iterator, List, Mapping, Optional, Set, cast

import marshmallow.fields as mfields
import marshmallow_dataclass
Expand Down Expand Up @@ -747,3 +747,29 @@ def get_state_selector_of_many(
(execution_info.get_state_selector() for execution_info in execution_infos),
StateSelector.empty(),
)


class ExecutionResourcesManager:
"""
Aggregates execution resources throughout transaction stream processing.
"""

def __init__(
self,
cairo_usage: ExecutionResources,
syscall_counter: Dict[str, int],
):
# The accumulated Cairo usage.
self.cairo_usage = cairo_usage

# A mapping from system call to the cumulative times it was invoked.
self.syscall_counter = syscall_counter

# Alternative constructors.

@classmethod
def empty(cls) -> "ExecutionResourcesManager":
return cls(
cairo_usage=ExecutionResources.empty(),
syscall_counter={},
)
27 changes: 0 additions & 27 deletions src/starkware/starknet/business_logic/fact_state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
SharedStateBase,
StateSelectorBase,
)
from starkware.cairo.lang.vm.cairo_pie import ExecutionResources
from starkware.cairo.lang.vm.crypto import poseidon_hash_many
from starkware.python.utils import (
from_bytes,
Expand Down Expand Up @@ -48,32 +47,6 @@
ContractCarriedStateMapping = MutableMapping[int, ContractCarriedState]


class ExecutionResourcesManager:
"""
Aggregates execution resources throughout transaction stream processing.
"""

def __init__(
self,
cairo_usage: ExecutionResources,
syscall_counter: Dict[str, int],
):
# The accumulated Cairo usage.
self.cairo_usage = cairo_usage

# A mapping from system call to the cumulative times it was invoked.
self.syscall_counter = syscall_counter

# Alternative constructors.

@classmethod
def empty(cls) -> "ExecutionResourcesManager":
return cls(
cairo_usage=ExecutionResources.empty(),
syscall_counter={},
)


class CarriedState(CarriedStateBase):
"""
A state containing a mapping from contract addresses to their states and the accumulated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ python_lib(starknet_transaction_objects_lib
everest_internal_transaction_lib
everest_transaction_lib
starknet_abi_lib
starknet_business_logic_fact_state_lib
starknet_business_logic_patricia_state_lib
starknet_business_logic_state_lib
starknet_business_logic_utils_lib
Expand Down Expand Up @@ -71,7 +70,6 @@ python_lib(starknet_transaction_fee_lib

LIBS
starknet_abi_lib
starknet_business_logic_fact_state_lib
starknet_business_logic_state_lib
starknet_business_logic_utils_lib
starknet_contract_class_lib
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/starknet/business_logic/transaction/fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from starkware.starknet.business_logic.execution.execute_entry_point import ExecuteEntryPoint
from starkware.starknet.business_logic.execution.objects import (
CallInfo,
ExecutionResourcesManager,
ResourcesMapping,
TransactionExecutionContext,
)
from starkware.starknet.business_logic.fact_state.state import ExecutionResourcesManager
from starkware.starknet.business_logic.state.state_api import SyncState
from starkware.starknet.business_logic.utils import extract_l1_gas_and_cairo_usage
from starkware.starknet.definitions.constants import GasCost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
from starkware.starknet.business_logic.execution.execute_entry_point import ExecuteEntryPoint
from starkware.starknet.business_logic.execution.objects import (
CallInfo,
ExecutionResourcesManager,
ResourcesMapping,
TransactionExecutionContext,
TransactionExecutionInfo,
)
from starkware.starknet.business_logic.fact_state.contract_state_objects import StateSelector
from starkware.starknet.business_logic.fact_state.state import ExecutionResourcesManager
from starkware.starknet.business_logic.state.state import UpdatesTrackerState
from starkware.starknet.business_logic.state.state_api import SyncState
from starkware.starknet.business_logic.state.state_api_objects import BlockInfo
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/starknet/business_logic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from starkware.starknet.business_logic.execution.objects import (
CallInfo,
CallResult,
ExecutionResourcesManager,
ResourcesMapping,
TransactionExecutionInfo,
)
Expand All @@ -19,7 +20,6 @@
ContractClassFact,
DeprecatedCompiledClassFact,
)
from starkware.starknet.business_logic.fact_state.state import ExecutionResourcesManager
from starkware.starknet.business_logic.state.state import UpdatesTrackerState
from starkware.starknet.business_logic.state.state_api import SyncState
from starkware.starknet.definitions import constants, fields
Expand Down
1 change: 0 additions & 1 deletion src/starkware/starknet/core/os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ python_lib(starknet_os_utils_lib
cairo_run_lib
cairo_vm_lib
starknet_abi_lib
starknet_business_logic_fact_state_lib
starknet_business_logic_patricia_state_lib
starknet_business_logic_state_lib
starknet_contract_address_lib
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/starknet/core/os/syscall_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
CallInfo,
CallResult,
CallType,
ExecutionResourcesManager,
OrderedEvent,
OrderedL2ToL1Message,
TransactionExecutionContext,
TransactionExecutionInfo,
)
from starkware.starknet.business_logic.fact_state.state import ExecutionResourcesManager
from starkware.starknet.business_logic.state.state import ContractStorageState
from starkware.starknet.business_logic.state.state_api import SyncState
from starkware.starknet.business_logic.state.state_api_objects import BlockInfo
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/starknet/definitions/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
GAS_PRICE_LOWER_BOUND = 0
GAS_PRICE_UPPER_BOUND = 2**128
MAX_MESSAGE_TO_L1_LENGTH = 100
MAX_CALLDATA_LENGTH = 2**30
NONCE_LOWER_BOUND = 0
NONCE_UPPER_BOUND = 2**NONCE_BITS
SIERRA_ARRAY_LEN_BOUND = 2**32
SYSCALL_SELECTOR_UPPER_BOUND = FIELD_SIZE
TRANSACTION_COMMITMENT_TREE_HEIGHT = 64
TRANSACTION_HASH_LOWER_BOUND = 0
Expand Down
42 changes: 30 additions & 12 deletions src/starkware/starknet/definitions/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from starkware.starknet.definitions import constants
from starkware.starknet.definitions.error_codes import StarknetErrorCode
from starkware.starknet.definitions.transaction_type import TransactionType
from starkware.starkware_utils.field_validators import validate_non_negative, validate_positive
from starkware.starkware_utils.field_validators import (
validate_length,
validate_non_negative,
validate_positive,
)
from starkware.starkware_utils.marshmallow_dataclass_fields import (
BackwardCompatibleIntAsHex,
BytesAsHex,
Expand All @@ -33,6 +37,15 @@
marshmallow_field=mfields.List(everest_fields.FeltField.get_marshmallow_field())
)

bounded_felt_as_hex_list_metadata = dict(
marshmallow_field=mfields.List(
everest_fields.FeltField.get_marshmallow_field(),
validate=validate_length(
field_name="felt_list", max_length=constants.SIERRA_ARRAY_LEN_BOUND - 1
),
)
)

felt_as_hex_or_str_list_metadata = dict(
marshmallow_field=mfields.List(
BackwardCompatibleIntAsHex(
Expand All @@ -41,12 +54,21 @@
)
)

calldata_metadata = felt_as_hex_or_str_list_metadata

felt_list_metadata = dict(
marshmallow_field=mfields.List(IntAsStr(validate=everest_fields.FeltField.validate))
)

bounded_felt_as_hex_or_str_list_metadata = dict(
marshmallow_field=mfields.List(
BackwardCompatibleIntAsHex(
allow_decimal_loading=True, validate=everest_fields.FeltField.validate
),
validate=validate_length(
field_name="felt_list", max_length=constants.SIERRA_ARRAY_LEN_BOUND - 1
),
)
)


def felt_formatter(hex_felt: str) -> str:
return field_element_repr(val=int(hex_felt, 16), prime=everest_fields.FeltField.upper_bound)
Expand All @@ -71,6 +93,11 @@ def new_class_hash_dict_keys_metadata(
marshmallow_field=StrictRequiredInteger(validate=validate_non_negative("timestamp"))
)

calldata_metadata = bounded_felt_as_hex_or_str_list_metadata
signature_metadata = bounded_felt_as_hex_or_str_list_metadata
calldata_as_hex_metadata = bounded_felt_as_hex_list_metadata
retdata_as_hex_metadata = felt_as_hex_list_metadata


# Address.

Expand Down Expand Up @@ -154,15 +181,6 @@ def address_metadata(name: str, error_code: StarknetErrorCode) -> Dict[str, Any]
field_name="Transaction index", required=False, load_default=None
)


# InvokeFunction.

call_data_as_hex_metadata = felt_as_hex_list_metadata
signature_as_hex_metadata = felt_as_hex_or_str_list_metadata
signature_metadata = felt_list_metadata
retdata_as_hex_metadata = felt_as_hex_list_metadata


# L1Handler.

payload_metadata = felt_as_hex_list_metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ mod TestContract {
const UNEXPECTED_ERROR: felt252 = 'UNEXPECTED ERROR';

struct Storage {
my_storage_var: felt252
my_storage_var: felt252,
public_key: felt252
}

#[constructor]
fn constructor() {
public_key::write('public_key');
}

#[external]
Expand Down Expand Up @@ -149,5 +155,17 @@ mod TestContract {
z
}

#[external]
fn test_deploy(
class_hash: ClassHash,
contract_address_salt: felt252,
calldata: Array::<felt252>,
deploy_from_zero: bool,
) {
starknet::syscalls::deploy_syscall(
class_hash, contract_address_salt, calldata.span(), deploy_from_zero
).unwrap_syscall();

}
}

Loading

0 comments on commit f260522

Please sign in to comment.