Skip to content

Commit

Permalink
Use clvm_rs version of Program.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkiss committed Jun 7, 2023
1 parent 707ed9e commit ae51594
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion hsms/clvm/disasm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io

from clvm_rs.program import Program
from clvm_rs import Program


# this differs from clvm_tools in that it adds the single quote
Expand Down
2 changes: 1 addition & 1 deletion hsms/cmds/hsm_test_spend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hashlib
import zlib

from clvm_rs.program import Program
from clvm_rs import Program

from hsms.bls12_381 import BLSPublicKey

Expand Down
2 changes: 1 addition & 1 deletion hsms/cmds/hsms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
import zlib

from clvm_rs.program import Program
from clvm_rs import Program

import segno

Expand Down
2 changes: 1 addition & 1 deletion hsms/consensus/conditions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Iterable, List

from clvm_rs.program import Program
from clvm_rs import Program


def iter_program(program: Program) -> Iterable[Program]:
Expand Down
5 changes: 3 additions & 2 deletions hsms/debug/debug_spend_bundle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from clvm_rs.program import Program
from clvm_rs import Program

from hsms.bls12_381 import BLSSignature
from hsms.clvm.disasm import disassemble as bu_disassemble, KEYWORD_FROM_ATOM
Expand Down Expand Up @@ -82,7 +82,7 @@ def debug_spend_bundle(
f"\nbrun -y main.sym '{bu_disassemble(puzzle_reveal)}'"
f" '{bu_disassemble(solution)}'"
)
r = puzzle_reveal.run(solution)
cost, r = puzzle_reveal.run_with_cost(solution, max_cost=1<<34)
conditions = conditions_by_opcode(r)
error = None
if error:
Expand All @@ -95,6 +95,7 @@ def debug_spend_bundle(
msgs.append(m)
print()
print(disassemble(r))
print(f"cost = {cost}")
print()
if conditions and len(conditions) > 0:
print("grouped conditions:")
Expand Down
2 changes: 1 addition & 1 deletion hsms/make_unsigned_tx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hashlib

from clvm_rs.program import Program
from clvm_rs import Program

from hsms.meta.hexbytes import hexbytes
from hsms.multisig.pst import PartiallySignedTransaction
Expand Down
8 changes: 4 additions & 4 deletions hsms/process/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, Iterable, List, Optional, Tuple
from weakref import WeakKeyDictionary

from clvm_rs.program import Program
from clvm_rs import Program

from hsms.atoms import hexbytes
from hsms.bls12_381 import BLSPublicKey, BLSSecretExponent
Expand All @@ -26,9 +26,9 @@ class SignatureMetadata:

def conditions_for_coin_spend(coin_spend: CoinSpend) -> Program:
if coin_spend not in CONDITIONS_FOR_COIN_SPEND:
CONDITIONS_FOR_COIN_SPEND[coin_spend] = coin_spend.puzzle_reveal.run(
coin_spend.solution
)
CONDITIONS_FOR_COIN_SPEND[coin_spend] = coin_spend.puzzle_reveal.run_with_cost(
coin_spend.solution, max_cost=1<<32
)[1]
return CONDITIONS_FOR_COIN_SPEND[coin_spend]


Expand Down
2 changes: 1 addition & 1 deletion hsms/process/unsigned_spend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from typing import List

from clvm_rs.program import Program
from clvm_rs import Program

from hsms.bls12_381 import BLSPublicKey, BLSSignature
from hsms.process.signing_hints import SumHint, PathHint
Expand Down
2 changes: 1 addition & 1 deletion hsms/puzzles/load_clvm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib

import pkg_resources
from clvm_rs.program import Program
from clvm_rs import Program
from clvm_tools_rs import compile_clvm


Expand Down
4 changes: 2 additions & 2 deletions hsms/puzzles/p2_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
the doctor ordered.
"""

from clvm_rs.program import Program
from clvm_rs import Program

from .load_clvm import load_clvm

MOD = load_clvm("p2_conditions.cl")


def puzzle_for_conditions(conditions) -> Program:
return MOD.run([conditions])
return MOD.run_with_cost([conditions], max_cost=1<<32)[1]


def solution_for_conditions(conditions) -> Program:
Expand Down
6 changes: 4 additions & 2 deletions hsms/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

import hashlib

from clvm_rs.program import Program
from clvm_rs import Program

from hsms.bls12_381 import BLSPublicKey, BLSSecretExponent
from hsms.streamables import bytes32
Expand Down Expand Up @@ -90,7 +90,9 @@ def calculate_synthetic_offset(
def calculate_synthetic_public_key(
public_key: BLSPublicKey, hidden_puzzle_hash: bytes32
) -> BLSPublicKey:
r = SYNTHETIC_MOD.run([bytes(public_key), hidden_puzzle_hash])
_cost, r = SYNTHETIC_MOD.run_with_cost(
[bytes(public_key), hidden_puzzle_hash], max_cost=1 << 32
)
return BLSPublicKey.from_bytes(r.atom)


Expand Down
2 changes: 1 addition & 1 deletion hsms/streamables/coin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io

from clvm_rs.program import Program
from clvm_rs import Program

from hsms.atoms import uint64
from hsms.meta import streamable
Expand Down
2 changes: 1 addition & 1 deletion hsms/streamables/coin_spend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from clvm_rs.program import Program
from clvm_rs import Program

from .coin import Coin

Expand Down
2 changes: 1 addition & 1 deletion hsms/util/clvm_serialization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Callable, Dict, List, Tuple, TypeVar

from clvm_rs.program import Program
from clvm_rs import Program


K = TypeVar("K")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
repository = "https://github.com/chia-network/hsms.git"
readme = "README.md"
src_root = "."
dependencies = ["blspy==1.0.16", "segno==1.4.1", "clvm_rs @ git+https://github.com/Chia-Network/clvm_rs@17196e726b073681dc2c2df14fcff4b5cf6e527b#egg=clvm_rs&subdirectory=wheel", "clvm_tools_rs==0.1.30"]
dependencies = ["blspy==1.0.16", "segno==1.4.1", "clvm_rs==0.2.5", "clvm_tools_rs==0.1.30"]
packages = ["hsms"]
# version is defined with `setuptools_scm`. See `SConstruct` file.

Expand Down
2 changes: 1 addition & 1 deletion tests/test_disasm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from clvm_rs.program import Program
from clvm_rs import Program

from hsms.clvm.disasm import disassemble

Expand Down

0 comments on commit ae51594

Please sign in to comment.