whitespace, comments, minor fixes

This commit is contained in:
The MMGen Project 2026-11-29 17:04:40 +00:00
commit 39f82f771b
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
14 changed files with 68 additions and 38 deletions

View file

@ -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

View file

@ -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'),

View file

@ -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

View file

@ -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

View file

@ -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(),

View file

@ -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

View file

@ -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)

View file

@ -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,

View file

@ -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

View file

@ -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:

View file

@ -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,

View file

@ -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}'

View file

@ -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))

View file

@ -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: