Skip to content

Commit

Permalink
v0.13.0a0 (pre).
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed Nov 16, 2023
1 parent 8dcdcf9 commit 351e92a
Show file tree
Hide file tree
Showing 233 changed files with 64,283 additions and 32,232 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ RUN ./docker_common_deps.sh
RUN curl https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.6.12+commit.27d51765 -o /usr/local/bin/solc-0.6.12
RUN echo 'f6cb519b01dabc61cab4c184a3db11aa591d18151e362fcae850e42cffdfb09a /usr/local/bin/solc-0.6.12' | sha256sum --check
RUN chmod +x /usr/local/bin/solc-0.6.12
RUN npm install -g --unsafe-perm ganache@7.4.3
RUN npm install -g --unsafe-perm ganache@7.4.3 vsce@1.87.1

COPY . /app
RUN chown -R starkware:starkware /app

USER starkware

# Build the cairo-lang package.
RUN bazel build //src/starkware/cairo/lang:create_cairo_lang_package_zip
Expand All @@ -30,7 +33,6 @@ RUN src/starkware/cairo/lang/package_test/run_test.sh

# Build the Visual Studio Code extension.
WORKDIR /app/src/starkware/cairo/lang/ide/vscode-cairo
RUN npm install -g vsce@1.87.1
RUN npm install
RUN vsce package

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We recommend starting from [Setting up the environment](https://cairo-lang.org/d
# Installation instructions

You should be able to download the python package zip file directly from
[github](https://github.com/starkware-libs/cairo-lang/releases/tag/v0.12.3)
[github](https://github.com/starkware-libs/cairo-lang/releases/tag/v0.13.0)
and install it using ``pip``.
See [Setting up the environment](https://cairo-lang.org/docs/quickstart.html).

Expand Down 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.12.3.zip .
> docker cp ${container_id}:/app/cairo-lang-0.13.0.zip .
> docker rm -v ${container_id}
```

24 changes: 14 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,24 @@ http_file(

http_archive(
name = "rules_python",
sha256 = "a3a6e99f497be089f81ec082882e40246bfd435f52f4e82f37e89449b04573f6",
strip_prefix = "rules_python-0.10.2",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.10.2.tar.gz",
patch_args = ["-p1"],
patches = ["//bazel_utils/patches:rules_python.patch"],
sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b",
strip_prefix = "rules_python-0.26.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

http_archive(
name = CAIRO_COMPILER_ARCHIVE,
build_file = get_from_cairo_lang(
"//src/starkware/starknet/compiler/v1:BUILD." + CAIRO_COMPILER_ARCHIVE,
),
strip_prefix = "cairo",
url = "https://github.com/starkware-libs/cairo/releases/download/v2.1.0/release-x86_64-unknown-linux-musl.tar.gz",
url = "https://github.com/starkware-libs/cairo/releases/download/v2.4.0-rc0/release-x86_64-unknown-linux-musl.tar.gz",
)

http_archive(
Expand All @@ -59,8 +65,6 @@ http_archive(

register_toolchains("//bazel_utils/python:py_stub_toolchain")

load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python3",
python_version = "3.9",
Expand All @@ -74,8 +78,8 @@ load("@rules_python//python:pip.bzl", "pip_parse")
pip_parse(
name = "cpython_reqs",
extra_pip_args = [
"--retries=10",
"--timeout=300",
"--retries=100",
"--timeout=3000",
],
python_interpreter_target = interpreter,
requirements_lock = "//scripts:requirements.txt",
Expand All @@ -88,8 +92,8 @@ install_deps()
pip_parse(
name = "pypy_reqs",
extra_pip_args = [
"--retries=10",
"--timeout=300",
"--retries=100",
"--timeout=3000",
],
python_interpreter_target = "@pypy3.9//:bin/pypy3",
requirements_lock = "//scripts:pypy-requirements.txt",
Expand Down
13 changes: 12 additions & 1 deletion bazel_utils/gen_python_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

from argparse import ArgumentParser

SUPPRESS_SIGINT_CODE = """\
import signal
signal.signal(signal.SIGINT, signal.SIG_IGN)
"""


def main():
parser = ArgumentParser(description="Generates an executable file for py_exe().")
Expand All @@ -25,6 +30,12 @@ def main():
help="Path for the output of the shell binary that wraps the py_binary",
required=True,
)
parser.add_argument(
"--suppress_sigint",
help="Suppress SIGINT in the shell binary.",
required=False,
action="store_true",
)
args = parser.parse_args()

with open(args.output_py, "w") as f:
Expand All @@ -33,7 +44,7 @@ def main():
import os
import subprocess
import sys
{SUPPRESS_SIGINT_CODE if args.suppress_sigint else ""}
cmd = [
sys.executable, "-u", "-s", "-m", {args.module!r}
] + sys.argv[1:]
Expand Down
Empty file added bazel_utils/patches/BUILD
Empty file.
12 changes: 12 additions & 0 deletions bazel_utils/patches/rules_python.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/python/pip_install/repositories.bzl b/python/pip_install/repositories.bzl
index b322a70..14f2e30 100644
--- a/python/pip_install/repositories.bzl
+++ b/python/pip_install/repositories.bzl
@@ -116,6 +116,7 @@ py_library(
"**/*.pyc.*", # During pyc creation, temp files named *.pyc.NNN are created
"**/* *",
"**/*.dist-info/RECORD",
+ "**/__pycache__/**",
"BUILD",
"WORKSPACE",
]),
5 changes: 4 additions & 1 deletion bazel_utils/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _py_wrappers_impl(ctx):
ctx.attr.py_exe_name,
"--module",
ctx.attr.module,
],
] + (["--suppress_sigint"] if ctx.attr.suppress_sigint else []),
)

_py_wrappers = rule(
Expand All @@ -102,6 +102,7 @@ _py_wrappers = rule(
),
"py_exe_name": attr.string(),
"module": attr.string(),
"suppress_sigint": attr.bool(default = False),
},
)

Expand All @@ -115,6 +116,7 @@ def py_exe(
env = {},
is_pypy = False,
legacy_create_init = False,
suppress_sigint = False,
**kwargs):
py_exe_module = name + "_exe.py"
sh_file = name + "_exe.sh"
Expand All @@ -124,6 +126,7 @@ def py_exe(
name = name + "_wrappers",
py_exe_name = name,
module = module,
suppress_sigint = suppress_sigint,
py_binary_name = py_binary_name,
py_wrapper = py_exe_module,
sh_wrapper = sh_file,
Expand Down
4 changes: 3 additions & 1 deletion docker_common_deps.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
curl -L -o /tmp/bazel_install.sh https://github.com/bazelbuild/bazel/releases/download/5.2.0/bazel-5.2.0-installer-linux-x86_64.sh
curl -L -o /tmp/bazel_install.sh https://github.com/bazelbuild/bazel/releases/download/5.4.0/bazel-5.4.0-installer-linux-x86_64.sh
chmod +x /tmp/bazel_install.sh
/tmp/bazel_install.sh

groupadd -g 1234 starkware && useradd -m starkware -u 1234 -g 1234
2 changes: 1 addition & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pytest-asyncio==0.21.0
pytest-profiling==1.7.0
pytest-xdist==3.3.1
pytest==7.3.1
PyYAML==6.0
PyYAML==6.0.1
regex==2023.3.23
requests==2.28.2
rlp==3.0.0
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 @@ -129,7 +129,7 @@ def main():

# Initialize Ethereum account for on-chain transaction sending.
operator_private_key_str = input(
"Please enter an operator private key, " "or press Enter to generate a new private key: "
"Please enter an operator private key, or press Enter to generate a new private key: "
)
try:
operator_private_key = int(operator_private_key_str, 16)
Expand Down
4 changes: 2 additions & 2 deletions src/services/everest/api/gateway/set_config_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
@marshmallow_dataclass.dataclass
class AlternativeEndpointSettingRequest(ValidatedMarshmallowDataclass):
"""
This type of request is allowed only in setups that support dynamically configuring the
endpoint for alternative transactions.
In order to use this request, StarkWare must configure your setup to support dynamically
configuring the endpoint for alternative transactions.
AlternativeEndpointSettingRequest is sent from the client to the gateway
when the configuration of the alternative transaction request endpoint is changed.
Expand Down
24 changes: 5 additions & 19 deletions src/services/everest/definitions/fields.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import dataclasses
import random
import string
from typing import Any, ClassVar, Dict, List, Optional
from typing import Any, Dict, List, Optional, Type

import marshmallow.fields as mfields
import marshmallow.utils
from web3.types import ChecksumAddress

from services.everest.definitions import constants
Expand All @@ -27,10 +26,8 @@ class EthAddressTypeField(ValidatedField[str]):
A field representation of an Ethereum address.
"""

error_message: ClassVar[str] = "{name} {value} is out of range / not checksummed."

def __init__(self, name, error_code):
super().__init__(name, error_code)
def error_message(self, value: str) -> str:
return f"{self.name} {value} is out of range / not checksummed."

# Randomization.
def get_random_value(self, random_object: Optional[random.Random] = None) -> str:
Expand All @@ -50,27 +47,16 @@ def get_invalid_values(self) -> List[str]:
self.get_random_value() + "0", # type: ignore # Too long address.
]

def format_invalid_value_error_message(self, value: str, name: Optional[str] = None) -> str:
return self.error_message.format(
name=self.name if name is None else name,
value=value,
)

# Serialization.
def get_marshmallow_field(
self, required: bool = True, load_default: Any = marshmallow.utils.missing
) -> mfields.Field:
return mfields.String(required=required, load_default=load_default)
def get_marshmallow_type(self) -> Type[mfields.Field]:
return mfields.String

def convert_valid_to_checksum(self, value: str) -> ChecksumAddress:
self.validate(value=value)
# This won't change value. It will only allow the function to return value as return
# ChecksumAddress.
return Web3.to_checksum_address(value=value) # type: ignore

def format(self, value: str) -> str:
return value


FactRegistryField = EthAddressTypeField(
name="Address of fact registry", error_code=StarkErrorCode.INVALID_CONTRACT_ADDRESS
Expand Down
2 changes: 1 addition & 1 deletion src/services/external_api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ py_library(
visibility = ["//visibility:public"],
deps = [
":services_external_api_utils_lib",
"//src/starkware/starkware_utils:starkware_dataclasses_field_utils_lib",
"//src/starkware/python:starkware_python_utils_lib",
"//src/starkware/starkware_utils:starkware_dataclasses_field_utils_lib",
requirement("aiohttp"),
] + SERVICES_EXTERNAL_API_LIB_ADDITIONAL_LIBS,
)
Expand Down
9 changes: 9 additions & 0 deletions src/services/external_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def __init__(
url: str,
certificates_path: Optional[str] = None,
retry_config: Optional[RetryConfig] = None,
request_timeout: Optional[int] = None,
headers: Optional[Mapping[str, str]] = None,
):
self.url = url
self.ssl_context: Optional[ssl.SSLContext] = None
Expand All @@ -123,6 +125,12 @@ def __init__(
self.retry_config.n_retries > 0 or self.retry_config.n_retries == -1
), "RetryConfig n_retries parameter value must be either a positive int or equals to -1."

self.request_kwargs: Dict[str, Any] = {}
if request_timeout is not None:
self.request_kwargs["timeout"] = request_timeout
if headers is not None:
self.request_kwargs["headers"] = headers

if certificates_path is not None:
self.ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
self.ssl_context.verify_mode = ssl.CERT_REQUIRED
Expand Down Expand Up @@ -190,6 +198,7 @@ async def _send_request(
url=url,
data=self._prepare_data(data=data),
params=params,
**self.request_kwargs,
) as response:
return await self._parse_response(
request_url=url,
Expand Down
2 changes: 1 addition & 1 deletion src/services/external_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def join_routes(route_list: List[str]) -> str:
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)
return "" if len(route_list) == 0 else "/" + "/".join(s.strip("/") for s in route_list)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from starkware.cairo.builtin_selection.inner_select_builtins import inner_select_builtins
from starkware.cairo.builtin_selection.select_input_builtins import select_input_builtins
from starkware.cairo.builtin_selection.validate_builtins import validate_builtins
from starkware.cairo.common.builtin_poseidon.poseidon import PoseidonBuiltin, poseidon_hash_many
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.hash_chain import hash_chain
from starkware.cairo.common.registers import get_ap, get_fp_and_pc
Expand Down Expand Up @@ -34,14 +35,34 @@ struct BuiltinData {
poseidon: felt,
}

// Computes the hash of a program.
// Arguments:
// * program_data_ptr - the pointer to the program to be hashed.
// * use_poseidon - a flag that determines whether the hashing will use Poseidon hash.
// Return values:
// * hash - the computed program hash.
func compute_program_hash{pedersen_ptr: HashBuiltin*, poseidon_ptr: PoseidonBuiltin*}(
program_data_ptr: felt*, use_poseidon: felt
) -> (hash: felt) {
if (use_poseidon == 1) {
let (hash) = poseidon_hash_many{poseidon_ptr=poseidon_ptr}(
n=program_data_ptr[0], elements=&program_data_ptr[1]
);
return (hash=hash);
} else {
let (hash) = hash_chain{hash_ptr=pedersen_ptr}(data_ptr=program_data_ptr);
return (hash=hash);
}
}

// Executes a single task.
// The task is passed in the 'task' hint variable.
// Outputs of the task are prefixed by:
// a. Output size (including this prefix)
// b. hash_chain(ProgramHeader || task.program.data) where ProgramHeader is defined below.
// The function returns a pointer to the updated builtin pointers after executing the task.
func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
builtin_encodings: BuiltinData*, builtin_instance_sizes: BuiltinData*
builtin_encodings: BuiltinData*, builtin_instance_sizes: BuiltinData*, use_poseidon: felt
) {
// Allocate memory for local variables.
alloc_locals;
Expand Down Expand Up @@ -73,7 +94,13 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}(

// Call hash_chain, to verify the program hash.
let pedersen_ptr = cast(input_builtin_ptrs.pedersen, HashBuiltin*);
let (hash) = hash_chain{hash_ptr=pedersen_ptr}(data_ptr=program_data_ptr);
let poseidon_ptr = cast(input_builtin_ptrs.poseidon, PoseidonBuiltin*);
with pedersen_ptr, poseidon_ptr {
let (hash) = compute_program_hash(
program_data_ptr=program_data_ptr, use_poseidon=use_poseidon
);
}

// Write hash_chain result to output_ptr + 1.
assert [output_ptr + 1] = hash;
%{
Expand Down Expand Up @@ -106,7 +133,7 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
bitwise=input_builtin_ptrs.bitwise,
ec_op=input_builtin_ptrs.ec_op,
keccak=input_builtin_ptrs.keccak,
poseidon=input_builtin_ptrs.poseidon,
poseidon=cast(poseidon_ptr, felt),
);

// Call select_input_builtins to get the relevant input builtin pointers for the task.
Expand Down
Loading

0 comments on commit 351e92a

Please sign in to comment.