MCPcopy Create free account
hub / github.com/ElementsProject/elements / gen_test_vectors

Method gen_test_vectors

test/functional/feature_taproot.py:1654–1898  ·  view source on GitHub ↗

Run a scenario that corresponds (and optionally produces) to BIP341 test vectors.

(self)

Source from the content-addressed store, hash-verified

1652 self.log.info(" - Done")
1653
1654 def gen_test_vectors(self):
1655 """Run a scenario that corresponds (and optionally produces) to BIP341 test vectors."""
1656
1657 self.log.info("Unit test scenario...")
1658
1659 # Deterministically mine coins to OP_TRUE in block 1
1660 assert self.nodes[1].getblockcount() == 0
1661 coinbase = CTransaction()
1662 coinbase.nVersion = 1
1663 coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), SEQUENCE_FINAL)]
1664 coinbase.vout = [CTxOut(5000000000, CScript([OP_1]))]
1665 coinbase.nLockTime = 0
1666 coinbase.rehash()
1667 assert coinbase.hash == "648ee1a8eafbada9bd93f8d776038feac85b360f00682a02b27b92d32f6f14dc"
1668 # Mine it
1669 block = create_block(hashprev=int(self.nodes[1].getbestblockhash(), 16), coinbase=coinbase)
1670 block.rehash()
1671 block.solve()
1672 self.nodes[1].submitblock(block.serialize().hex())
1673 assert self.nodes[1].getblockcount() == 1
1674 self.generate(self.nodes[1], COINBASE_MATURITY)
1675
1676 SEED = 317
1677 VALID_LEAF_VERS = list(range(0xc4, 0x100, 2)) + [0x66, 0x7e, 0x80, 0x84, 0x96, 0x98, 0xba, 0xbc, 0xbe]
1678 # Generate private keys
1679 prvs = [hashlib.sha256(SEED.to_bytes(2, 'big') + bytes([i])).digest() for i in range(100)]
1680 # Generate corresponding public x-only pubkeys
1681 pubs = [compute_xonly_pubkey(prv)[0] for prv in prvs]
1682 # Generate taproot objects
1683 inner_keys = [pubs[i] for i in range(7)]
1684
1685 script_lists = [
1686 None,
1687 [("0", CScript([pubs[50], OP_CHECKSIG]), 0xc4)],
1688 [("0", CScript([pubs[51], OP_CHECKSIG]), 0xc4)],
1689 [("0", CScript([pubs[52], OP_CHECKSIG]), 0xc4), ("1", CScript([b"BIP341"]), VALID_LEAF_VERS[pubs[99][0] % len(VALID_LEAF_VERS)])],
1690 [("0", CScript([pubs[53], OP_CHECKSIG]), 0xc4), ("1", CScript([b"Taproot"]), VALID_LEAF_VERS[pubs[99][1] % len(VALID_LEAF_VERS)])],
1691 [("0", CScript([pubs[54], OP_CHECKSIG]), 0xc4), [("1", CScript([pubs[55], OP_CHECKSIG]), 0xc4), ("2", CScript([pubs[56], OP_CHECKSIG]), 0xc4)]],
1692 [("0", CScript([pubs[57], OP_CHECKSIG]), 0xc4), [("1", CScript([pubs[58], OP_CHECKSIG]), 0xc4), ("2", CScript([pubs[59], OP_CHECKSIG]), 0xc4)]],
1693 ]
1694 taps = [taproot_construct(inner_keys[i], script_lists[i]) for i in range(len(inner_keys))]
1695
1696 # Require negated taps[0]
1697 assert taps[0].negflag
1698 # Require one negated and one non-negated in taps 1 and 2.
1699 # assert taps[1].negflag != taps[2].negflag
1700 # Require one negated and one non-negated in taps 3 and 4.
1701 #assert taps[3].negflag != taps[4].negflag
1702 # Require one negated and one non-negated in taps 5 and 6.
1703 # assert taps[5].negflag != taps[6].negflag
1704
1705 # cblks = [{leaf: get({**DEFAULT_CONTEXT, 'tap': taps[i], 'leaf': leaf}, 'controlblock') for leaf in taps[i].leaves} for i in range(7)]
1706 # Require one swapped and one unswapped in taps 3 and 4.
1707 #assert (cblks[3]['0'][33:65] < cblks[3]['1'][33:65]) != (cblks[4]['0'][33:65] < cblks[4]['1'][33:65])
1708 # Require one swapped and one unswapped in taps 5 and 6, both at the top and child level.
1709 #assert (cblks[5]['0'][33:65] < cblks[5]['1'][65:]) != (cblks[6]['0'][33:65] < cblks[6]['1'][65:])
1710 #assert (cblks[5]['1'][33:65] < cblks[5]['2'][33:65]) != (cblks[6]['1'][33:65] < cblks[6]['2'][33:65])
1711 # Require within taps 5 (and thus also 6) that one level is swapped and the other is not.

Callers 1

run_testMethod · 0.95

Calls 15

rehashMethod · 0.95
setMethod · 0.95
get_pubkeyMethod · 0.95
init_blockinfoMethod · 0.95
block_submitMethod · 0.95
serializeMethod · 0.95
CTransactionClass · 0.90
CTxInClass · 0.90
COutPointClass · 0.90
CScriptClass · 0.90
CTxOutClass · 0.90
create_blockFunction · 0.90

Tested by

no test coverage detected