From 8b52d0abf3ea877d1d6ff04c9031722de604acd4 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 29 Apr 2024 15:15:52 +0200 Subject: [PATCH] make OwnedSpendBundleConditions (and OwnedSpend) expose PublicKey rather than Bytes48 in the agg sig conditions --- Cargo.lock | 1 + crates/chia-consensus/Cargo.toml | 1 + crates/chia-consensus/src/error.rs | 3 + .../src/gen/owned_conditions.rs | 63 ++++++++++--------- tests/run_gen.py | 4 +- tests/test_streamable.py | 56 ++++++++++------- wheel/generate_type_stubs.py | 16 ++--- wheel/python/chia_rs/chia_rs.pyi | 48 +++++++------- wheel/src/api.rs | 2 +- wheel/src/run_generator.rs | 30 ++++----- 10 files changed, 120 insertions(+), 104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c228f7f81..ebfcd5436 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -352,6 +352,7 @@ dependencies = [ name = "chia-consensus" version = "0.7.0" dependencies = [ + "chia-bls 0.7.0", "chia-protocol", "chia-puzzles", "chia-traits 0.7.0", diff --git a/crates/chia-consensus/Cargo.toml b/crates/chia-consensus/Cargo.toml index 7257a7d84..28bfbabf5 100644 --- a/crates/chia-consensus/Cargo.toml +++ b/crates/chia-consensus/Cargo.toml @@ -24,6 +24,7 @@ clvm-traits = { version = "0.7.0", path = "../clvm-traits" } clvm-derive = { version = "0.6.0", path = "../clvm-derive" } chia-protocol = { version = "0.7.0", path = "../chia-protocol" } chia-puzzles = { version = "0.7.0", path = "../chia-puzzles" } +chia-bls = { version = "0.7.0", path = "../chia-bls" } hex-literal = "0.4.1" thiserror = "1.0.44" diff --git a/crates/chia-consensus/src/error.rs b/crates/chia-consensus/src/error.rs index f36df9763..9eb02820b 100644 --- a/crates/chia-consensus/src/error.rs +++ b/crates/chia-consensus/src/error.rs @@ -20,6 +20,9 @@ pub enum Error { #[error("Validation {0}")] Validation(#[from] ValidationErr), + #[error("BLS {0}")] + Bls(#[from] chia_bls::Error), + #[error("not a singleton mod hash")] NotSingletonModHash, diff --git a/crates/chia-consensus/src/gen/owned_conditions.rs b/crates/chia-consensus/src/gen/owned_conditions.rs index 5f8638ff5..e575defe5 100644 --- a/crates/chia-consensus/src/gen/owned_conditions.rs +++ b/crates/chia-consensus/src/gen/owned_conditions.rs @@ -1,4 +1,6 @@ -use chia_protocol::{Bytes, Bytes32, Bytes48}; +use crate::error::Result; +use chia_bls::PublicKey; +use chia_protocol::{Bytes, Bytes32}; use chia_streamable_macro::Streamable; use clvmr::{Allocator, NodePtr}; @@ -25,13 +27,13 @@ pub struct OwnedSpend { pub birth_height: Option, pub birth_seconds: Option, pub create_coin: Vec<(Bytes32, u64, Option)>, - pub agg_sig_me: Vec<(Bytes48, Bytes)>, - pub agg_sig_parent: Vec<(Bytes48, Bytes)>, - pub agg_sig_puzzle: Vec<(Bytes48, Bytes)>, - pub agg_sig_amount: Vec<(Bytes48, Bytes)>, - pub agg_sig_puzzle_amount: Vec<(Bytes48, Bytes)>, - pub agg_sig_parent_amount: Vec<(Bytes48, Bytes)>, - pub agg_sig_parent_puzzle: Vec<(Bytes48, Bytes)>, + pub agg_sig_me: Vec<(PublicKey, Bytes)>, + pub agg_sig_parent: Vec<(PublicKey, Bytes)>, + pub agg_sig_puzzle: Vec<(PublicKey, Bytes)>, + pub agg_sig_amount: Vec<(PublicKey, Bytes)>, + pub agg_sig_puzzle_amount: Vec<(PublicKey, Bytes)>, + pub agg_sig_parent_amount: Vec<(PublicKey, Bytes)>, + pub agg_sig_parent_puzzle: Vec<(PublicKey, Bytes)>, pub flags: u32, } @@ -53,7 +55,7 @@ pub struct OwnedSpendBundleConditions { // ASSERT_BEFORE_SECONDS_ABSOLUTE conditions pub before_seconds_absolute: Option, // Unsafe Agg Sig conditions (i.e. not tied to the spend generating it) - pub agg_sig_unsafe: Vec<(Bytes48, Bytes)>, + pub agg_sig_unsafe: Vec<(PublicKey, Bytes)>, pub cost: u64, // the sum of all values of all spent coins pub removal_amount: u128, @@ -62,7 +64,7 @@ pub struct OwnedSpendBundleConditions { } impl OwnedSpend { - pub fn from(a: &Allocator, spend: Spend) -> Self { + pub fn from(a: &Allocator, spend: Spend) -> Result { let mut create_coin = Vec::<(Bytes32, u64, Option)>::with_capacity(spend.create_coin.len()); for c in spend.create_coin { @@ -77,7 +79,7 @@ impl OwnedSpend { )); } - Self { + Ok(Self { coin_id: *spend.coin_id, parent_id: a.atom(spend.parent_id).as_ref().try_into().unwrap(), puzzle_hash: a.atom(spend.puzzle_hash).as_ref().try_into().unwrap(), @@ -89,34 +91,34 @@ impl OwnedSpend { birth_height: spend.birth_height, birth_seconds: spend.birth_seconds, create_coin, - agg_sig_me: convert_agg_sigs(a, &spend.agg_sig_me), - agg_sig_parent: convert_agg_sigs(a, &spend.agg_sig_parent), - agg_sig_puzzle: convert_agg_sigs(a, &spend.agg_sig_puzzle), - agg_sig_amount: convert_agg_sigs(a, &spend.agg_sig_amount), - agg_sig_puzzle_amount: convert_agg_sigs(a, &spend.agg_sig_puzzle_amount), - agg_sig_parent_amount: convert_agg_sigs(a, &spend.agg_sig_parent_amount), - agg_sig_parent_puzzle: convert_agg_sigs(a, &spend.agg_sig_parent_puzzle), + agg_sig_me: convert_agg_sigs(a, &spend.agg_sig_me)?, + agg_sig_parent: convert_agg_sigs(a, &spend.agg_sig_parent)?, + agg_sig_puzzle: convert_agg_sigs(a, &spend.agg_sig_puzzle)?, + agg_sig_amount: convert_agg_sigs(a, &spend.agg_sig_amount)?, + agg_sig_puzzle_amount: convert_agg_sigs(a, &spend.agg_sig_puzzle_amount)?, + agg_sig_parent_amount: convert_agg_sigs(a, &spend.agg_sig_parent_amount)?, + agg_sig_parent_puzzle: convert_agg_sigs(a, &spend.agg_sig_parent_puzzle)?, flags: spend.flags, - } + }) } } impl OwnedSpendBundleConditions { - pub fn from(a: &Allocator, sb: SpendBundleConditions) -> Self { + pub fn from(a: &Allocator, sb: SpendBundleConditions) -> Result { let mut spends = Vec::::new(); for s in sb.spends { - spends.push(OwnedSpend::from(a, s)); + spends.push(OwnedSpend::from(a, s)?); } - let mut agg_sigs = Vec::<(Bytes48, Bytes)>::with_capacity(sb.agg_sig_unsafe.len()); + let mut agg_sigs = Vec::<(PublicKey, Bytes)>::with_capacity(sb.agg_sig_unsafe.len()); for (pk, msg) in sb.agg_sig_unsafe { agg_sigs.push(( - a.atom(pk).as_ref().try_into().unwrap(), + PublicKey::from_bytes(a.atom(pk).as_ref().try_into().unwrap())?, a.atom(msg).as_ref().into(), )); } - Self { + Ok(Self { spends, reserve_fee: sb.reserve_fee, height_absolute: sb.height_absolute, @@ -127,17 +129,20 @@ impl OwnedSpendBundleConditions { cost: sb.cost, removal_amount: sb.removal_amount, addition_amount: sb.addition_amount, - } + }) } } -fn convert_agg_sigs(a: &Allocator, agg_sigs: &[(NodePtr, NodePtr)]) -> Vec<(Bytes48, Bytes)> { - let mut ret = Vec::<(Bytes48, Bytes)>::new(); +fn convert_agg_sigs( + a: &Allocator, + agg_sigs: &[(NodePtr, NodePtr)], +) -> Result> { + let mut ret = Vec::<(PublicKey, Bytes)>::new(); for (pk, msg) in agg_sigs { ret.push(( - a.atom(*pk).as_ref().try_into().unwrap(), + PublicKey::from_bytes(a.atom(*pk).as_ref().try_into().unwrap())?, a.atom(*msg).as_ref().into(), )); } - ret + Ok(ret) } diff --git a/tests/run_gen.py b/tests/run_gen.py index fe4b8d3ae..f1c2cf1be 100755 --- a/tests/run_gen.py +++ b/tests/run_gen.py @@ -53,7 +53,7 @@ def print_spend_bundle_conditions(result) -> str: if result.before_height_absolute is not None: ret += f"ASSERT_BEFORE_HEIGHT_ABSOLUTE {result.before_height_absolute}\n" for a in sorted(result.agg_sig_unsafe): - ret += f"AGG_SIG_UNSAFE pk: {a[0].hex()} msg: {a[1].hex()}\n" + ret += f"AGG_SIG_UNSAFE pk: {a[0]} msg: {a[1].hex()}\n" ret += "SPENDS:\n" for s in sorted(result.spends, key=lambda x: x.coin_id): ret += f"- coin id: {s.coin_id.hex()} ph: {s.puzzle_hash.hex()}\n" @@ -72,7 +72,7 @@ def print_spend_bundle_conditions(result) -> str: else: ret += f" CREATE_COIN: ph: {a[0].hex()} amount: {a[1]}\n" for a in sorted(s.agg_sig_me): - ret += f" AGG_SIG_ME pk: {a[0].hex()} msg: {a[1].hex()}\n" + ret += f" AGG_SIG_ME pk: {a[0]} msg: {a[1].hex()}\n" ret += f"cost: {result.cost}\n" ret += f"removal_amount: {result.removal_amount}\n" ret += f"addition_amount: {result.addition_amount}\n" diff --git a/tests/test_streamable.py b/tests/test_streamable.py index 45ab8d58a..fbf2be217 100644 --- a/tests/test_streamable.py +++ b/tests/test_streamable.py @@ -1,14 +1,24 @@ -from chia_rs import Spend, SpendBundleConditions, Coin, G1Element, G2Element, Program +from chia_rs import ( + Spend, + SpendBundleConditions, + Coin, + G1Element, + G2Element, + Program, + AugSchemeMPL, +) from chia_rs.sized_ints import uint64 +from chia_rs.sized_bytes import bytes32 import pytest import copy +sk = AugSchemeMPL.key_gen(bytes32.random()) +pk = sk.get_g1() coin = b"bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc" parent = b"edededededededededededededededed" ph = b"abababababababababababababababab" ph2 = b"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd" -sig = b"abababababababababababababababababababababababab" def test_hash_spend() -> None: @@ -25,7 +35,7 @@ def test_hash_spend() -> None: None, None, [(ph2, 1000000, None)], - [(sig, b"msg")], + [(pk, b"msg")], [], [], [], @@ -46,7 +56,7 @@ def test_hash_spend() -> None: None, None, [(ph2, 1000000, None)], - [(sig, b"msg")], + [(pk, b"msg")], [], [], [], @@ -65,10 +75,10 @@ def test_hash_spend() -> None: def test_hash_spend_bundle_conditions() -> None: a1 = SpendBundleConditions( - [], 1000, 1337, 42, None, None, [(sig, b"msg")], 12345678, 123, 456 + [], 1000, 1337, 42, None, None, [(pk, b"msg")], 12345678, 123, 456 ) a2 = SpendBundleConditions( - [], 1001, 1337, 42, None, None, [(sig, b"msg")], 12345678, 123, 456 + [], 1001, 1337, 42, None, None, [(pk, b"msg")], 12345678, 123, 456 ) b = hash(a1) c = hash(a2) @@ -91,7 +101,7 @@ def test_json_spend() -> None: None, None, [(ph2, 1000000, None)], - [(sig, b"msg")], + [(pk, b"msg")], [], [], [], @@ -113,7 +123,7 @@ def test_json_spend() -> None: "birth_height": None, "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], - "agg_sig_me": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "0x6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -138,7 +148,7 @@ def test_from_json_spend() -> None: None, None, [(ph2, 1000000, None)], - [(sig, b"msg")], + [(pk, b"msg")], [], [], [], @@ -161,7 +171,7 @@ def test_from_json_spend() -> None: "birth_height": None, "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], - "agg_sig_me": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "0x6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -188,7 +198,7 @@ def test_from_json_spend_set_optional() -> None: None, None, [(ph2, 1000000, None)], - [(sig, b"msg")], + [(pk, b"msg")], [], [], [], @@ -211,7 +221,7 @@ def test_from_json_spend_set_optional() -> None: "birth_height": None, "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], - "agg_sig_me": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "0x6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -241,7 +251,7 @@ def test_invalid_hex_prefix() -> None: "birth_height": None, "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], - "agg_sig_me": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "0x6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -270,7 +280,7 @@ def test_invalid_hex_prefix_bytes() -> None: "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], # the message field is missing the 0x prefix and is variable length bytes - "agg_sig_me": [["0x" + sig.hex(), "6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -299,7 +309,7 @@ def test_invalid_hex_digit() -> None: "birth_height": None, "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], - "agg_sig_me": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "0x6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -328,7 +338,7 @@ def test_invalid_hex_length() -> None: "birth_height": None, "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], - "agg_sig_me": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "0x6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -356,7 +366,7 @@ def test_missing_field() -> None: "birth_height": None, "birth_seconds": None, "create_coin": [["0x" + ph2.hex(), 1000000, None]], - "agg_sig_me": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_me": [["0x" + bytes(pk).hex(), "0x6d7367"]], "agg_sig_parent": [], "agg_sig_puzzle": [], "agg_sig_amount": [], @@ -371,7 +381,7 @@ def test_missing_field() -> None: def test_json_spend_bundle_conditions() -> None: a = SpendBundleConditions( - [], 1000, 1337, 42, None, None, [(sig, b"msg")], 12345678, 123, 456 + [], 1000, 1337, 42, None, None, [(pk, b"msg")], 12345678, 123, 456 ) assert a.to_json_dict() == { @@ -381,7 +391,7 @@ def test_json_spend_bundle_conditions() -> None: "seconds_absolute": 42, "before_height_absolute": None, "before_seconds_absolute": None, - "agg_sig_unsafe": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_unsafe": [["0x" + bytes(pk).hex(), "0x6d7367"]], "cost": 12345678, "removal_amount": 123, "addition_amount": 456, @@ -391,7 +401,7 @@ def test_json_spend_bundle_conditions() -> None: def test_from_json_spend_bundle_conditions() -> None: a = SpendBundleConditions( - [], 1000, 1337, 42, None, None, [(sig, b"msg")], 12345678, 123, 456 + [], 1000, 1337, 42, None, None, [(pk, b"msg")], 12345678, 123, 456 ) b = SpendBundleConditions.from_json_dict( { @@ -401,7 +411,7 @@ def test_from_json_spend_bundle_conditions() -> None: "seconds_absolute": 42, "before_height_absolute": None, "before_seconds_absolute": None, - "agg_sig_unsafe": [["0x" + sig.hex(), "0x6d7367"]], + "agg_sig_unsafe": [["0x" + bytes(pk).hex(), "0x6d7367"]], "cost": 12345678, "removal_amount": 123, "addition_amount": 456, @@ -424,7 +434,7 @@ def test_copy_spend() -> None: None, None, [(ph2, 1000000, None)], - [(sig, b"msg")], + [(pk, b"msg")], [], [], [], @@ -446,7 +456,7 @@ def test_copy_spend() -> None: def test_copy_spend_bundle_conditions() -> None: a = SpendBundleConditions( - [], 1000, 1337, 42, None, None, [(sig, b"msg")], 12345678, 123, 456 + [], 1000, 1337, 42, None, None, [(pk, b"msg")], 12345678, 123, 456 ) b = copy.copy(a) diff --git a/wheel/generate_type_stubs.py b/wheel/generate_type_stubs.py index 8aed193ee..a6b3cce3a 100644 --- a/wheel/generate_type_stubs.py +++ b/wheel/generate_type_stubs.py @@ -437,13 +437,13 @@ def __init__( "birth_height: Optional[int]", "birth_seconds: Optional[int]", "create_coin: List[Tuple[bytes, int, Optional[bytes]]]", - "agg_sig_me: List[Tuple[bytes, bytes]]", - "agg_sig_parent: List[Tuple[bytes, bytes]]", - "agg_sig_puzzle: List[Tuple[bytes, bytes]]", - "agg_sig_amount: List[Tuple[bytes, bytes]]", - "agg_sig_puzzle_amount: List[Tuple[bytes, bytes]]", - "agg_sig_parent_amount: List[Tuple[bytes, bytes]]", - "agg_sig_parent_puzzle: List[Tuple[bytes, bytes]]", + "agg_sig_me: List[Tuple[G1Element, bytes]]", + "agg_sig_parent: List[Tuple[G1Element, bytes]]", + "agg_sig_puzzle: List[Tuple[G1Element, bytes]]", + "agg_sig_amount: List[Tuple[G1Element, bytes]]", + "agg_sig_puzzle_amount: List[Tuple[G1Element, bytes]]", + "agg_sig_parent_amount: List[Tuple[G1Element, bytes]]", + "agg_sig_parent_puzzle: List[Tuple[G1Element, bytes]]", "flags: int", ], ) @@ -458,7 +458,7 @@ def __init__( "seconds_absolute: int", "before_height_absolute: Optional[int]", "before_seconds_absolute: Optional[int]", - "agg_sig_unsafe: List[Tuple[bytes, bytes]]", + "agg_sig_unsafe: List[Tuple[G1Element, bytes]]", "cost: int", "removal_amount: int", "addition_amount: int", diff --git a/wheel/python/chia_rs/chia_rs.pyi b/wheel/python/chia_rs/chia_rs.pyi index 3e63b36fe..982747bce 100644 --- a/wheel/python/chia_rs/chia_rs.pyi +++ b/wheel/python/chia_rs/chia_rs.pyi @@ -238,13 +238,13 @@ class Spend: birth_height: Optional[int] birth_seconds: Optional[int] create_coin: List[Tuple[bytes, int, Optional[bytes]]] - agg_sig_me: List[Tuple[bytes, bytes]] - agg_sig_parent: List[Tuple[bytes, bytes]] - agg_sig_puzzle: List[Tuple[bytes, bytes]] - agg_sig_amount: List[Tuple[bytes, bytes]] - agg_sig_puzzle_amount: List[Tuple[bytes, bytes]] - agg_sig_parent_amount: List[Tuple[bytes, bytes]] - agg_sig_parent_puzzle: List[Tuple[bytes, bytes]] + agg_sig_me: List[Tuple[G1Element, bytes]] + agg_sig_parent: List[Tuple[G1Element, bytes]] + agg_sig_puzzle: List[Tuple[G1Element, bytes]] + agg_sig_amount: List[Tuple[G1Element, bytes]] + agg_sig_puzzle_amount: List[Tuple[G1Element, bytes]] + agg_sig_parent_amount: List[Tuple[G1Element, bytes]] + agg_sig_parent_puzzle: List[Tuple[G1Element, bytes]] flags: int def __init__( self, @@ -259,13 +259,13 @@ class Spend: birth_height: Optional[int], birth_seconds: Optional[int], create_coin: Sequence[Tuple[bytes, int, Optional[bytes]]], - agg_sig_me: Sequence[Tuple[bytes, bytes]], - agg_sig_parent: Sequence[Tuple[bytes, bytes]], - agg_sig_puzzle: Sequence[Tuple[bytes, bytes]], - agg_sig_amount: Sequence[Tuple[bytes, bytes]], - agg_sig_puzzle_amount: Sequence[Tuple[bytes, bytes]], - agg_sig_parent_amount: Sequence[Tuple[bytes, bytes]], - agg_sig_parent_puzzle: Sequence[Tuple[bytes, bytes]], + agg_sig_me: Sequence[Tuple[G1Element, bytes]], + agg_sig_parent: Sequence[Tuple[G1Element, bytes]], + agg_sig_puzzle: Sequence[Tuple[G1Element, bytes]], + agg_sig_amount: Sequence[Tuple[G1Element, bytes]], + agg_sig_puzzle_amount: Sequence[Tuple[G1Element, bytes]], + agg_sig_parent_amount: Sequence[Tuple[G1Element, bytes]], + agg_sig_parent_puzzle: Sequence[Tuple[G1Element, bytes]], flags: int ) -> None: ... def __hash__(self) -> int: ... @@ -297,13 +297,13 @@ class Spend: birth_height: Union[ Optional[int], _Unspec] = _Unspec(), birth_seconds: Union[ Optional[int], _Unspec] = _Unspec(), create_coin: Union[ List[Tuple[bytes, int, Optional[bytes]]], _Unspec] = _Unspec(), - agg_sig_me: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), - agg_sig_parent: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), - agg_sig_puzzle: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), - agg_sig_amount: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), - agg_sig_puzzle_amount: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), - agg_sig_parent_amount: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), - agg_sig_parent_puzzle: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), + agg_sig_me: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), + agg_sig_parent: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), + agg_sig_puzzle: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), + agg_sig_amount: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), + agg_sig_puzzle_amount: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), + agg_sig_parent_amount: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), + agg_sig_parent_puzzle: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), flags: Union[ int, _Unspec] = _Unspec()) -> Spend: ... class SpendBundleConditions: @@ -313,7 +313,7 @@ class SpendBundleConditions: seconds_absolute: int before_height_absolute: Optional[int] before_seconds_absolute: Optional[int] - agg_sig_unsafe: List[Tuple[bytes, bytes]] + agg_sig_unsafe: List[Tuple[G1Element, bytes]] cost: int removal_amount: int addition_amount: int @@ -325,7 +325,7 @@ class SpendBundleConditions: seconds_absolute: int, before_height_absolute: Optional[int], before_seconds_absolute: Optional[int], - agg_sig_unsafe: Sequence[Tuple[bytes, bytes]], + agg_sig_unsafe: Sequence[Tuple[G1Element, bytes]], cost: int, removal_amount: int, addition_amount: int @@ -354,7 +354,7 @@ class SpendBundleConditions: seconds_absolute: Union[ int, _Unspec] = _Unspec(), before_height_absolute: Union[ Optional[int], _Unspec] = _Unspec(), before_seconds_absolute: Union[ Optional[int], _Unspec] = _Unspec(), - agg_sig_unsafe: Union[ List[Tuple[bytes, bytes]], _Unspec] = _Unspec(), + agg_sig_unsafe: Union[ List[Tuple[G1Element, bytes]], _Unspec] = _Unspec(), cost: Union[ int, _Unspec] = _Unspec(), removal_amount: Union[ int, _Unspec] = _Unspec(), addition_amount: Union[ int, _Unspec] = _Unspec()) -> SpendBundleConditions: ... diff --git a/wheel/src/api.rs b/wheel/src/api.rs index 7f9cc6897..a5a708414 100644 --- a/wheel/src/api.rs +++ b/wheel/src/api.rs @@ -183,7 +183,7 @@ fn run_puzzle( let conds = native_run_puzzle::( &mut a, puzzle, solution, parent_id, amount, max_cost, flags, )?; - Ok(OwnedSpendBundleConditions::from(&a, conds)) + Ok(OwnedSpendBundleConditions::from(&a, conds)?) } // this is like a CoinSpend but with references to the puzzle and solution, diff --git a/wheel/src/run_generator.rs b/wheel/src/run_generator.rs index 5812065bf..191225786 100644 --- a/wheel/src/run_generator.rs +++ b/wheel/src/run_generator.rs @@ -4,7 +4,7 @@ use chia_consensus::gen::flags::ANALYZE_SPENDS; use chia_consensus::gen::owned_conditions::OwnedSpendBundleConditions; use chia_consensus::gen::run_block_generator::run_block_generator as native_run_block_generator; use chia_consensus::gen::run_block_generator::run_block_generator2 as native_run_block_generator2; -use chia_consensus::gen::validation_error::ValidationErr; +use chia_consensus::gen::validation_error::{ErrorCode, ValidationErr}; use clvmr::cost::Cost; @@ -49,14 +49,12 @@ pub fn run_block_generator( Ok( match run_block(&mut allocator, program, &refs, max_cost, flags) { Ok(spend_bundle_conds) => { - // everything was successful - ( - None, - Some(OwnedSpendBundleConditions::from( - &allocator, - spend_bundle_conds, - )), - ) + let conds = OwnedSpendBundleConditions::from(&allocator, spend_bundle_conds); + match conds { + // everything was successful + Ok(c) => (None, Some(c)), + Err(_) => (Some(ErrorCode::InvalidPublicKey.into()), None), + } } Err(ValidationErr(_, error_code)) => { // a validation error occurred @@ -103,14 +101,12 @@ pub fn run_block_generator2( Ok( match run_block(&mut allocator, program, &refs, max_cost, flags) { Ok(spend_bundle_conds) => { - // everything was successful - ( - None, - Some(OwnedSpendBundleConditions::from( - &allocator, - spend_bundle_conds, - )), - ) + let conds = OwnedSpendBundleConditions::from(&allocator, spend_bundle_conds); + match conds { + // everything was successful + Ok(c) => (None, Some(c)), + Err(_) => (Some(ErrorCode::InvalidPublicKey.into()), None), + } } Err(ValidationErr(_, error_code)) => { // a validation error occurred