Exemple #1
0
def hash_key_pairs_for_conditions_dict(
    conditions_dict: Dict[ConditionOpcode, List[ConditionVarPair]], coin_name: bytes32
) -> List[BLSSignature.PkMessagePair]:
    pairs: List[BLSSignature.PkMessagePair] = []
    for cvp in conditions_dict.get(ConditionOpcode.AGG_SIG, []):
        # TODO: check types
        # assert len(_) == 3
        blspubkey: BLSPublicKey = BLSPublicKey(cvp.var1)
        message: bytes32 = bytes32(blspy.Util.hash256(cvp.var2))
        pairs.append(BLSSignature.PkMessagePair(blspubkey, message))
    for cvp in conditions_dict.get(ConditionOpcode.AGG_SIG_ME, []):
        aggsigme_blspubkey: BLSPublicKey = BLSPublicKey(cvp.var1)
        aggsigme_message: bytes32 = bytes32(blspy.Util.hash256(cvp.var2 + coin_name))
        pairs.append(BLSSignature.PkMessagePair(aggsigme_blspubkey, aggsigme_message))
    return pairs
Exemple #2
0
    clvm_cost = 0
    for i in range(0, 1000):
        cost_run, sexp = run_program(puzzles[i], solutions[i])
        clvm_cost += cost_run

    puzzle_end = time.time()
    puzzle_time = puzzle_end - puzzle_start
    print(f"Puzzle_time is: {puzzle_time}")
    print(f"Puzzle cost sum is: {clvm_cost}")

    private_key = BLSPrivateKey(
        extended_secret_key.private_child(0).get_private_key())
    public_key = private_key.public_key()
    message = token_bytes()
    signature = private_key.sign(message)
    pk_message_pair = BLSSignature.PkMessagePair(public_key, message)

    # Run AggSig 1000 times
    agg_sig_start = time.time()
    agg_sig_cost = 0
    for i in range(0, 1000):
        valid = signature.validate([pk_message_pair])
        agg_sig_cost += 20
    agg_sig_end = time.time()
    agg_sig_time = agg_sig_end - agg_sig_start
    print(f"Aggsig Cost: {agg_sig_cost}")
    print(f"Aggsig time is: {agg_sig_time}")

    # clvm_should_cost = agg_sig_cost * puzzle_time / agg_sig_time
    clvm_should_cost = (agg_sig_cost * puzzle_time) / agg_sig_time
    print(f"Puzzle should cost: {clvm_should_cost}")