-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'drand-voting' into drand-voting-app
- Loading branch information
Showing
168 changed files
with
63,488 additions
and
110,608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import asyncio | ||
import os | ||
from enum import Enum | ||
from pathlib import Path | ||
|
||
import dotenv | ||
from starknet_py.net.account.account import Account | ||
from starknet_py.net.full_node_client import FullNodeClient | ||
from starknet_py.net.models import StarknetChainId | ||
from starknet_py.net.signer.stark_curve_signer import KeyPair | ||
|
||
from garaga.hints.io import to_int | ||
from garaga.starknet.cli.smart_contract_project import SmartContractProject | ||
|
||
dotenv.load_dotenv(".secrets") | ||
|
||
|
||
class Network(Enum): | ||
SEPOLIA = "sepolia" | ||
MAINNET = "mainnet" | ||
|
||
def to_starknet_chain_id(self): | ||
if self == Network.SEPOLIA: | ||
return StarknetChainId.SEPOLIA | ||
elif self == Network.MAINNET: | ||
return StarknetChainId.MAINNET | ||
else: | ||
raise ValueError(f"Unknown network: {self}") | ||
|
||
|
||
class Fee(Enum): | ||
ETH = "eth" | ||
STRK = "strk" | ||
|
||
|
||
def get_account(network: Network): | ||
rpc_url = os.getenv(f"{network.value.upper()}_RPC_URL") | ||
account_address = os.getenv(f"{network.value.upper()}_ACCOUNT_ADDRESS") | ||
account_private_key = os.getenv(f"{network.value.upper()}_ACCOUNT_PRIVATE_KEY") | ||
|
||
client = FullNodeClient(node_url=rpc_url) | ||
account = Account( | ||
address=account_address, | ||
client=client, | ||
key_pair=KeyPair.from_private_key(to_int(account_private_key)), | ||
chain=network.to_starknet_chain_id(), | ||
) | ||
return account | ||
|
||
|
||
async def declare_contract_from_path(path: Path, network: Network, fee: Fee): | ||
contract = SmartContractProject(smart_contract_folder=path) | ||
account = get_account(network) | ||
await contract.declare_class_hash(account=account, fee=fee.value) | ||
|
||
|
||
async def declare_contract_from_path_both_networks(path: Path, fee: Fee): | ||
await declare_contract_from_path(path, Network.SEPOLIA, fee) | ||
await declare_contract_from_path(path, Network.MAINNET, fee) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run( | ||
declare_contract_from_path_both_networks( | ||
Path("src/contracts/universal_ecip"), Fee.STRK | ||
) | ||
) | ||
asyncio.run( | ||
declare_contract_from_path_both_networks( | ||
Path("src/contracts/drand_quicknet"), Fee.STRK | ||
) | ||
) | ||
|
||
asyncio.run( | ||
declare_contract_from_path_both_networks( | ||
Path("src/contracts/risc0_verifier_bn254"), Fee.STRK | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import ast | ||
import asyncio | ||
import sys | ||
from enum import Enum | ||
from pathlib import Path | ||
|
||
from starknet_py.net.full_node_client import FullNodeClient | ||
|
||
import garaga.hints.io as io | ||
from garaga.starknet.cli.smart_contract_project import SmartContractProject | ||
|
||
|
||
class Network(Enum): | ||
SEPOLIA = "sepolia" | ||
MAINNET = "mainnet" | ||
|
||
|
||
def get_class_hash_from_generator(): | ||
try: | ||
with open( | ||
"hydra/garaga/starknet/groth16_contract_generator/generator.py", "r" | ||
) as f: | ||
tree = ast.parse(f.read()) | ||
for node in ast.walk(tree): | ||
if isinstance(node, ast.Assign) and len(node.targets) == 1: | ||
if getattr(node.targets[0], "id", None) == "ECIP_OPS_CLASS_HASH": | ||
return hex(node.value.value) | ||
raise ValueError("ECIP_OPS_CLASS_HASH not found in generator.py") | ||
except Exception as e: | ||
print(f"Error parsing generator.py: {str(e)}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
async def verify_network(network: Network, class_hash: str): | ||
class_hash = io.to_hex_str(class_hash) | ||
print(f"\nVerifying class hash {class_hash} on {network.value}...") | ||
client = FullNodeClient(f"https://free-rpc.nethermind.io/{network.value}-juno") | ||
try: | ||
result = await client.get_class_by_hash(class_hash) | ||
if not result: | ||
print(f"Error: Contract not declared on {network.value}", file=sys.stderr) | ||
sys.exit(1) | ||
print(f"✓ Contract verified on {network.value}") | ||
except Exception as e: | ||
print(f"Error checking {network.value}: {str(e)}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
async def verify_ecip_contract(): | ||
class_hash = get_class_hash_from_generator() | ||
print(f"Verifying ECIP contract using class hash: {class_hash}") | ||
|
||
await verify_network(Network.SEPOLIA, class_hash) | ||
await verify_network(Network.MAINNET, class_hash) | ||
|
||
print("\n✓ Contract verified on both networks") | ||
|
||
|
||
async def verify_contract_from_path(path: Path): | ||
contract = SmartContractProject(smart_contract_folder=path) | ||
class_hash = contract.get_sierra_class_hash() | ||
print(f"Verifying contract {path} with class hash {io.to_hex_str(class_hash)}") | ||
await verify_network(Network.SEPOLIA, class_hash) | ||
await verify_network(Network.MAINNET, class_hash) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(verify_ecip_contract()) | ||
asyncio.run(verify_contract_from_path(Path("src/contracts/drand_quicknet"))) | ||
asyncio.run(verify_contract_from_path(Path("src/contracts/risc0_verifier_bn254"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.