mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-29 10:00:05 +02:00
signet: miner skips PSBT step for OP_TRUE
This commit is contained in:
@@ -80,6 +80,9 @@ DIFF_4_N_BITS = 0x1c3fffc0
|
||||
DIFF_4_TARGET = int(DIFF_1_TARGET / 4)
|
||||
assert_equal(uint256_from_compact(DIFF_4_N_BITS), DIFF_4_TARGET)
|
||||
|
||||
# From BIP325
|
||||
SIGNET_HEADER = b"\xec\xc7\xda\xa2"
|
||||
|
||||
def nbits_str(nbits):
|
||||
return f"{nbits:08x}"
|
||||
|
||||
|
@@ -10,9 +10,9 @@ import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
from test_framework.blocktools import DIFF_1_N_BITS
|
||||
from test_framework.blocktools import DIFF_1_N_BITS, SIGNET_HEADER
|
||||
from test_framework.key import ECKey
|
||||
from test_framework.script_util import key_to_p2wpkh_script
|
||||
from test_framework.script_util import CScript, key_to_p2wpkh_script
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
@@ -23,31 +23,49 @@ from test_framework.wallet_util import bytes_to_wif
|
||||
|
||||
CHALLENGE_PRIVATE_KEY = (42).to_bytes(32, 'big')
|
||||
|
||||
def get_segwit_commitment(node):
|
||||
coinbase = node.getblock(node.getbestblockhash(), 2)['tx'][0]
|
||||
commitment = coinbase['vout'][1]['scriptPubKey']['hex']
|
||||
assert_equal(commitment[0:12], '6a24aa21a9ed')
|
||||
return commitment
|
||||
|
||||
def get_signet_commitment(segwit_commitment):
|
||||
for el in CScript.fromhex(segwit_commitment):
|
||||
if isinstance(el, bytes) and el[0:4] == SIGNET_HEADER:
|
||||
return el[4:].hex()
|
||||
return None
|
||||
|
||||
class SignetMinerTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.chain = "signet"
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.num_nodes = 4
|
||||
|
||||
# generate and specify signet challenge (simple p2wpkh script)
|
||||
privkey = ECKey()
|
||||
privkey.set(CHALLENGE_PRIVATE_KEY, True)
|
||||
pubkey = privkey.get_pubkey().get_bytes()
|
||||
challenge = key_to_p2wpkh_script(pubkey)
|
||||
self.extra_args = [[f'-signetchallenge={challenge.hex()}']]
|
||||
|
||||
self.extra_args = [
|
||||
[f'-signetchallenge={challenge.hex()}'],
|
||||
["-signetchallenge=51"], # OP_TRUE
|
||||
["-signetchallenge=60"], # OP_16
|
||||
["-signetchallenge=202cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"], # sha256("hello")
|
||||
]
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_cli()
|
||||
self.skip_if_no_wallet()
|
||||
self.skip_if_no_bitcoin_util()
|
||||
|
||||
def run_test(self):
|
||||
node = self.nodes[0]
|
||||
# import private key needed for signing block
|
||||
wallet_importprivkey(node, bytes_to_wif(CHALLENGE_PRIVATE_KEY), "now")
|
||||
def setup_network(self):
|
||||
self.setup_nodes()
|
||||
# Nodes with different signet networks are not connected
|
||||
|
||||
# generate block with signet miner tool
|
||||
# generate block with signet miner tool
|
||||
def mine_block(self, node):
|
||||
n_blocks = node.getblockcount()
|
||||
base_dir = self.config["environment"]["SRCDIR"]
|
||||
signet_miner_path = os.path.join(base_dir, "contrib", "signet", "miner")
|
||||
rpc_argv = node.binaries.rpc_argv() + [f"-datadir={node.cli.datadir}"]
|
||||
@@ -63,7 +81,34 @@ class SignetMinerTest(BitcoinTestFramework):
|
||||
f'--set-block-time={int(time.time())}',
|
||||
'--poolnum=99',
|
||||
], check=True, stderr=subprocess.STDOUT)
|
||||
assert_equal(node.getblockcount(), 1)
|
||||
assert_equal(node.getblockcount(), n_blocks + 1)
|
||||
|
||||
def run_test(self):
|
||||
self.log.info("Signet node with single signature challenge")
|
||||
node = self.nodes[0]
|
||||
# import private key needed for signing block
|
||||
wallet_importprivkey(node, bytes_to_wif(CHALLENGE_PRIVATE_KEY), 0)
|
||||
self.mine_block(node)
|
||||
# MUST include signet commitment
|
||||
assert get_signet_commitment(get_segwit_commitment(node))
|
||||
|
||||
node = self.nodes[1]
|
||||
self.log.info("Signet node with trivial challenge (OP_TRUE)")
|
||||
self.mine_block(node)
|
||||
# MAY omit signet commitment (BIP 325). Do so for better compatibility
|
||||
# with signet unaware mining software and hardware.
|
||||
assert get_signet_commitment(get_segwit_commitment(node)) is None
|
||||
|
||||
node = self.nodes[2]
|
||||
self.log.info("Signet node with trivial challenge (OP_16)")
|
||||
self.mine_block(node)
|
||||
assert get_signet_commitment(get_segwit_commitment(node)) is None
|
||||
|
||||
node = self.nodes[3]
|
||||
self.log.info("Signet node with trivial challenge (push sha256 hash)")
|
||||
self.mine_block(node)
|
||||
assert get_signet_commitment(get_segwit_commitment(node)) is None
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user