示例#1
0
def test():
    b1 = BN([1, 2])
    b2 = BN([3, 1, 4, 1, 5, 9])
    i1 = int.from_bytes(bytes([1, 2]), byteorder='big', signed=False)
    i2 = int.from_bytes(bytes([3,1,4,1,5,9]), byteorder='big', signed=False)
    g1 = G1.generator()
    g2 = G2.generator()
    u1 = G1()  # unity
    u2 = G2()

    x1 = g1 * b1
    x2 = g1 * b2
    y1 = g2 * b1
    y2 = g2 * b2

    # Implicit conversion from python ints to BNWrapper
    assert x1 == g1 * i1 == i1 * g1
    assert x2 == g1 * i2 == i2 * g1
    assert y1 == g2 * i1 == i1 * g2
    assert y2 == g2 * i2 == i2 * g2

    # G1
    assert x1 != x2
    assert x1 * b1 == b1 * x1
    assert x1 * b1 != x1 * b2
    assert x1 + u1 == x1
    assert x1 + x2 == x2 + x1
    assert x1 + x1.inverse() == u1

    # G2
    assert y1 != y2
    assert y1 * b1 == b1 * y1
    assert y1 * b1 != y1 * b2
    assert y1 + u2 == y1
    assert y1 + y2 == y2 + y1
    assert y1 + y1.inverse() == u2

    # pairing operation
    pair = x1 & y1
    assert pair != x1 & y2
    assert pair != x2 & y1
    assert pair == x1.pair(y1)
from src.util.ints import uint64
from src.wallet.cc_wallet.debug_spend_bundle import debug_spend_bundle
from src.wallet.cc_wallet.cc_utils import (
    cc_puzzle_for_inner_puzzle,
    cc_puzzle_hash_for_inner_puzzle_hash,
    spendable_cc_list_from_coin_solution,
    spend_bundle_for_spendable_ccs,
    CC_MOD,
)
from src.wallet.puzzles.genesis_by_coin_id_with_0 import create_genesis_or_zero_coin_checker
from src.wallet.puzzles.genesis_by_puzzle_hash_with_0 import create_genesis_puzzle_or_zero_coin_checker

CONDITIONS = dict(
    (k, bytes(v)[0]) for k, v in ConditionOpcode.__members__.items())

NULL_SIGNATURE = G2Element.generator() * 0

ANYONE_CAN_SPEND_PUZZLE = Program.to(1)  # simply return the conditions

NULL_F = Program.from_bytes(bytes.fromhex("ff01ff8080"))  # (q ())

PUZZLE_TABLE: Dict[bytes32, Program] = dict(
    (_.get_tree_hash(), _) for _ in [ANYONE_CAN_SPEND_PUZZLE])


def hash_to_puzzle_f(puzzle_hash: bytes32) -> Optional[Program]:
    return PUZZLE_TABLE.get(puzzle_hash)


def add_puzzles_to_puzzle_preimage_db(puzzles: List[Program]) -> None:
    for _ in puzzles:
示例#3
0
def test_elements():
    b1 = BNWrapper([1, 2])
    b2 = BNWrapper([3, 1, 4, 1, 5, 9])
    i1 = int.from_bytes(bytes([1, 2]), byteorder="big")
    i2 = int.from_bytes(bytes([3, 1, 4, 1, 5, 9]), byteorder="big")
    g1 = G1Element.generator()
    g2 = G2Element.generator()
    u1 = G1Element.infinity()  # unity
    u2 = G2Element.infinity()

    # Does not allow construction
    try:
        i = G1Element()
        assert False
    except Exception:
        pass
    try:
        i = G2Element()
        assert False
    except Exception:
        pass

    x1 = g1 * b1
    x2 = g1 * b2
    y1 = g2 * b1
    y2 = g2 * b2

    # Implicit conversion from python ints to BNWrapperWrapperWrapper
    assert x1 == g1 * i1 == i1 * g1
    assert x2 == g1 * i2 == i2 * g1
    assert y1 == g2 * i1 == i1 * g2
    assert y2 == g2 * i2 == i2 * g2

    # G1
    assert x1 != x2
    assert x1 * b1 == b1 * x1
    assert x1 * b1 != x1 * b2
    assert x1 + u1 == x1
    assert x1 + x2 == x2 + x1
    assert x1 + x1.negate() == u1
    assert x1 == G1Element(bytes(x1))
    copy = deepcopy(x1)
    assert x1 == copy
    x1 += x2
    assert x1 != copy

    # G2
    assert y1 != y2
    assert y1 * b1 == b1 * y1
    assert y1 * b1 != y1 * b2
    assert y1 + u2 == y1
    assert y1 + y2 == y2 + y1
    assert y1 + y1.negate() == u2
    assert y1 == G2Element(bytes(y1))
    copy = deepcopy(y1)
    assert y1 == copy
    y1 += y2
    assert y1 != copy

    # pairing operation
    pair = x1 & y1
    assert pair != x1 & y2
    assert pair != x2 & y1
    assert pair == x1.pair(y1)
    assert pair == GTElement(bytes(pair))
    copy = deepcopy(pair)
    assert pair == copy
    pair = None
    assert pair != copy