Skip to content

Commit

Permalink
Cairo v0.8.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed Mar 13, 2022
1 parent ed6cf8d commit 4e23351
Show file tree
Hide file tree
Showing 283 changed files with 9,383 additions and 2,491 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.cairo linguist-language=python linguist-detectable=false
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.5)
cmake_minimum_required (VERSION 3.22)

project(CairoLang VERSION 0.1.0)
include(CTest)
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM ciimage/python:3.7

RUN apt update
RUN apt install -y cmake libgmp3-dev g++ python3-pip python3.7-dev python3.7-venv npm
RUN apt install -y make libgmp3-dev g++ python3-pip python3.7-dev python3.7-venv npm
# Installing cmake via apt doesn't bring the most up-to-date version.
RUN pip install cmake==3.22

# Install solc and ganache
RUN curl https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.6.12+commit.27d51765 -o /usr/local/bin/solc-0.6.12
Expand All @@ -19,7 +21,7 @@ WORKDIR /app/build/Release
RUN make all -j8

# Run tests.
RUN ctest -V
RUN ctest -V -j8

WORKDIR /app/
RUN src/starkware/cairo/lang/package_test/run_test.sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Once the docker image is built, you can fetch the python package zip file using:

```bash
> container_id=$(docker create cairo)
> docker cp ${container_id}:/app/cairo-lang-0.7.1.zip .
> docker cp ${container_id}:/app/cairo-lang-0.8.0.zip .
> docker rm -v ${container_id}
```

32 changes: 18 additions & 14 deletions src/cmake_utils/pip_rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ function(python_pip TARGET)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Create a list of all dependencies regardless of python's version.
execute_process(
COMMAND ${UNITE_LIBS_EXECUTABLE} ${ARGS_LIBS}
OUTPUT_VARIABLE UNITED_LIBS
)
set(UNITED_LIBS ${ARGS_LIBS})
if("${UNITED_LIBS}" MATCHES ":")
execute_process(
COMMAND ${UNITE_LIBS_EXECUTABLE} ${UNITED_LIBS}
OUTPUT_VARIABLE UNITED_LIBS
)
endif()
separate_arguments(UNITED_LIBS)

set(ALL_STAMPS)
Expand All @@ -32,17 +35,15 @@ function(python_pip TARGET)
set(STAMP_FILE ${CMAKE_BINARY_DIR}/python_pip/${TARGET}_${INTERPRETER}_${REQ}.stamp)

# Creating library directory.
if (${REQ} MATCHES "==local$")
if (${REQ} MATCHES "\\+local$")
string(REPLACE "==" "-" PACKAGE_NAME ${REQ})
set(ZIP_FILE "${PROJECT_SOURCE_DIR}/${PACKAGE_NAME}.zip")
add_custom_command(
OUTPUT ${STAMP_FILE}
COMMENT "Building ${REQ} from a local copy."
COMMAND rm -rf ${LIB_DIR}/*
COMMAND unzip ${ZIP_FILE} -d ${LIB_DIR} > /dev/null
# We don't know if the directory in the zip has the same name as the package.
COMMAND ls ${LIB_DIR} | grep -v -x ${PACKAGE_NAME} | xargs -r -I {} mv ${LIB_DIR}/{} ${LIB_DIR}/${PACKAGE_NAME}
COMMAND mv ${LIB_DIR}/${PACKAGE_NAME}/* ${LIB_DIR}
COMMAND mv ${LIB_DIR}/${PACKAGE_NAME}/* ${LIB_DIR}/
COMMAND rm -rf ${LIB_DIR}/${PACKAGE_NAME}/
COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_FILE}
DEPENDS ${ZIP_FILE}
Expand Down Expand Up @@ -70,8 +71,8 @@ function(python_pip TARGET)
)
endif()

set(ALL_STAMPS ${ALL_STAMPS} ${STAMP_FILE})
set(ALL_LIB_DIRS ${ALL_LIB_DIRS} "${INTERPRETER}:${LIB_DIR}")
list(APPEND ALL_STAMPS ${STAMP_FILE})
list(APPEND ALL_LIB_DIRS "${INTERPRETER}:${LIB_DIR}")
endforeach()

# Info target.
Expand Down Expand Up @@ -108,10 +109,13 @@ function(python_get_pip_deps TARGET)
set(CMAKE_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_generated_rules.cmake")

# Create a list of all dependency files.
execute_process(
COMMAND ${UNITE_LIBS_EXECUTABLE} ${ARGN}
OUTPUT_VARIABLE UNITED_DEP_FILES
)
set(UNITED_DEP_FILES ${ARGN})
if("${UNITED_DEP_FILES}" MATCHES ":")
execute_process(
COMMAND ${UNITE_LIBS_EXECUTABLE} ${UNITED_DEP_FILES}
OUTPUT_VARIABLE UNITED_DEP_FILES
)
endif()
separate_arguments(UNITED_DEP_FILES)

# Add as a reconfigure dependency, so that CMake will reconfigure on change.
Expand Down
21 changes: 12 additions & 9 deletions src/cmake_utils/python_rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function(python_lib LIB)
# Copy files.
copy_files(${LIB}_copy_files ${CMAKE_CURRENT_SOURCE_DIR} ${LIB_DIR} ${ARGS_FILES})
get_target_property(COPY_STAMP ${LIB}_copy_files STAMP_FILE)
set(ALL_FILE_DEPS ${ALL_FILE_DEPS} ${COPY_STAMP})
list(APPEND ALL_FILE_DEPS ${COPY_STAMP})

# Copy artifacts.
foreach(ARTIFACT ${ARGS_ARTIFACTS})
Expand All @@ -73,22 +73,25 @@ function(python_lib LIB)
DEPENDS ${ARTIFACT_SRC}
COMMENT "Copying artifact ${ARTIFACT_SRC} to ${LIB_DIR}/${ARTIFACT_DEST}"
)
set(ALL_FILE_DEPS ${ALL_FILE_DEPS} ${LIB_DIR}/${ARTIFACT_DEST})
set(LIB_FILES ${LIB_FILES} ${ARGS_PREFIX}${ARTIFACT_DEST})
list(APPEND ALL_FILE_DEPS ${LIB_DIR}/${ARTIFACT_DEST})
list(APPEND LIB_FILES ${ARGS_PREFIX}${ARTIFACT_DEST})
endforeach()

# Create a list of all dependencies regardless of python's version.
execute_process(
COMMAND ${UNITE_LIBS_EXECUTABLE} ${ARGS_LIBS}
OUTPUT_VARIABLE UNITED_LIBS
)
set(UNITED_LIBS ${ARGS_LIBS})
if("${UNITED_LIBS}" MATCHES ":")
execute_process(
COMMAND ${UNITE_LIBS_EXECUTABLE} ${UNITED_LIBS}
OUTPUT_VARIABLE UNITED_LIBS
)
endif()
separate_arguments(UNITED_LIBS)

# Info target.
set(DEP_INFO)
foreach(DEP_LIB ${UNITED_LIBS} ${ARGS_PY_EXE_DEPENDENCIES})
get_lib_info_file(DEP_INFO_FILE ${DEP_LIB})
set(DEP_INFO ${DEP_INFO} ${DEP_INFO_FILE})
LIST(APPEND DEP_INFO ${DEP_INFO_FILE})
endforeach()

get_lib_info_file(INFO_FILE ${LIB})
Expand Down Expand Up @@ -140,7 +143,7 @@ function(python_venv VENV_NAME)
set(DEP_INFO)
foreach(DEP_LIB ${ARGS_LIBS})
get_lib_info_file(DEP_INFO_FILE ${DEP_LIB})
set(DEP_INFO ${DEP_INFO} ${DEP_INFO_FILE})
list(APPEND DEP_INFO ${DEP_INFO_FILE})
endforeach()

add_custom_command(
Expand Down
4 changes: 2 additions & 2 deletions src/demo/amm_demo/amm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from starkware.cairo.common.dict_access import DictAccess
from starkware.cairo.common.hash import hash2
from starkware.cairo.common.math import assert_nn_le, unsigned_div_rem
from starkware.cairo.common.registers import get_fp_and_pc
from starkware.cairo.common.small_merkle_tree import small_merkle_tree
from starkware.cairo.common.small_merkle_tree import small_merkle_tree_update

struct Account:
member public_key : felt
Expand Down Expand Up @@ -213,7 +213,7 @@ func compute_merkle_roots{pedersen_ptr : HashBuiltin*, range_check_ptr}(state :
hash_dict_start=hash_dict_start)

# Compute the two Merkle roots.
let (root_before, root_after) = small_merkle_tree{hash_ptr=pedersen_ptr}(
let (root_before, root_after) = small_merkle_tree_update{hash_ptr=pedersen_ptr}(
squashed_dict_start=hash_dict_start,
squashed_dict_end=hash_dict_end,
height=LOG_N_ACCOUNTS)
Expand Down
2 changes: 1 addition & 1 deletion src/demo/amm_demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from web3 import HTTPProvider, Web3, eth

from demo.amm_demo.prove_batch import Account, Balance, BatchProver, SwapTransaction
from starkware.cairo.bootloader.hash_program import compute_program_hash_chain
from starkware.cairo.bootloaders.hash_program import compute_program_hash_chain
from starkware.cairo.common.small_merkle_tree import MerkleTree
from starkware.cairo.lang.vm.crypto import get_crypto_lib_context_manager, pedersen_hash
from starkware.cairo.sharp.sharp_client import init_client
Expand Down
2 changes: 1 addition & 1 deletion src/demo/amm_demo/prove_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tempfile
from typing import Any, Dict, List, Tuple

from starkware.cairo.bootloader.generate_fact import get_program_output
from starkware.cairo.bootloaders.generate_fact import get_program_output
from starkware.cairo.sharp.sharp_client import Program, SharpClient


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ class EverestFeederGatewayClient(BaseClient):
async def get_last_batch_id(self) -> int:
raw_response = await self._send_request(send_method="GET", uri="/get_last_batch_id")
return json.loads(raw_response)

async def get_l1_blockchain_id(self) -> int:
raw_response = await self._send_request(send_method="GET", uri="/get_l1_blockchain_id")
return json.loads(raw_response)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def add_class(self, cls: type):
self.classes[cls_name] = cls


class EverestTransactionExecutionInfo:
class EverestTransactionExecutionInfo(ValidatedMarshmallowDataclass):
"""
Base class of classes containing information generated from an execution of a transaction on
the state. Each Everest application may implement it specifically.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ class TransactionFailureReason(ValidatedMarshmallowDataclass):
transaction.
"""

tx_id: int
code: str
error_message: Optional[str]

@marshmallow.decorators.pre_load
def remove_tx_id(self, data: Dict[str, Any], many: bool, **kwargs) -> Dict[str, Any]:
data.pop("tx_id", None)
return data

@marshmallow.decorators.post_dump
def truncate_error_message(self, data: Dict[str, Any], many: bool, **kwargs) -> Dict[str, Any]:
error_message = data["error_message"]
Expand Down
11 changes: 11 additions & 0 deletions src/services/everest/definitions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ python_lib(everest_definitions_lib
pip_marshmallow
pip_web3
)

python_lib(everest_general_config_lib
PREFIX services/everest/definitions

FILES
general_config.py

LIBS
starkware_config_utils_lib
pip_marshmallow_dataclass
)
6 changes: 5 additions & 1 deletion src/services/everest/definitions/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ def format(self, value: str) -> str:
)


def felt(name_in_error_message: str) -> RangeValidatedField:
return dataclasses.replace(FeltField, name=name_in_error_message)


def felt_metadata(name_in_error_message: str) -> Dict[str, Any]:
return dataclasses.replace(FeltField, name=name_in_error_message).metadata()
return felt(name_in_error_message=name_in_error_message).metadata()
8 changes: 8 additions & 0 deletions src/services/everest/definitions/general_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import marshmallow_dataclass

from starkware.starkware_utils.config_base import Config


@marshmallow_dataclass.dataclass(frozen=True)
class EverestGeneralConfig(Config):
pass
8 changes: 8 additions & 0 deletions src/services/external_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
python_lib(services_external_api_utils_lib
PREFIX services/external_api

FILES
utils.py
)

python_lib(services_external_api_lib
PREFIX services/external_api

Expand All @@ -7,6 +14,7 @@ python_lib(services_external_api_lib
${SERVICES_EXTERNAL_API_LIB_ADDITIONAL_FILES}

LIBS
services_external_api_utils_lib
starkware_dataclasses_utils_lib
pip_aiohttp
${SERVICES_EXTERNAL_API_LIB_ADDITIONAL_LIBS}
Expand Down
16 changes: 7 additions & 9 deletions src/services/external_api/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,18 @@ async def _send_request(

return text
except aiohttp.ClientError as exception:
error_message = f"Got {type(exception).__name__}"
error_message = f"Got {type(exception).__name__} while trying to access {url}."

if limited_retries and n_retries_left == 0:
logger.error(error_message, exc_info=True)
raise

logger.debug(f"{error_message}, retrying...", exc_info=True)
logger.debug(f"{error_message}, retrying...")
except BadRequest as exception:
error_message = f"Got {type(exception).__name__}"
error_message = (
f"Got {type(exception).__name__} while trying to access {url}. "
f"Status code: {exception.status_code}; text: {exception.text}."
)

if limited_retries and (
n_retries_left == 0
Expand All @@ -134,12 +137,7 @@ async def _send_request(
logger.error(error_message, exc_info=True)
raise

logger.debug(
f"{error_message} while trying to access {url}. "
f"status_code: {exception.status_code}. text: {exception.text}, "
"retrying...",
exc_info=True,
)
logger.debug(f"{error_message}, retrying...")

await asyncio.sleep(1)

Expand Down
11 changes: 7 additions & 4 deletions src/services/external_api/has_uri_prefix.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from abc import ABC, abstractmethod
from typing import cast
from typing import Optional, cast

from services.external_api.utils import join_routes


class HasUriPrefix(ABC):
Expand All @@ -17,9 +19,10 @@ def prefix(cls) -> str:
"""

@classmethod
def format_uri(cls, name: str) -> str:
def format_uri(cls, name: str, version: Optional[str] = None) -> str:
"""
Concatenates cls.prefix with given URI.
Concatenates version/cls.prefix with given URI.
"""
prefix = cast(str, cls.prefix) # Mypy sees the property as a callable.
return name if len(prefix) == 0 else f"{cls.prefix}{name}"
route_list = [s for s in [version, prefix, name] if s is not None and len(s) != 0]
return join_routes(route_list=route_list)
11 changes: 11 additions & 0 deletions src/services/external_api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import List


def join_routes(route_list: List[str]) -> str:
"""
Joins a list of routes where the result will start with '/' and between every two routes there
will be exactly one '/'. The reason why it is implemented and the builtin urljoin isn't being
used, is that urljoin ignores preceding strings in the path if a leading slash is encountered.
"""
assert None not in route_list and "" not in route_list
return "/" + "/".join(s.strip("/") for s in route_list)
2 changes: 1 addition & 1 deletion src/starkware/cairo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_subdirectory(bootloader)
add_subdirectory(bootloaders)
add_subdirectory(common)
add_subdirectory(lang)
add_subdirectory(sharp)
32 changes: 0 additions & 32 deletions src/starkware/cairo/bootloader/fact_topology.py

This file was deleted.

Loading

0 comments on commit 4e23351

Please sign in to comment.