From 39f82f771b0e22c51807d269bd990c98febfd6f1 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 29 Nov 2026 17:04:40 +0000 Subject: [PATCH] whitespace, comments, minor fixes --- doc/release-notes/release-notes-v17.0.1.md | 4 +- mmgen/addr.py | 2 +- mmgen/data/mmgen.cfg | 12 ++--- mmgen/help/autosign.py | 5 ++- mmgen/proto/btc/tx/bump.py | 2 +- mmgen/proto/btc/tx/new.py | 4 +- mmgen/proto/btc/tx/unsigned.py | 2 +- mmgen/proto/eth/tx/new.py | 5 +-- mmgen/proto/vm/tx/completed.py | 3 -- mmgen/tx/new.py | 2 +- test/cmdtest_d/automount.py | 2 + test/cmdtest_d/base.py | 7 +++ test/cmdtest_d/main.py | 51 +++++++++++++++------- test/cmdtest_d/shared.py | 5 ++- 14 files changed, 68 insertions(+), 38 deletions(-) diff --git a/doc/release-notes/release-notes-v17.0.1.md b/doc/release-notes/release-notes-v17.0.1.md index f885a648..4d5cc444 100644 --- a/doc/release-notes/release-notes-v17.0.1.md +++ b/doc/release-notes/release-notes-v17.0.1.md @@ -12,5 +12,5 @@ All users are urgently advised to upgrade. #### Important security fixes: - - ffffffff `tx.file`: require `have_wif` field to be absent - - ffffffff `check_swap_memo()`: require `is_swap` to be set if memo present in transaction + - fa0d2a63 `tx.file`: require `have_wif` field to be absent for transaction outputs + - 1d96c17b `check_swap_memo()`: require `is_swap` to be set if memo present in transaction diff --git a/mmgen/addr.py b/mmgen/addr.py index 0ef5cb12..d406e3e2 100644 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -48,7 +48,7 @@ class MMGenAddrType(HiliteStr, InitErrors, MMGenObject): 'L': ati('legacy', 'std', False,'p2pkh', 'p2pkh', 'wif', (), 'Legacy uncompressed address'), 'C': ati('compressed','std', True, 'p2pkh', 'p2pkh', 'wif', (), 'Compressed P2PKH address'), 'S': ati('segwit', 'std', True, 'segwit', 'p2sh', 'wif', (), 'Segwit P2SH-P2WPKH address'), - 'B': ati('bech32', 'std', True, 'bech32', 'bech32', 'wif', (), 'Native Segwit (Bech32) address'), + 'B': ati('bech32', 'std', True, 'bech32', 'bech32', 'wif', (), 'Segwit Bech32 P2WPKH address'), 'X': ati('bech32x', 'std', True, 'p2pkh', 'bech32', 'wif', (), 'Cross-chain Bech32 address'), 'K': ati('bech32pk', 'std', True, 'bech32pk','bech32', 'wif', (), 'Cross-chain pubkey Bech32 address'), 'E': ati('ethereum', 'std', False,'ethereum','p2pkh', 'privkey', ('wallet_passwd',),'Ethereum address'), diff --git a/mmgen/data/mmgen.cfg b/mmgen/data/mmgen.cfg index 59769cd2..d967f75b 100644 --- a/mmgen/data/mmgen.cfg +++ b/mmgen/data/mmgen.cfg @@ -64,9 +64,6 @@ # enable this option on the offline device. # forbid_version_mismatched_tx_files true -# Set the maximum transaction fee for BTC: -# btc_max_tx_fee 0.003 - # Set the transaction fee adjustment factor. Auto-calculated fees are # multiplied by this value: # fee_adjust 1.0 @@ -138,13 +135,16 @@ ####################################################################### ####################################################################### -##################### -## Altcoin options ## -##################### +########################### +## Coin-specific options ## +########################### # Set this to false to prefer legacy BCH address format: # bch_cashaddr true +# Set the maximum transaction fee for BTC: +# btc_max_tx_fee 0.003 + # Set the maximum transaction fee for BCH: # bch_max_tx_fee 0.1 diff --git a/mmgen/help/autosign.py b/mmgen/help/autosign.py index db604f17..39eff5ba 100644 --- a/mmgen/help/autosign.py +++ b/mmgen/help/autosign.py @@ -175,7 +175,7 @@ begin with ‘--xmrwallets=1’. More wallets may be added in later signing sessions if necessary. See EXAMPLES below. - SECURITY NOTE + PHYSICAL SECURITY By placing the session wallet and password on separate devices, this program creates a two-factor authentication setup whereby an attacker must gain @@ -200,6 +200,9 @@ device. Always remember to power off the signing machine when your signing session is over. + + NETWORK SECURITY + After each signing operation, this program displays a summary showing each transaction’s non-wallet destination address(es) and amount(s). As an extra security measure, it’s a good idea to compare these with the address(es) and diff --git a/mmgen/proto/btc/tx/bump.py b/mmgen/proto/btc/tx/bump.py index f817d1b6..c3a66ca6 100644 --- a/mmgen/proto/btc/tx/bump.py +++ b/mmgen/proto/btc/tx/bump.py @@ -44,7 +44,7 @@ class Bump(Completed, NewSwap, TxBase.Bump): return False output_amt = self.outputs[self.bump_output_idx].amt if ret >= output_amt: - msg('{} {c}: {} fee too large. Maximum fee: <{} {c}'.format( + msg('{} {c}: {} fee too high. Maximum fee: <{} {c}'.format( ret.hl(), desc, output_amt.hl(), diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index e110e334..2c8748e2 100644 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -94,9 +94,9 @@ class New(Base, TxNew): case False: msg(f'{fee!r}: invalid TX fee (not a {self.coin} amount or {self.rel_fee_desc} specification)') case x if x > self.proto.max_tx_fee: - msg(f'{x} {self.coin}: {desc} fee too large (maximum fee: {self.proto.max_tx_fee} {self.coin})') + msg(f'{x} {self.coin}: {desc} fee too high (maximum fee: {self.proto.max_tx_fee} {self.coin})') case x if x < self.relay_fee: - msg(f'{x} {self.coin}: {desc} fee too small (less than relay fee of {self.relay_fee} {self.coin})') + msg(f'{x} {self.coin}: {desc} fee too low (less than relay fee of {self.relay_fee} {self.coin})') case x: return x return False diff --git a/mmgen/proto/btc/tx/unsigned.py b/mmgen/proto/btc/tx/unsigned.py index 7dba3935..e361bae6 100644 --- a/mmgen/proto/btc/tx/unsigned.py +++ b/mmgen/proto/btc/tx/unsigned.py @@ -49,7 +49,7 @@ class Unsigned(Completed, TxBase.Unsigned): try: args = ( - ('signrawtransaction', self.serialized, sig_data, wifs, self.proto.sighash_type), + ('signrawtransaction', self.serialized, sig_data, wifs, self.proto.sighash_type), ('signrawtransactionwithkey', self.serialized, wifs, sig_data, self.proto.sighash_type) )['sign_with_key' in self.rpc.caps] ret = await self.rpc.call(*args) diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index f049181a..f30da918 100644 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -109,10 +109,9 @@ class New(VmNew, Base, TxBase.New): return ret def convert_and_check_fee(self, fee, desc): - abs_fee = self.feespec2abs(fee, None) - if abs_fee is False: + if (abs_fee := self.feespec2abs(fee, None)) is False: return False - elif not self.disable_fee_check and (abs_fee > self.proto.max_tx_fee): + if not self.disable_fee_check and (abs_fee > self.proto.max_tx_fee): msg('{} {c}: {} fee too large (maximum fee: {} {c})'.format( abs_fee.hl(), desc, diff --git a/mmgen/proto/vm/tx/completed.py b/mmgen/proto/vm/tx/completed.py index 6e637071..1825b500 100644 --- a/mmgen/proto/vm/tx/completed.py +++ b/mmgen/proto/vm/tx/completed.py @@ -30,8 +30,5 @@ class Completed: from ....util import is_hex_str return is_hex_str(self.serialized) - def check_pubkey_scripts(self): - pass - def get_serialized_locktime(self): return None # TODO diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 29302331..92b70bba 100644 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -535,7 +535,7 @@ class New(Base): await self.set_gas() fee_hint = None desc = 'User-selected' if self.cfg.fee else 'Recommended' if fee_hint else None - if (funds_left := await self.get_funds_remaining( + if (funds_left := await self.get_funds_remaining( # sets self.usr_fee self.cfg.fee or fee_hint, outputs_sum, desc)) is not None: diff --git a/test/cmdtest_d/automount.py b/test/cmdtest_d/automount.py index 31facd84..788303cf 100644 --- a/test/cmdtest_d/automount.py +++ b/test/cmdtest_d/automount.py @@ -303,6 +303,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtest): def _alice_txbump( self, fee_opt = None, + extra_opts = [], output_args = [], bad_tx_expect = None, low_fee_fix = None, @@ -314,6 +315,7 @@ class CmdTestAutosignAutomount(CmdTestAutosignThreaded, CmdTestRegtest): t = self.spawn( 'mmgen-txbump', ['--alice', '--autosign'] + + extra_opts + ([fee_opt] if fee_opt else []) + ([] if idx is None else [str(idx)]) + output_args, diff --git a/test/cmdtest_d/base.py b/test/cmdtest_d/base.py index d760c90b..9e8c6880 100644 --- a/test/cmdtest_d/base.py +++ b/test/cmdtest_d/base.py @@ -151,3 +151,10 @@ class CmdTestBase: except ProcessLookupError: imsg(yellow(f'{pid}: no such process')) return 'ok' + + def max_tx_fee_opt(self, n): + fee_adj = { + 'btc': 1, + 'ltc': 30, + 'bch': 20} + return f'--{self.coin}-max-tx-fee={fee_adj[self.coin] * n}' diff --git a/test/cmdtest_d/main.py b/test/cmdtest_d/main.py index b2e430e3..381a1e74 100644 --- a/test/cmdtest_d/main.py +++ b/test/cmdtest_d/main.py @@ -415,11 +415,16 @@ class CmdTestMain(CmdTestBase, CmdTestShared): def txcreate_dfl_wallet(self, addrfile): return self.txcreate_common( sources = ['15'], - add_opts = ['--btc-max-tx-fee=0.005'], + add_opts = [self.max_tx_fee_opt(0.005)], add_output_args = ['data:' + 'z' * self.proto.max_op_return_data_len]) def txsign_dfl_wallet(self, txfile, pf='', save=True, has_label=False): - return self.txsign(None, txfile, save=save, has_label=has_label, dfl_wallet=True) + return self.txsign( + None, + txfile, + save = save, + has_label = has_label, + dfl_wallet = True) def passchg_dfl_wallet(self, pf): return self.passchg(wf=None, pf=pf, dfl_wallet=True) @@ -699,6 +704,7 @@ class CmdTestMain(CmdTestBase, CmdTestShared): non_mmgen_input_compressed = True, cmdline_inputs = False, single_output = False, + exit_val = None, tweaks = []): def make_input_opts(): @@ -727,14 +733,15 @@ class CmdTestMain(CmdTestBase, CmdTestShared): t = self.spawn( ('mmgen-txcreate', 'mmgen-txdo')[bool(ss_args)], - [f'--outdir={self.tmpdir}', f'--fee={self.tx_fee}', '--no-blank'] - + ([] if self.proto.cap('rbf') else ['--no-rbf']) - + add_opts - + (make_input_opts() if cmdline_inputs else []) - + self._make_txcreate_outputs(tx_data, single_output) - + add_output_args - + [tx_data[num]['addrfile'] for num in tx_data] - + ss_args) + [f'--outdir={self.tmpdir}', f'--fee={self.tx_fee}', '--no-blank'] + + ([] if self.proto.cap('rbf') else ['--no-rbf']) + + add_opts + + (make_input_opts() if cmdline_inputs else []) + + self._make_txcreate_outputs(tx_data, single_output) + + add_output_args + + [tx_data[num]['addrfile'] for num in tx_data] + + ss_args, + exit_val = exit_val) if t.expect( [('Get', 'Unsigned transac')[cmdline_inputs], r'Unable to connect to \S+'], @@ -756,6 +763,9 @@ class CmdTestMain(CmdTestBase, CmdTestShared): for num in range(1 if single_output else (len(tx_data) + 1)): t.expect('Continue anyway? (y/N): ', 'y') + if exit_val: + return t + outputs_list = [(addrs_per_wallet+1)*i + 1 for i in range(len(tx_data))] if non_mmgen_input: outputs_list.append(len(tx_data)*(addrs_per_wallet+1) + 1) @@ -775,7 +785,7 @@ class CmdTestMain(CmdTestBase, CmdTestShared): def txcreate1(self, addrfile): return self.txcreate_common( sources = ['1'], - add_opts = ['--vsize-adj=1.01', '--btc-max-tx-fee=0.005'], + add_opts = ['--vsize-adj=1.01', self.max_tx_fee_opt(0.005)], add_output_args = ['hexdata:' + 'ee' * self.proto.max_op_return_data_len]) def txsign1(self, *args, **kwargs): @@ -945,8 +955,12 @@ class CmdTestMain(CmdTestBase, CmdTestShared): args=['-H', f'{rf},{hincog_offset}', '-l', str(hincog_seedlen)]) def txsign_keyaddr(self, keyaddr_file, txfile): - t = self.spawn('mmgen-txsign', - ['-d', self.tmpdir, '-p1', '-M', keyaddr_file, txfile], no_passthru_opts=['coin']) + t = self.spawn('mmgen-txsign', [ + '-d', self.tmpdir, + '-p1', + '-M', keyaddr_file, + txfile], + no_passthru_opts = ['coin']) t.license() t.view_tx('n') t.do_decrypt_ka_data(pw=self.kapasswd) @@ -954,7 +968,10 @@ class CmdTestMain(CmdTestBase, CmdTestShared): return t def txcreate_ni(self, addrfile): - return self.txcreate_common(sources=['1'], cmdline_inputs=True, add_opts=['--yes']) + return self.txcreate_common( + sources = ['1'], + cmdline_inputs = True, + add_opts = ['--yes']) def walletgen2(self, del_dw_run='dummy'): return self.walletgen1(seed_len=128) @@ -969,8 +986,10 @@ class CmdTestMain(CmdTestBase, CmdTestShared): return self.txcreate_common(sources=['2'], single_output=True) def txsign2(self, wf1, txf1, wf2, txf2): - t = self.spawn('mmgen-txsign', - ['-d', self.tmpdir, txf1, wf1, txf2, wf2], no_passthru_opts=['coin']) + t = self.spawn('mmgen-txsign', [ + '-d', self.tmpdir, + txf1, wf1, txf2, wf2], + no_passthru_opts = ['coin']) t.license() for cnum, wf in (('1', wf1), ('2', wf2)): wcls = get_wallet_cls(ext=get_extension(wf)) diff --git a/test/cmdtest_d/shared.py b/test/cmdtest_d/shared.py index 3ae37779..2471a0b9 100644 --- a/test/cmdtest_d/shared.py +++ b/test/cmdtest_d/shared.py @@ -232,6 +232,7 @@ class CmdTestShared: expect_str = None, env = {}, view = 'n', + exit_val = None, dfl_wallet = False): opts = extra_opts + ['-d', self.tmpdir, txfile] + ([wf] if wf else []) wcls = get_wallet_cls(ext = 'mmdat' if dfl_wallet else get_extension(wf)) @@ -241,13 +242,15 @@ class CmdTestShared: extra_desc, no_passthru_opts = ['coin'], env = env, - exit_val = None if save or (wcls.enc and wcls.type != 'brain') else 1) + exit_val = exit_val or (None if save or (wcls.enc and wcls.type != 'brain') else 1)) t.license() if expect_str: t.expect(expect_str) t.view_tx(view) if wcls.enc and wcls.type != 'brain': t.passphrase(wcls.desc, self.wpasswd) + if exit_val: + return t if save: self.txsign_end(t, has_label=has_label) else: