Add constant for total Bitcoin supply
What changed, and why it matters
This commit is a simple code cleanup: it replaces two hard-coded copies of the maximum possible number of satoshis in existence with a single named constant. The actual safety check and the numeric value it compares against remain exactly the same, so there is no security change.
No action required; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces BITCOIN_TOTAL_SUPPLY in src/constants.h and uses it in src/handler/sign_psbt.c for the existing prevout_amount and output sanity checks. The expression (21000000ULL * 100000000UL) evaluates to the same 2.1e15 satoshi value as the previous inline literals. No logic, bounds, or behavior changed.
Changed components
src/constants.hsrc/handler/sign_psbt.cInspect captured patch +5 / −2
diff --git a/src/constants.h b/src/constants.h
index a01c69f..20232f8 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -126,3 +126,6 @@ _Static_assert(MAX_BIP32_PATH_STEPS == MAX_BIP32_PATH,
#define MAX_BIP44_ACCOUNT_RECOMMENDED 100
#define MAX_BIP44_ADDRESS_INDEX_RECOMMENDED 50000
+
+// Upper bound of Bitcoin's total supply in satoshis
+#define BITCOIN_TOTAL_SUPPLY (21000000ULL * 100000000UL)
diff --git a/src/handler/sign_psbt.c b/src/handler/sign_psbt.c
index 0eab8eb..471ba66 100644
--- a/src/handler/sign_psbt.c
+++ b/src/handler/sign_psbt.c
@@ -739,7 +739,7 @@ preprocess_inputs(dispatcher_context_t *dc,
}
}
- if (input.prevout_amount > 21000000ULL * 100000000ULL) {
+ if (input.prevout_amount > BITCOIN_TOTAL_SUPPLY) {
// sanity check to avoid overflows in amounts
PRINTF("Input amount exceed Bitcoin total supply!\n");
SEND_SW(dc, SW_INCORRECT_DATA);
@@ -963,7 +963,7 @@ preprocess_outputs(dispatcher_context_t *dc,
}
uint64_t value = read_u64_le(raw_result, 0);
- if (value > 21000000ULL * 100000000ULL) {
+ if (value > BITCOIN_TOTAL_SUPPLY) {
// sanity check to avoid overflows in amounts
PRINTF("Output amount exceed Bitcoin total supply!\n");
SEND_SW(dc, SW_INCORRECT_DATA);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.