Confirmed the assertion via a functional test
def test_nonstandard_master_key_id(self, passphrase, do_wallet_tool):
self.log.info("Test that a master key with a non-standard ID remains unchanged")
current_node = self.nodes[0]
wallet_name = "pr36031_non_standard_id"
current_node.createwallet(wallet_name=wallet_name)
pr36031_non_standard_id = current_node.get_wallet_rpc(wallet_name)
pr36031_non_standard_id.encryptwallet(passphrase)
pr36031_non_standard_id.unloadwallet()
dumpfile_path = current_node.datadir_path / f"{pr36031_non_standard_id}.dump"
do_wallet_tool(f"-wallet={wallet_name}", f"-dumpfile={dumpfile_path}", "dump")
mkey_prefix = "046d6b6579"
''' Patch the mkey record's ID from 1 (01000000, 4-byte LE) to 42 (2a000000)'''
with open(dumpfile_path, "r") as f:
dump_content = f.readlines()
dump_content = dump_content[:-1]
mkey_idx = next(i for i, l in enumerate(dump_content) if l.startswith(F"{mkey_prefix}"))
key_hex, value_hex = dump_content[mkey_idx].strip().split(",")
''''asserts that the value is not 1 as changed in `src/wallet/crypter.h:45 uint32_t m_id{10000};` '''
assert_not_equal(key_hex[-8:], "01000000")
dump_content[mkey_idx] = f"{key_hex[:-8]}2a000000,{value_hex}\n"
with open(dumpfile_path, "w") as f:
contents = "".join(dump_content)
f.write(contents)
checksum = hash256(contents.encode())
f.write(f"checksum,{checksum.hex()}\n")
wallet_name_new = "pr36031_non_standard_id_new"
do_wallet_tool(f"-wallet={wallet_name_new}", f"-dumpfile={dumpfile_path}", "createfromdump")
current_node.loadwallet(wallet_name_new)
pr36031_non_standard_id_new = current_node.get_wallet_rpc(wallet_name_new)
receive = pr36031_non_standard_id_new.getnewaddress()
current_node.generatetoaddress(101, receive, called_by_framework=True)
with WalletUnlock(pr36031_non_standard_id_new, passphrase):
destination = pr36031_non_standard_id_new.getnewaddress()
utxo = pr36031_non_standard_id_new.listunspent()[0]
raw = pr36031_non_standard_id_new.createrawtransaction(
[{"txid": utxo["txid"], "vout": utxo["vout"]}],
{destination: 1.0},
)
signed = pr36031_non_standard_id_new.signrawtransactionwithwallet(raw)
assert_equal(signed["complete"], True)
pr36031_non_standard_id_new.unloadwallet()
redump_path = current_node.datadir_path / "pr36031_non_standard_id_new.dump"
do_wallet_tool(f"-wallet={wallet_name_new}", f"-dumpfile={redump_path}", "dump")
with open(redump_path, "r") as f:
mkey_line = next(l for l in f if l.startswith(f"{mkey_prefix}"))
''''asserts that the above operations were actually done using the tweaked mkey '''
assert mkey_line.split(",")[0].endswith("2a000000")
The test passes with the above change
output
<img width="2708" height="1520" alt="Image" src="https://github.com/user-attachments/assets/7dbecfd9-e8b8-440c-9a41-4f5f9391dddc" />