From 5f3b23252a04f1714838415e69e318ed8e097c15 Mon Sep 17 00:00:00 2001 From: Michael Zaikin Date: Mon, 2 Dec 2024 10:51:54 +0100 Subject: [PATCH] Simpler CLI command naming, minor docs inconsistencies and deploy_v1 fix (#259) Co-authored-by: feltroid Prime <96737978+feltroidprime@users.noreply.github.com> --- ...erate-and-deploy-your-verifier-contract.md | 34 +++++++-------- ...-proof-and-using-your-deployed-contract.md | 10 ++--- hydra/garaga/starknet/cli/declare.py | 2 +- hydra/garaga/starknet/cli/deploy.py | 3 +- hydra/garaga/starknet/cli/starknet_cli.py | 8 ++-- hydra/garaga/starknet/cli/verify.py | 42 ++++++++++++++----- 6 files changed, 61 insertions(+), 38 deletions(-) diff --git a/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generate-and-deploy-your-verifier-contract.md b/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generate-and-deploy-your-verifier-contract.md index 3b53702e..736ff5e1 100644 --- a/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generate-and-deploy-your-verifier-contract.md +++ b/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generate-and-deploy-your-verifier-contract.md @@ -122,14 +122,14 @@ garaga Once your verifying key is ready, you can use the following command : ``` -garaga gen --system groth16 --vk vk.json +garaga gen --system groth16 --vk vk.json ``` You should see an output like this : ```bash -(venv) :~/garaga-flow garaga gen --system groth16 --vk vk_bls.json -Please enter the name of your project. Press enter for default name. [my_project]: +(venv) :~/garaga-flow garaga gen --system groth16 --vk vk_bls.json +Please enter the name of your project. Press enter for default name. [my_project]: Detected curve: CurveID.BLS12_381 ⠧ Generating Smart Contract project for ProofSystem.Groth16 using vk_bls.json... Done! @@ -301,18 +301,18 @@ MAINNET_ACCOUNT_ADDRESS=0x4 ``` {% endcode %} -Then, you can run the command `garaga declare-project`, which will build the contract and declare it to Starknet. If the class hash is already deployed, it will return it as well. Declaring the contract involves sending all its bytecode and it is quite an expensive operation. Make sure you dapp is properly tested before! +Then, you can run the command `garaga declare`, which will build the contract and declare it to Starknet. If the class hash is already deployed, it will return it as well. Declaring the contract involves sending all its bytecode and it is quite an expensive operation. Make sure you dapp is properly tested before! ```bash - Usage: garaga declare-project [OPTIONS] - - Declare your smart contract to Starknet. Obtain its class hash and a explorer link. - + Usage: garaga declare [OPTIONS] + + Declare your smart contract to Starknet. Obtain its class hash and a explorer link. + ╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --project-path DIRECTORY Path to the Cairo project holding the Scarb.toml file to declare │ -│ [default: /home/felt/PycharmProjects/garaga-flow/my_project/] │ +│ [default: /home/felt/garaga-flow/my_project/] │ │ --env-file FILE Path to the environment file │ -│ [default: /home/felt/PycharmProjects/garaga-flow/my_project/.secrets] │ +│ [default: /home/felt/garaga-flow/my_project/.secrets] │ │ --network [sepolia|mainnet] Starknet network [default: sepolia] │ │ --fee TEXT Fee token type [eth, strk] [default: eth] │ │ --help -h Show this message and exit. │ @@ -320,22 +320,22 @@ Then, you can run the command `garaga declare-project`, which will build the con ``` ```bash -garaga declare-project --project-path my-project/ --env-file .secrets --network sepolia --fee strk +garaga declare --project-path my_project/ --env-file .secrets --network sepolia --fee strk ``` This command will return the class hash, used in the next step.\ \ -Finally, to deploy the contract, a use `garaga deploy-project` : +Finally, to deploy the contract, a use `garaga deploy` : ```bash - Usage: garaga deploy-project [OPTIONS] - - Deploy an instance of a smart contract class hash to Starknet. Obtain its address, the available endpoints and a explorer link. - + Usage: garaga deploy [OPTIONS] + + Deploy an instance of a smart contract class hash to Starknet. Obtain its address, the available endpoints and a explorer link. + ╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ * --class-hash TEXT Contract class hash to deploy. Can be decimal or hex string [default: None] [required] │ │ --env-file FILE Path to the environment file containing rpc, address, private_key │ -│ [default: /home/felt/PycharmProjects/garaga-flow/my_project/.secrets] │ +│ [default: /home/felt/garaga-flow/my_project/.secrets] │ │ --network [sepolia|mainnet] Starknet network [default: sepolia] │ │ --fee TEXT Fee token type [eth, strk] [default: strk] │ │ --help -h Show this message and exit. │ diff --git a/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract.md b/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract.md index 15b04604..6d708048 100644 --- a/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract.md +++ b/docs/gitbook/deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract.md @@ -18,10 +18,10 @@ The Garaga CLI takes care of converting your proof to the correct calldata and c To do this, use the garaga `verify-onchain` command. ```bash - Usage: garaga verify-onchain [OPTIONS] - - Invoke a SNARK verifier on Starknet given a contract address, a proof and a verification key. - + Usage: garaga verify-onchain [OPTIONS] + + Invoke a SNARK verifier on Starknet given a contract address, a proof and a verification key. + ╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ * --system [groth16] Proof system [default: None] [required] │ │ * --contract-address TEXT Starknet contract address [default: None] [required] │ @@ -73,7 +73,7 @@ The command should look like this: {% code overflow="wrap" %} ``` -garaga verify-onchain --system groth16 --address 0x1234... --vk vk.json --proof proof.json --public-inputs public.json --env-file .secrets --network sepolia +garaga verify-onchain --system groth16 --contract-address 0x1234... --vk vk.json --proof proof.json --public-inputs public.json --env-file .secrets --network sepolia ``` {% endcode %} diff --git a/hydra/garaga/starknet/cli/declare.py b/hydra/garaga/starknet/cli/declare.py index 2bd0d753..d4de5a0c 100644 --- a/hydra/garaga/starknet/cli/declare.py +++ b/hydra/garaga/starknet/cli/declare.py @@ -18,7 +18,7 @@ app = typer.Typer() -def declare_project( +def declare( project_path: Annotated[ Path, typer.Option( diff --git a/hydra/garaga/starknet/cli/deploy.py b/hydra/garaga/starknet/cli/deploy.py index 4f89cb48..ccd2eb31 100644 --- a/hydra/garaga/starknet/cli/deploy.py +++ b/hydra/garaga/starknet/cli/deploy.py @@ -18,7 +18,7 @@ app = typer.Typer() -def deploy_project( +def deploy( class_hash: Annotated[ str, typer.Option( @@ -81,6 +81,7 @@ def deploy_project( auto_estimate=True, salt=1, cairo_version=1, + abi=[], ) ) elif fee.lower() == "strk": diff --git a/hydra/garaga/starknet/cli/starknet_cli.py b/hydra/garaga/starknet/cli/starknet_cli.py index b5a9c082..11196805 100644 --- a/hydra/garaga/starknet/cli/starknet_cli.py +++ b/hydra/garaga/starknet/cli/starknet_cli.py @@ -1,7 +1,7 @@ import typer -from garaga.starknet.cli.declare import declare_project -from garaga.starknet.cli.deploy import deploy_project +from garaga.starknet.cli.declare import declare +from garaga.starknet.cli.deploy import deploy from garaga.starknet.cli.gen import gen from garaga.starknet.cli.verify import calldata, verify_onchain @@ -11,8 +11,8 @@ ) app.command(no_args_is_help=True)(gen) -app.command(no_args_is_help=True)(declare_project) -app.command(no_args_is_help=True)(deploy_project) +app.command(no_args_is_help=True)(declare) +app.command(no_args_is_help=True)(deploy) app.command(no_args_is_help=True)(verify_onchain) app.command(no_args_is_help=True)(calldata) diff --git a/hydra/garaga/starknet/cli/verify.py b/hydra/garaga/starknet/cli/verify.py index 7be7906b..ad5ea2cc 100644 --- a/hydra/garaga/starknet/cli/verify.py +++ b/hydra/garaga/starknet/cli/verify.py @@ -9,6 +9,7 @@ from starknet_py.contract import ( ContractFunction, InvokeResult, + PreparedFunctionInvokeV1, PreparedFunctionInvokeV3, ) @@ -16,6 +17,7 @@ from garaga.hints.io import to_int from garaga.starknet.cli.utils import ( Network, + complete_fee, complete_proof_system, get_contract_iff_exists, load_account, @@ -97,6 +99,14 @@ def verify_onchain( case_sensitive=False, ), ] = Network.SEPOLIA.value, + fee: Annotated[ + str, + typer.Option( + help="Fee token type [eth, strk]", + case_sensitive=False, + autocompletion=complete_fee, + ), + ] = "eth", ): """Invoke a SNARK verifier on Starknet given a contract address, a proof and a verification key.""" vk_obj = Groth16VerifyingKey.from_json(vk) @@ -128,16 +138,28 @@ def verify_onchain( vk=vk_obj, proof=proof_obj, ) - prepare_invoke = PreparedFunctionInvokeV3( - to_addr=function_call.contract_data.address, - calldata=calldata, - selector=function_call.get_selector(function_call.name), - l1_resource_bounds=None, - _contract_data=function_call.contract_data, - _client=function_call.client, - _account=function_call.account, - _payload_transformer=function_call._payload_transformer, - ) + if "eth" in fee.lower(): + prepare_invoke = PreparedFunctionInvokeV1( + to_addr=function_call.contract_data.address, + calldata=calldata, + selector=function_call.get_selector(function_call.name), + max_fee=None, + _contract_data=function_call.contract_data, + _client=function_call.client, + _account=function_call.account, + _payload_transformer=function_call._payload_transformer, + ) + elif "strk" in fee.lower(): + prepare_invoke = PreparedFunctionInvokeV3( + to_addr=function_call.contract_data.address, + calldata=calldata, + selector=function_call.get_selector(function_call.name), + l1_resource_bounds=None, + _contract_data=function_call.contract_data, + _client=function_call.client, + _account=function_call.account, + _payload_transformer=function_call._payload_transformer, + ) invoke_result: InvokeResult = asyncio.run(prepare_invoke.invoke(auto_estimate=True))