diff --git a/hydra/garaga/starknet/cli/utils.py b/hydra/garaga/starknet/cli/utils.py index 10f858ca..ab363bc4 100644 --- a/hydra/garaga/starknet/cli/utils.py +++ b/hydra/garaga/starknet/cli/utils.py @@ -5,6 +5,7 @@ import shutil import subprocess from enum import Enum +from importlib.metadata import PackageNotFoundError, version import rich from starknet_py.contract import Contract @@ -18,6 +19,15 @@ from garaga.hints.io import to_int +def get_package_version(): + try: + __version__ = version("garaga") + except PackageNotFoundError: + # package is not installed + __version__ = "dev" + return __version__ + + class Network(Enum): SEPOLIA = "sepolia" MAINNET = "mainnet" diff --git a/hydra/garaga/starknet/groth16_contract_generator/generator.py b/hydra/garaga/starknet/groth16_contract_generator/generator.py index 109e3587..29031279 100644 --- a/hydra/garaga/starknet/groth16_contract_generator/generator.py +++ b/hydra/garaga/starknet/groth16_contract_generator/generator.py @@ -5,7 +5,7 @@ from garaga.definitions import CurveID from garaga.modulo_circuit_structs import G2Line, StructArray from garaga.precompiled_circuits.multi_miller_loop import precompute_lines -from garaga.starknet.cli.utils import create_directory +from garaga.starknet.cli.utils import create_directory, get_package_version from garaga.starknet.groth16_contract_generator.parsing_utils import Groth16VerifyingKey ECIP_OPS_CLASS_HASH = 0x2672F1F079CCBAFE1BE4A20A76421B509FCFB406CBF6818563ED812EDAEB3A3 @@ -167,6 +167,9 @@ def gen_groth16_verifier( src_dir = os.path.join(output_folder_path, "src") create_directory(src_dir) + with open(os.path.join(output_folder_path, ".tools-versions"), "w") as f: + f.write("scarb 2.8.2\n") + with open(os.path.join(src_dir, "groth16_verifier_constants.cairo"), "w") as f: f.write(constants_code) @@ -188,13 +191,23 @@ def gen_groth16_verifier( def get_scarb_toml_file(package_name: str, cli_mode: bool): + version = get_package_version() + if version == "dev": + suffix = "" + else: + suffix = ', tag = "v' + version + '"' + if cli_mode: + dep = 'git = "https://github.com/keep-starknet-strange/garaga.git"' + suffix + else: + dep = 'path = "../../"' + return f"""[package] name = "{package_name}" version = "0.1.0" edition = "2024_07" [dependencies] -garaga = {{ {'git = "https://github.com/keep-starknet-strange/garaga.git"' if cli_mode else 'path = "../../"'} }} +garaga = {{ {dep} }} starknet = "2.8.2" [cairo] diff --git a/pyproject.toml b/pyproject.toml index 87f31f86..bc54bc35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ dependencies = [ "python-dotenv", "starknet-py-unbroken==0.24.5" ] +description = "State-of-the-art Elliptic Curve operations and SNARKS verification for Cairo & Starknet 🐺." [project.optional-dependencies] dev = [ diff --git a/src/contracts/groth16_example_bls12_381/.tools-versions b/src/contracts/groth16_example_bls12_381/.tools-versions new file mode 100644 index 00000000..cc60fd62 --- /dev/null +++ b/src/contracts/groth16_example_bls12_381/.tools-versions @@ -0,0 +1 @@ +scarb 2.8.2 diff --git a/src/contracts/groth16_example_bn254/.tools-versions b/src/contracts/groth16_example_bn254/.tools-versions new file mode 100644 index 00000000..cc60fd62 --- /dev/null +++ b/src/contracts/groth16_example_bn254/.tools-versions @@ -0,0 +1 @@ +scarb 2.8.2