Skip to content

Commit

Permalink
Cairo v0.13.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 committed Mar 5, 2024
1 parent ab6d079 commit efa9648
Show file tree
Hide file tree
Showing 55 changed files with 423 additions and 359 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 vsce@1.87.1
RUN npm install -g --unsafe-perm ganache@7.9.0 vsce@1.87.1

COPY . /app
RUN chown -R starkware:starkware /app
Expand Down
10 changes: 9 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ http_file(
],
)

http_file(
name = "solc-0.8.24",
downloaded_file_path = "solc-0.8.24",
executable = True,
sha256 = "fb03a29a517452b9f12bcf459ef37d0a543765bb3bbc911e70a87d6a37c30d5f",
urls = ["https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.8.24+commit.e11b9ed9"],
)

http_archive(
name = "rules_python",
patch_args = ["-p1"],
Expand All @@ -52,7 +60,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.6.0-rc.0/release-x86_64-unknown-linux-musl.tar.gz",
url = "https://github.com/starkware-libs/cairo/releases/download/v2.6.0/release-x86_64-unknown-linux-musl.tar.gz",
)

http_archive(
Expand Down
5 changes: 5 additions & 0 deletions bazel_utils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ sh_binary(
srcs = ["@solc-0.6.12//file"],
)

sh_binary(
name = "solc-0.8.24",
srcs = ["@solc-0.8.24//file"],
)

py_library(
name = "default_extract_artifacts_lib",
srcs = [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"description": "",
"dependencies": {
"ganache": "7.4.4"
"ganache": "7.9.0"
},
"devDependencies": {},
"author": "",
Expand Down
8 changes: 4 additions & 4 deletions src/starkware/cairo/common/find_element.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from starkware.cairo.common.math import assert_le, assert_le_felt, assert_nn_le
from starkware.cairo.common.math import assert_le, assert_le_felt, assert_lt_felt, assert_nn_le

const FIND_ELEMENT_RANGE_CHECK_USAGE = 2;

Expand Down Expand Up @@ -67,7 +67,7 @@ func find_element{range_check_ptr}(array_ptr: felt*, elm_size, n_elms, key) -> (
// Given an array sorted by its first field, returns the pointer to the first element in the array
// whose first field is at least key. If no such item exists, returns a pointer to the end of the
// array.
// Prover assumption: all the keys (the first field in each item) are in [0, RANGE_CHECK_BOUND).
// Assumption: the array is sorted as unsigned numbers.
func search_sorted_lower{range_check_ptr}(array_ptr: felt*, elm_size, n_elms, key) -> (
elm_ptr: felt*
) {
Expand Down Expand Up @@ -105,7 +105,7 @@ func search_sorted_lower{range_check_ptr}(array_ptr: felt*, elm_size, n_elms, ke
}

if (index != 0) {
assert_le_felt(a=[elm_ptr - elm_size] + 1, b=key);
assert_lt_felt(a=[elm_ptr - elm_size], b=key);
}

return (elm_ptr=elm_ptr);
Expand All @@ -114,7 +114,7 @@ func search_sorted_lower{range_check_ptr}(array_ptr: felt*, elm_size, n_elms, ke
// Given an array sorted by its first field, returns the pointer to the first element in the array
// whose first field is exactly key. If no such item exists, returns an undefined pointer,
// and success=0.
// Prover assumption: all the keys (the first field in each item) are in [0, RANGE_CHECK_BOUND).
// Assumption: the array is sorted as unsigned numbers.
func search_sorted{range_check_ptr}(array_ptr: felt*, elm_size, n_elms, key) -> (
elm_ptr: felt*, success: felt
) {
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.13.1a0
0.13.1
25 changes: 9 additions & 16 deletions src/starkware/cairo/lang/vm/cairo_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,15 @@ def verify_zip_format(cls, zf: zipfile.ZipFile):
), "Invalid list of inner files in the CairoPIE zip."

# Make sure the file sizes are reasonable.
file_size = lambda name: inner_files[name].file_size if name in inner_files else 0
assert (
file_size(cls.METADATA_FILENAME) < cls.MAX_SIZE
), f"Invalid file size for {cls.METADATA_FILENAME}."
assert (
file_size(cls.MEMORY_FILENAME) < cls.MAX_SIZE
), f"Invalid file size for {cls.MEMORY_FILENAME}."
assert (
file_size(cls.ADDITIONAL_DATA_FILENAME) < cls.MAX_SIZE
), f"Invalid file size for {cls.ADDITIONAL_DATA_FILENAME}."
assert (
file_size(cls.EXECUTION_RESOURCES_FILENAME) < 10000
), f"Invalid file size for {cls.EXECUTION_RESOURCES_FILENAME}."
assert (
file_size(cls.VERSION_FILENAME) < 10000
), f"Invalid file size for {cls.VERSION_FILENAME}."
for name, limit in (
(cls.METADATA_FILENAME, cls.MAX_SIZE),
(cls.MEMORY_FILENAME, cls.MAX_SIZE),
(cls.ADDITIONAL_DATA_FILENAME, cls.MAX_SIZE),
(cls.EXECUTION_RESOURCES_FILENAME, 10000),
(cls.VERSION_FILENAME, 10000),
):
size = inner_files[name].file_size if name in inner_files else 0
assert size < limit, f"Invalid file size {size} for {name}; limit is {limit}."

def get_segment(self, segment_info: SegmentInfo):
return self.memory.get_range(
Expand Down
7 changes: 3 additions & 4 deletions src/starkware/cairo/sharp/client_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class ClientLib:
This is a slim wrapper around the SHARP API.
"""

def __init__(self, service_url: str):
def __init__(self, url: str):
"""
service_url is the SHARP url.
"""
self.service_url = service_url
self.url = url

def add_job(self, cairo_pie: CairoPie) -> str:
"""
Expand Down Expand Up @@ -48,13 +48,12 @@ def _send(self, action: str, payload: dict) -> dict:
action: the action to be sent to the SHARP.
payload: action specific parameters.
"""

data = {
"action": action,
"request": payload,
}
http = urllib3.PoolManager()
res = http.request(
method="POST", url=self.service_url, body=json.dumps(data).encode("utf-8")
method="POST", url=f"{self.url}{action}", body=json.dumps(data).encode("utf-8")
)
return json.loads(res.data.decode("utf-8"))
15 changes: 8 additions & 7 deletions src/starkware/cairo/sharp/client_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ class Response:
data: bytes


EXPECTED_URL = "https://some_url/"


def test_add_job(monkeypatch: MonkeyPatch):
expected_url = "some url"
expected_data = {
"action": "add_job",
"request": {"cairo_pie": base64.b64encode(MockCairoPie().serialize()).decode("ascii")},
Expand All @@ -34,35 +36,34 @@ def test_add_job(monkeypatch: MonkeyPatch):
# A mock function enforcing expected scenario.
def check_expected(_, method: str, url: str, body: str):
assert method == "POST"
assert url == expected_url
assert url == EXPECTED_URL + expected_data["action"]
assert json.loads(body) == expected_data
return Response(json.dumps({"cairo_job_key": expected_res}).encode("utf-8"))

monkeypatch.setattr(PoolManager, "request", check_expected)

# Test the scenario.
client = ClientLib(expected_url)
client = ClientLib(url=EXPECTED_URL)
res = client.add_job(MockCairoPie())
assert res == expected_res


def test_get_status(monkeypatch: MonkeyPatch):
expected_url = "some url"
expected_id = "some id"
expected_data = {"action": "get_status", "request": {"cairo_job_key": expected_id}}
expected_res = "the status"

# A mock function enforcing expected scenario.
def check_expected(_, method: str, url: str, body: str):
assert method == "POST"
assert url == expected_url
assert url == EXPECTED_URL + expected_data["action"]
assert json.loads(body) == expected_data
return Response(json.dumps({"status": expected_res}).encode("utf-8"))

monkeypatch.setattr(PoolManager, "request", check_expected)

# Test the scenario.
client = ClientLib(expected_url)
client = ClientLib(url=EXPECTED_URL)
res = client.get_status(expected_id)
assert res == expected_res

Expand All @@ -76,7 +77,7 @@ def check_expected(_, method: str, url: str, body: str):
monkeypatch.setattr(PoolManager, "request", check_expected)

# Test the scenario.
client = ClientLib("")
client = ClientLib(url=EXPECTED_URL)

with pytest.raises(AssertionError, match="Error when sending job to SHARP:"):
client.add_job(MockCairoPie())
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",
"url": "https://testnet.provingservice.io/",
"verifier_address": "0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe",
"steps_limit": 1000000
}
28 changes: 18 additions & 10 deletions src/starkware/cairo/sharp/sharp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ def run_program(self, program: Program, program_input_path: Optional[str]) -> Ca
self.cairo_run_path,
"--layout=all_solidity",
f"--program={program_file.name}",
f"--program_input={program_input_path}"
if program_input_path is not None
else None,
(
f"--program_input={program_input_path}"
if program_input_path is not None
else None
),
f"--cairo_pie_output={cairo_pie_file.name}",
],
)
Expand Down Expand Up @@ -152,7 +154,7 @@ def init_client(bin_dir: str, node_rpc_url: Optional[str] = None) -> SharpClient

# Initialize the SharpClient.
client = SharpClient(
service_client=ClientLib(config["prover_url"]),
service_client=ClientLib(url=config["url"]),
contract_client=FactChecker(
fact_registry_address=config["verifier_address"],
node_rpc_url=node_rpc_url if node_rpc_url is not None else "",
Expand All @@ -167,9 +169,10 @@ def init_client(bin_dir: str, node_rpc_url: Optional[str] = None) -> SharpClient

def submit(args, command_args):
parser = argparse.ArgumentParser(
description="Submits a Cairo job to SHARP. "
"You can provide (1) the source code and the program input OR (2) the compiled program and "
"the program input OR (3) the Cairo PIE."
description=(
"Submits a Cairo job to SHARP. You can provide (1) the source code and the program "
"input OR (2) the compiled program and the program input OR (3) the Cairo PIE."
)
)

parser.add_argument(
Expand Down Expand Up @@ -242,7 +245,10 @@ def is_verified(args, command_args):
)
parser.add_argument("fact", type=str, help="The fact to verify if registered.")
parser.add_argument(
"--node_url", required=True, type=str, help="URL for a Sepolia Ethereum node RPC API."
"--node_url",
required=True,
type=str,
help="URL for a Sepolia Ethereum node RPC API.",
)

parser.parse_args(command_args, namespace=args)
Expand All @@ -266,8 +272,10 @@ def main():
"--bin_dir",
type=str,
default="",
help="The path to a directory that contains the cairo-compile and cairo-run scripts. "
"If not specified, files are assumed to be in the system's PATH.",
help=(
"The path to a directory that contains the cairo-compile and cairo-run scripts. "
"If not specified, files are assumed to be in the system's PATH."
),
)
parser.add_argument(
"--flavor",
Expand Down
24 changes: 21 additions & 3 deletions src/starkware/solidity/components/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ package(default_visibility = ["//visibility:public"])

exports_files(glob(["*.sol"]))

sol_library(
name = "governance_sol",
srcs = [
"Governance.sol",
],
deps = [
"//src/starkware/solidity/interfaces:governance_interface_sol",
],
)

sol_library(
name = "governance_contract_sol",
srcs = [
Expand All @@ -21,13 +31,21 @@ sol_library(
name = "solidity_contracts_components_sol",
srcs = [
"FactRegistry.sol",
"GovernedFinalizable.sol",
"OnchainDataFactTreeEncoder.sol",
],
deps = [
"//src/starkware/solidity/interfaces:governance_interface_sol",
"//src/starkware/solidity/interfaces:solidity_contracts_interfaces_sol",
"//src/starkware/solidity/libraries:common_library_sol",
"//src/starkware/solidity/libraries:named_storage_sol",
],
)

sol_library(
name = "governed_finalizable_sol",
srcs = [
"GovernedFinalizable.sol",
],
deps = [
"//src/starkware/solidity/interfaces:governance_interface_sol",
"//src/starkware/solidity/libraries:named_storage8_sol",
],
)
2 changes: 1 addition & 1 deletion src/starkware/solidity/components/Governance.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

import "../interfaces/MGovernance.sol";

Expand Down
4 changes: 2 additions & 2 deletions src/starkware/solidity/components/GovernedFinalizable.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity ^0.8.0;

import "starkware/solidity/interfaces/MGovernance.sol";
import "starkware/solidity/libraries/NamedStorage.sol";
import "starkware/solidity/libraries/NamedStorage8.sol";

/**
A Governor controlled finalizable contract.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

library OnchainDataFactTreeEncoder {
struct DataAvailabilityFact {
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/solidity/components/Operator.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

import "../interfaces/MOperator.sol";
import "../interfaces/MGovernance.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/solidity/interfaces/BlockDirectCall.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

/*
This contract provides means to block direct call of an external function.
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/solidity/interfaces/ContractInitializer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

/**
Interface for contract initialization.
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/solidity/interfaces/IFactRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

/*
The Fact Registry design pattern is a way to separate cryptographic verification from the
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/solidity/interfaces/Identity.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

interface Identity {
/*
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/solidity/interfaces/MGovernance.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

abstract contract MGovernance {
function _isGovernor(address user) internal view virtual returns (bool);
Expand Down
2 changes: 1 addition & 1 deletion src/starkware/solidity/interfaces/MOperator.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.6.12;
pragma solidity >=0.6.12;

import "./MGovernance.sol";

Expand Down
Loading

0 comments on commit efa9648

Please sign in to comment.