From 4f037bff4febde0a91f61f598a4faf61429670d4 Mon Sep 17 00:00:00 2001 From: Geoff Walmsley Date: Fri, 15 Dec 2023 11:49:46 +1300 Subject: [PATCH 1/2] convert blspy to chia_rs, update chia to 2.1.2 --- cdv/cmds/chia_inspect.py | 15 ++++++++++----- cdv/test/__init__.py | 2 +- cdv/util/keys.py | 4 ++-- setup.py | 2 +- tests/cmds/test_inspect.py | 12 ++++++------ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cdv/cmds/chia_inspect.py b/cdv/cmds/chia_inspect.py index 6cedeb5..1987f58 100644 --- a/cdv/cmds/chia_inspect.py +++ b/cdv/cmds/chia_inspect.py @@ -7,7 +7,6 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union import click -from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey from chia.consensus.cost_calculator import NPCResult from chia.consensus.default_constants import DEFAULT_CONSTANTS from chia.full_node.bundle_tools import simple_solution_generator @@ -31,6 +30,7 @@ calculate_synthetic_public_key, calculate_synthetic_secret_key, ) +from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey from cdv.cmds.util import parse_program @@ -161,6 +161,7 @@ def inspect_any_cmd(ctx: click.Context, objects: Tuple[str]): if type(obj) == str: print(f"Could not guess the type of {obj}") elif type(obj) == Coin: # type: ignore[comparison-overlap] + assert isinstance(obj, Coin) # mypy otherwise complains that obj is a str do_inspect_coin_cmd(ctx, [obj]) elif type(obj) == CoinSpend: # type: ignore[comparison-overlap] do_inspect_coin_spend_cmd(ctx, [obj]) @@ -170,11 +171,11 @@ def inspect_any_cmd(ctx: click.Context, objects: Tuple[str]): do_inspect_coin_record_cmd(ctx, [obj]) elif type(obj) == Program: do_inspect_program_cmd(ctx, [obj]) - elif type(obj) == G1Element: + elif type(obj) == G1Element: # type: ignore[comparison-overlap] do_inspect_keys_cmd(ctx, public_key=obj) - elif type(obj) == PrivateKey: + elif type(obj) == PrivateKey: # type: ignore[comparison-overlap] do_inspect_keys_cmd(ctx, secret_key=obj) - elif type(obj) == G2Element: + elif type(obj) == G2Element: # type: ignore[comparison-overlap] print("That's a BLS aggregated signature") # This is more helpful than just printing it back to them @@ -374,7 +375,9 @@ def do_inspect_spend_bundle_cmd( # If this is from the command line and they've specified at lease one spend to parse if kwargs and (len(kwargs["spend"]) > 0): if len(kwargs["aggsig"]) > 0: - sig: G2Element = AugSchemeMPL.aggregate([G2Element(hexstr_to_bytes(sig)) for sig in kwargs["aggsig"]]) + sig: G2Element = AugSchemeMPL.aggregate( + [G2Element.from_bytes(hexstr_to_bytes(sig)) for sig in kwargs["aggsig"]] + ) else: sig = G2Element() spend_bundle_objs: List[SpendBundle] = [ @@ -626,6 +629,7 @@ def do_inspect_keys_cmd(ctx: click.Context, print_results: bool = True, **kwargs if len(kwargs) == 1: if "secret_key" in kwargs: sk = kwargs["secret_key"] + assert sk is not None pk = sk.get_g1() elif "public_key" in kwargs: pk = kwargs["public_key"] @@ -676,6 +680,7 @@ def one_or_zero(value): if case == "auth": list_path = [12381, 8444, 6, 0] if list_path: + assert sk is not None sk = _derive_path(sk, list_path) pk = sk.get_g1() path = "m/" + "/".join([str(e) for e in path]) diff --git a/cdv/test/__init__.py b/cdv/test/__init__.py index 759bbd5..2356fb7 100644 --- a/cdv/test/__init__.py +++ b/cdv/test/__init__.py @@ -6,7 +6,6 @@ from typing import Dict, List, Optional, Tuple, Union import pytimeparse -from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey from chia.clvm.spend_sim import SimClient, SpendSim from chia.consensus.default_constants import DEFAULT_CONSTANTS from chia.types.blockchain_format.coin import Coin @@ -25,6 +24,7 @@ puzzle_for_pk, ) from chia.wallet.sign_coin_spends import sign_coin_spends +from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey from cdv.util.keys import private_key_for_index, public_key_for_index diff --git a/cdv/util/keys.py b/cdv/util/keys.py index bf8e5af..6dfe32b 100644 --- a/cdv/util/keys.py +++ b/cdv/util/keys.py @@ -2,13 +2,13 @@ from typing import Dict, List -from blspy import AugSchemeMPL, BasicSchemeMPL, G1Element, G2Element, PrivateKey from chia.util.hash import std_hash +from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey def secret_exponent_for_index(index: int) -> int: blob = index.to_bytes(32, "big") - hashed_blob = BasicSchemeMPL.key_gen(std_hash(b"foo" + blob)) + hashed_blob = AugSchemeMPL.key_gen(std_hash(b"foo" + blob)) r = int.from_bytes(hashed_blob, "big") return r diff --git a/setup.py b/setup.py index 89564e0..e9d7217 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ "pytest-asyncio", "pytimeparse", "anyio", - "chia-blockchain==2.1.1", + "chia-blockchain==2.1.2", ] dev_dependencies = [ diff --git a/tests/cmds/test_inspect.py b/tests/cmds/test_inspect.py index 6f892d6..1ec8af5 100644 --- a/tests/cmds/test_inspect.py +++ b/tests/cmds/test_inspect.py @@ -347,15 +347,15 @@ def test_programs(self): assert id in result.output def test_keys(self): - mnemonic: str = "chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia chia" # noqa - sk: str = "6e66bc91c04127f1178cb725faf82b55214b5f215b10bd53bf2eb1ee9e76d2cc" - pk: str = "8777e5c4f5b21840eb69d9cc09433655b044a8e80048cd9583bab9a90f4774d2d57c1b19196ae132c9502db5902f3e5d" + mnemonic: str = "spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend spend" # noqa + sk: str = "1ef0ff42df2fdd4472312e033f555c569d18b85ba0d9f1b09ed87b254dc18a8e" + pk: str = "ae6c7589432cb60a00d84fc83971f50a98fd728863d3ceb189300f2f80d6839e9a2e761ef6cdce809caee83a4e73b623" hd_modifier: str = "m/12381/8444/0/0" type_modifier: str = "farmer" # Should be same as above HD Path - farmer_sk: str = "1d4a4c2f2059ac889fe066d1116a0fe5dc3d6aa016645306698968c78e8df916" - synthetic_sk: str = "6963ce75cd541a0b49cc6feb15185675beb513bd5808e744d475ec50cf75b2c0" + farmer_sk: str = "6a97995a8b35c69418ad60152a5e1c9a32d159bcb7c343c5ccf83c71e4df2038" + synthetic_sk: str = "4272b71ba1c628948e308148e92c1a9b24a785d52f604610a436d2088f72d578" ph_modifier: str = "69ae360134b1fae04326e5546f25dc794a19192a1f22a44a46d038e7f0d1ecbb" - modified_synthetic_sk: str = "2dc18bb076849fce06d9c36e59821ff43e8b81068d33fcc5ada3568fb9dcdb7f" + modified_synthetic_sk: str = "405d969856846304eec6b243d810665cb3b7e94b56747b87e8e5597948ba1da6" runner = CliRunner() From 4ac14cf4fd5f2dfc51e8fb7809bf2e3883ecb50f Mon Sep 17 00:00:00 2001 From: Geoff Walmsley Date: Wed, 17 Jan 2024 11:34:19 +1300 Subject: [PATCH 2/2] chia-blockchain 2.1.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e9d7217..45da4d4 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ "pytest-asyncio", "pytimeparse", "anyio", - "chia-blockchain==2.1.2", + "chia-blockchain==2.1.4", ] dev_dependencies = [