Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bitcoin/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ static bool sig_has_low_r(const secp256k1_ecdsa_signature* sig)
return compact_sig[0] < 0x80;
}

#if DEVELOPER
/* Some of the spec test vectors assume no sig grinding. */
extern bool dev_no_grind;

bool dev_no_grind = false;
#endif

void sign_hash(const struct privkey *privkey,
const struct sha256_double *h,
secp256k1_ecdsa_signature *s)
Expand All @@ -106,8 +113,13 @@ void sign_hash(const struct privkey *privkey,
ok = secp256k1_ecdsa_sign(secp256k1_ctx,
s,
h->sha.u.u8,
privkey->secret.data, NULL, extra_entropy);
privkey->secret.data, NULL,
IFDEV(dev_no_grind ? NULL
: extra_entropy,
extra_entropy));
((u32 *)extra_entropy)[0]++;
if (IFDEV(dev_no_grind, false))
break;
} while (!sig_has_low_r(s));

assert(ok);
Expand Down
26 changes: 12 additions & 14 deletions channeld/commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static void add_offered_htlc_out(struct bitcoin_tx *tx, size_t n,
option_anchor_outputs);
p2wsh = scriptpubkey_p2wsh(tx, wscript);
bitcoin_tx_add_output(tx, p2wsh, wscript, amount);
SUPERVERBOSE("# HTLC %" PRIu64 " offered %s wscript %s\n", htlc->id,
type_to_string(tmpctx, struct amount_sat, &amount),
SUPERVERBOSE("# HTLC #%" PRIu64 " offered amount %"PRIu64" wscript %s\n", htlc->id,
amount.satoshis, /* Raw: BOLT 3 output match */
tal_hex(wscript, wscript));
tal_free(wscript);
}
Expand All @@ -75,10 +75,9 @@ static void add_received_htlc_out(struct bitcoin_tx *tx, size_t n,

bitcoin_tx_add_output(tx, p2wsh, wscript, amount);

SUPERVERBOSE("# HTLC %"PRIu64" received %s wscript %s\n",
SUPERVERBOSE("# HTLC #%"PRIu64" received amount %"PRIu64" wscript %s\n",
htlc->id,
type_to_string(tmpctx, struct amount_sat,
&amount),
amount.satoshis, /* Raw: BOLT 3 output match */
tal_hex(wscript, wscript));
tal_free(wscript);
}
Expand Down Expand Up @@ -138,8 +137,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
base_fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
option_anchor_outputs);

SUPERVERBOSE("# base commitment transaction fee = %s\n",
type_to_string(tmpctx, struct amount_sat, &base_fee));
SUPERVERBOSE("# base commitment transaction fee = %"PRIu64"\n",
base_fee.satoshis /* Raw: spec uses raw numbers */);

/* BOLT #3:
* If `option_anchor_outputs` applies to the commitment
Expand Down Expand Up @@ -168,9 +167,9 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
option_anchor_outputs, side))
ok &= amount_sat_add(&out, out, amount_msat_to_sat_round_down(htlcs[i]->amount));
}
if (amount_msat_greater_sat(self_pay, dust_limit))
if (amount_msat_greater_eq_sat(self_pay, dust_limit))
ok &= amount_sat_add(&out, out, amount_msat_to_sat_round_down(self_pay));
if (amount_msat_greater_sat(other_pay, dust_limit))
if (amount_msat_greater_eq_sat(other_pay, dust_limit))
ok &= amount_sat_add(&out, out, amount_msat_to_sat_round_down(other_pay));
assert(ok);
SUPERVERBOSE("# actual commitment transaction fee = %"PRIu64"\n",
Expand Down Expand Up @@ -244,8 +243,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
(*htlcmap)[n] = direct_outputs ? dummy_to_local : NULL;
/* We don't assign cltvs[n]: if we use it, order doesn't matter.
* However, valgrind will warn us something wierd is happening */
SUPERVERBOSE("# to-local amount %s wscript %s\n",
type_to_string(tmpctx, struct amount_sat, &amount),
SUPERVERBOSE("# to_local amount %"PRIu64" wscript %s\n",
amount.satoshis, /* Raw: BOLT 3 output match */
tal_hex(tmpctx, wscript));
n++;
to_local = true;
Expand Down Expand Up @@ -287,9 +286,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
(*htlcmap)[n] = direct_outputs ? dummy_to_remote : NULL;
/* We don't assign cltvs[n]: if we use it, order doesn't matter.
* However, valgrind will warn us something wierd is happening */
SUPERVERBOSE("# to-remote amount %s key %s\n",
type_to_string(tmpctx, struct amount_sat,
&amount),
SUPERVERBOSE("# to_remote amount %"PRIu64" P2WPKH(%s)\n",
amount.satoshis, /* Raw: BOLT 3 output match */
type_to_string(tmpctx, struct pubkey,
&keyset->other_payment_key));
n++;
Expand Down
Loading