Skip to content

Commit

Permalink
Cairo v0.12.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed Aug 7, 2023
1 parent cc86dfc commit 0614f26
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 57 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
FROM ciimage/python:3.9
RUN sed -i -e 's|http://archive\.ubuntu\.com/ubuntu/|mirror://mirrors.ubuntu.com/mirrors.txt|' /etc/apt/sources.list
FROM ciimage/python:3.9-ci

RUN curl -sL https://starkware-third-party.s3.us-east-2.amazonaws.com/build_tools/node-v18.17.0-linux-x64.tar.xz -o node-v18.17.0-linux-x64.tar.xz && \
tar -xf node-v18.17.0-linux-x64.tar.xz -C /opt/ && \
rm -f node-v18.17.0-linux-x64.tar.xz

ENV PATH="${PATH}:/opt/node-v18.17.0-linux-x64/bin"

COPY ./docker_common_deps.sh /app/
WORKDIR /app/
RUN ./docker_common_deps.sh
RUN apt-get install -y git libgmp3-dev python3-pip python3.9-venv python3.9-dev npm

# 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 Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ http_archive(
"//src/starkware/starknet/compiler/v1:BUILD." + CAIRO_COMPILER_ARCHIVE,
),
strip_prefix = "cairo",
url = "https://github.com/starkware-libs/cairo/releases/download/v2.1.0-rc0/release-x86_64-unknown-linux-musl.tar.gz",
url = "https://github.com/starkware-libs/cairo/releases/download/v2.1.0/release-x86_64-unknown-linux-musl.tar.gz",
)

http_archive(
Expand Down
2 changes: 1 addition & 1 deletion bazel_utils/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def pytest_test(
] + ["--color=yes", "--junitxml=$$XML_OUTPUT_FILE", "--strict-markers"] + args,
python_version = "PY3",
srcs_version = "PY3",
deps = deps + [requirement("pytest"), "//:starkware"],
deps = deps + [requirement("pytest"), requirement("pytest_profiling"), requirement("pytest_xdist"), "//:starkware"],
data = data,
timeout = timeout,
legacy_create_init = legacy_create_init,
Expand Down
9 changes: 0 additions & 9 deletions docker_common_deps.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Install Clang
apt-get update
apt-get install -y libstdc++-8-dev libc6-dbg
apt-get install -y clang-12 clang-format-12 clang-tidy-6.0 libclang-12-dev llvm-12 g++-7
ln -sf /usr/bin/clang++-12 /usr/bin/clang++
ln -sf /usr/bin/clang-12 /usr/bin/clang

# Install bazel
apt-get install unzip -y
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
chmod +x /tmp/bazel_install.sh
/tmp/bazel_install.sh
6 changes: 5 additions & 1 deletion scripts/requirements-gen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ aiohttp
cachetools
ecdsa
eth-hash[pycryptodome]
execnet
fastecdsa
frozendict
gprof2dot
lark
marshmallow-dataclass>=7.1.0
marshmallow-enum
Expand All @@ -15,7 +17,9 @@ pipdeptree
prometheus-client
pytest
pytest-asyncio
pytest-profiling
pytest-xdist
PyYAML
typeguard<3.0.0
sympy
typeguard<3.0.0
web3
10 changes: 7 additions & 3 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ eth-rlp==0.3.0
eth-typing==3.3.0
eth-utils==2.1.0
exceptiongroup==1.1.1
execnet==2.0.2
fastecdsa==2.3.0
frozendict==2.3.7
frozenlist==1.3.3
gprof2dot==2022.7.29
hexbytes==0.3.0
idna==3.4
iniconfig==2.0.0
jsonschema==4.17.3
lark==1.1.5
lru-dict==1.1.8
marshmallow==3.19.0
marshmallow-dataclass==8.5.12
marshmallow-enum==1.5.1
marshmallow-oneofschema==3.0.1
marshmallow==3.19.0
mpmath==1.3.0
multidict==6.0.4
mypy-extensions==1.0.0
Expand All @@ -43,8 +45,10 @@ prometheus-client==0.16.0
protobuf==4.22.3
pycryptodome==3.17
pyrsistent==0.19.3
pytest==7.3.1
pytest-asyncio==0.21.0
pytest-profiling==1.7.0
pytest-xdist==3.3.1
pytest==7.3.1
PyYAML==6.0
regex==2023.3.23
requests==2.28.2
Expand All @@ -55,8 +59,8 @@ sympy==1.11.1
tomli==2.0.1
toolz==0.12.0
typeguard==2.13.3
typing-inspect==0.8.0
typing_extensions==4.5.0
typing-inspect==0.8.0
urllib3==1.26.15
web3==6.2.0
websockets==11.0.2
Expand Down
3 changes: 3 additions & 0 deletions src/starkware/cairo/common/cairo_secp/signature.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func public_key_point_to_eth_address{
}

// Returns 1 if (x, y) is a point on the secp256k1 curve and 0 otherwise.
//
// Prover assumption: the limbs of x and y are in the range (-2**87.49, 2**87.49).
// Soundness assumption: the limbs of x and y are in the range (-2**106.99, 2**106.99).
func is_on_curve{range_check_ptr}(x: BigInt3, y: BigInt3) -> (res: felt) {
let (x_square: UnreducedBigInt3) = unreduced_sqr(x);
let (x_square_reduced: BigInt3) = reduce(x_square);
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/cairo/lang/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.1a0
0.12.1
4 changes: 3 additions & 1 deletion src/starkware/starknet/compiler/v1/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def compile_cairo_to_sierra(
cairo_path: str,
allowed_libfuncs_list_name: Optional[str] = None,
allowed_libfuncs_list_file: Optional[str] = None,
single_file: bool = True,
) -> JsonObject:
"""
Compiles a Starknet Cairo 1.0 contract; returns the resulting Sierra as json.
Expand All @@ -104,7 +105,8 @@ def compile_cairo_to_sierra(
allowed_libfuncs_list_name=allowed_libfuncs_list_name,
allowed_libfuncs_list_file=allowed_libfuncs_list_file,
)
additional_args += ["--single-file"]
if single_file:
additional_args += ["--single-file"]

command = [STARKNET_COMPILE_EXE, cairo_path, *additional_args]
return run_compile_command(command=command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ func contract_call_helper{
let syscall_ptr = syscall_ptr + ResponseHeader.SIZE;

// Write the response header.
assert [response_header] = ResponseHeader(gas=remaining_gas, failure_flag=0);
with_attr error_message("Predicted gas costs are inconsistent with the actual execution.") {
assert [response_header] = ResponseHeader(gas=remaining_gas, failure_flag=0);
}

let response = cast(syscall_ptr, CallContractResponse*);
// Advance syscall pointer to the next syscall.
Expand Down
2 changes: 2 additions & 0 deletions src/starkware/starknet/definitions/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def from_raw_code(cls, code: str) -> "StarknetErrorCode":
# Errors that are raised by the gateways and caused by wrong usage of the user.

common_error_codes: List[ErrorCode] = [
# Client connection errors.
StarkErrorCode.CONNECTION_RESET_ERROR,
# Raw builtin exceptions from pre/post_load/dump are wrapped with StarkException and this code.
StarkErrorCode.MALFORMED_REQUEST,
StarkErrorCode.OUT_OF_RANGE_FIELD_ELEMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,36 +353,6 @@ def __post_init__(self):
self.block_hash is not None
), "Transactions accepted on L1 must have a block hash."

@marshmallow.pre_load
def _fill_missing_tx_statuses(self, data, **kwargs):
finality_status_key_name = "finality_status"
execution_status_key_name = "execution_status"

# If True, This object was serialized before finality_status was added.
if finality_status_key_name not in data:
deprecated_status = TransactionStatus[data["status"]]

# REVERTED status and execution status did not exist before finality_status was added.
assert deprecated_status is not TransactionStatus.REVERTED
assert "revert_reason" not in data
assert execution_status_key_name not in data

if deprecated_status.was_executed:
data[finality_status_key_name] = deprecated_status.name
data[execution_status_key_name] = ExecutionStatus.SUCCEEDED.name
elif deprecated_status is TransactionStatus.REJECTED:
data[finality_status_key_name] = FinalityStatus.RECEIVED.name
data[execution_status_key_name] = ExecutionStatus.REJECTED.name
else:
assert deprecated_status in (
TransactionStatus.RECEIVED,
TransactionStatus.NOT_RECEIVED,
)
data[finality_status_key_name] = deprecated_status.name
data[execution_status_key_name] = None

return data


@marshmallow_dataclass.dataclass(frozen=True)
class TransactionSpecificInfo(ValidatedResponseObject):
Expand Down Expand Up @@ -1118,6 +1088,22 @@ def __post_init__(self):
field is not None for field in created_block_fields
), "Block hash, block number, state_root must appear in a created block."

@marshmallow.pre_load
def fill_missing_execution_statuses(self, data: Dict[str, Any], **kwargs) -> Dict[str, Any]:
have_execution_status = [
"execution_status" in tx_receipt for tx_receipt in data["transaction_receipts"]
]
if all(have_execution_status):
return data

assert not any(
have_execution_status
), "Either all transaction receipts should have execution statuses, or none should."
for tx_receipt in data["transaction_receipts"]:
tx_receipt["execution_status"] = ExecutionStatus.SUCCEEDED.name

return data


@marshmallow_dataclass.dataclass(frozen=True)
class FeeEstimationInfo(ValidatedResponseObject):
Expand Down
6 changes: 3 additions & 3 deletions src/starkware/starknet/starknet_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ def _starknet_contract_impl(ctx):
else:
outs = [compiled_sierra_name]

single_file_flag = ["--single-file"] if ctx.file.main.extension == "cairo" else []
_compile_internal(
ctx = ctx,
srcs_list = srcs_list,
main = ctx.file.main,
compiled_file_name = compiled_sierra_name,
compile_exe = compile_cairo_to_sierra_exe,
outs = [compiled_sierra_name],
cairoopts = ctx.attr.cairoopts + single_file_flag,
cairoopts = ctx.attr.cairoopts,
progress_message = "Compiling cairo to sierra %s..." % ctx.file.main.path,
)

Expand Down Expand Up @@ -76,6 +75,7 @@ def _compile_internal(
outs,
cairoopts,
progress_message):
single_file_flag = ["--single-file"] if main.extension == "cairo" else []
ctx.actions.run(
executable = compile_exe,
# https://github.com/starkware-libs/cairo/blob/main/crates/cairo-lang-runner/README.md
Expand All @@ -85,7 +85,7 @@ def _compile_internal(
arguments = [
main.path,
compiled_file_name.path,
] + cairoopts,
] + cairoopts + single_file_flag,
inputs = srcs_list + [compile_exe] + ctx.files.compiler_data,
outputs = outs,
progress_message = progress_message,
Expand Down
4 changes: 1 addition & 3 deletions src/starkware/starkware_utils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ py_library(
"error_handling.py",
],
visibility = ["//visibility:public"],
deps = [
requirement("marshmallow"),
],
deps = [requirement("marshmallow")],
)

py_library(
Expand Down
2 changes: 2 additions & 0 deletions src/starkware/starkware_utils/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class StarkErrorCode(ErrorCode):
BATCH_NOT_READY = auto()
#: Connection error with the node (for example, Infura too many requests).
CONNECTION_ERROR = auto()
#: Connection error with a client.
CONNECTION_RESET_ERROR = auto()
#: Duplicate order.
DUPLICATE_ORDER = auto()
#: Multi-Transaction with zero transactions.
Expand Down

0 comments on commit 0614f26

Please sign in to comment.