Skip to content

fix: accept an explicit fee of 0 - #79

Closed
SafraNako wants to merge 1 commit into
theQRL:masterfrom
SafraNako:fix/accept-zero-fee
Closed

SafraNako wants to merge 1 commit into
theQRL:masterfrom
SafraNako:fix/accept-zero-fee

Conversation

@SafraNako

Copy link
Copy Markdown

Problem

The fee parser in the spending commands is:

let fee = 0 // (send / send-message / generate-lattice-keys) or 100 (sign-tx-offline)
if (flags.fee) {
  const passedFee = parseInt(flags.fee, 10)
  if (passedFee) {
    fee = passedFee
  } else {
    this.log(`${red('⨉')} Fee is invalid`)
    this.exit(1)
  }
}

parseInt('0', 10) is 0, which is falsy, so if (passedFee) sends a
zero fee down the "invalid" branch. Result: -f 0 is rejected on send,
send-message, notarize, generate-lattice-keys and sign-tx-offline
— even though 0 is exactly the fee these commands use when -f is
omitted, and the node accepts any fee >= 0.

$ ./bin/run send 1 -r Q0002... -h "<hexseed>" -i 1 -f 0 -T tx.json -t
Transaction details:
⨉ Fee is invalid          # exit 1, nothing written

$ ./bin/run send 1 -r Q0002... -h "<hexseed>" -i 1     -T tx.json -t
Fee: 0 Shor               # exit 0 — same value, omitted, works

The otsindex check a few lines above already gets this right
(if (!passedOts && passedOts !== 0)).

Fix

Reject only a non-numeric or negative fee:

if (Number.isNaN(passedFee) || passedFee < 0) { ... exit(1) }
fee = passedFee

-f abc, -f .01, -f -5 still fail exactly as before; -f 0 now
works. Also corrected the "defaults to 100 Shor" flag text on
send / send-message / generate-lattice-keys, which initialise
fee = 0 (sign-tx-offline keeps its genuine 100 default).

Tests

test/commands/send.test.js gains send #3c: an offline
send -f 0 -T <file> run that must exit 0 and write a transaction
whose fee is "0". Verified against the offline suite
(QRL_TEST_OFFLINE=true); npm run lint clean.

🤖 Generated with Claude Code

`if (passedFee) { fee = passedFee } else { "Fee is invalid"; exit(1) }`
treats `parseInt('0', 10)` (a valid zero fee) the same as a garbage
value, so `qrl send -f 0`, `send-message -f 0`, `notarize -f 0`,
`generate-lattice-keys -f 0` and `sign-tx-offline -f 0` all abort with
"Fee is invalid" — even though 0 is exactly the default the commands use
when `-f` is omitted (the node accepts any fee >= 0).

Reject only a non-numeric or negative value (`Number.isNaN(passedFee) ||
passedFee < 0`); `-f abc` / `-f .01` / `-f -5` still fail as before.

Also fix the stale "defaults to 100 Shor" text on send / send-message /
generate-lattice-keys — those initialise `fee = 0`. sign-tx-offline
keeps its real 100 default.

Adds an offline `send #3c` regression test: `send -f 0 -T <file>` exits 0
and writes a transaction whose `fee` is "0".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jplomas

jplomas commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks, this PR crosses with some fork work which closes this issue. Thank you for your contribution.

@jplomas jplomas closed this Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants