Browse Source

bitcoin/script: support variants where we only have the ripemd.

For space saving, we only keep the ripemd160 for old HTLCs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
af9d763763
  1. 44
      bitcoin/script.c
  2. 14
      bitcoin/script.h

44
bitcoin/script.c

@ -708,10 +708,10 @@ u8 **bitcoin_to_local_spend_revocation(const tal_t *ctx,
* OP_ENDIF * OP_ENDIF
* OP_ENDIF * OP_ENDIF
*/ */
u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx, u8 *bitcoin_wscript_htlc_offer_ripemd160(const tal_t *ctx,
const struct pubkey *localkey, const struct pubkey *localkey,
const struct pubkey *remotekey, const struct pubkey *remotekey,
const struct sha256 *payment_hash, const struct ripemd160 *payment_ripemd,
const struct pubkey *revocationkey) const struct pubkey *revocationkey)
{ {
u8 *script = tal_arr(ctx, u8, 0); u8 *script = tal_arr(ctx, u8, 0);
@ -739,8 +739,8 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
add_op(&script, OP_CHECKMULTISIG); add_op(&script, OP_CHECKMULTISIG);
add_op(&script, OP_ELSE); add_op(&script, OP_ELSE);
add_op(&script, OP_HASH160); add_op(&script, OP_HASH160);
ripemd160(&ripemd, payment_hash->u.u8, sizeof(payment_hash->u)); add_push_bytes(&script,
add_push_bytes(&script, ripemd.u.u8, sizeof(ripemd.u.u8)); payment_ripemd->u.u8, sizeof(payment_ripemd->u.u8));
add_op(&script, OP_EQUALVERIFY); add_op(&script, OP_EQUALVERIFY);
add_op(&script, OP_CHECKSIG); add_op(&script, OP_CHECKSIG);
add_op(&script, OP_ENDIF); add_op(&script, OP_ENDIF);
@ -749,6 +749,19 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
return script; return script;
} }
u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
const struct pubkey *localkey,
const struct pubkey *remotekey,
const struct sha256 *payment_hash,
const struct pubkey *revocationkey)
{
struct ripemd160 ripemd;
ripemd160(&ripemd, payment_hash->u.u8, sizeof(payment_hash->u));
return bitcoin_wscript_htlc_offer_ripemd160(ctx, localkey, remotekey,
&ripemd, revocationkey);
}
/* BOLT #3: /* BOLT #3:
* *
* #### Received HTLC Outputs * #### Received HTLC Outputs
@ -775,11 +788,11 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
* OP_ENDIF * OP_ENDIF
* OP_ENDIF * OP_ENDIF
*/ */
u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx, u8 *bitcoin_wscript_htlc_receive_ripemd(const tal_t *ctx,
const struct abs_locktime *htlc_abstimeout, const struct abs_locktime *htlc_abstimeout,
const struct pubkey *localkey, const struct pubkey *localkey,
const struct pubkey *remotekey, const struct pubkey *remotekey,
const struct sha256 *payment_hash, const struct ripemd160 *payment_ripemd,
const struct pubkey *revocationkey) const struct pubkey *revocationkey)
{ {
u8 *script = tal_arr(ctx, u8, 0); u8 *script = tal_arr(ctx, u8, 0);
@ -800,8 +813,8 @@ u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
add_op(&script, OP_EQUAL); add_op(&script, OP_EQUAL);
add_op(&script, OP_IF); add_op(&script, OP_IF);
add_op(&script, OP_HASH160); add_op(&script, OP_HASH160);
ripemd160(&ripemd, payment_hash->u.u8, sizeof(payment_hash->u)); add_push_bytes(&script,
add_push_bytes(&script, ripemd.u.u8, sizeof(ripemd.u.u8)); payment_ripemd->u.u8, sizeof(payment_ripemd->u.u8));
add_op(&script, OP_EQUALVERIFY); add_op(&script, OP_EQUALVERIFY);
add_number(&script, 2); add_number(&script, 2);
add_op(&script, OP_SWAP); add_op(&script, OP_SWAP);
@ -820,6 +833,21 @@ u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
return script; return script;
} }
u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
const struct abs_locktime *htlc_abstimeout,
const struct pubkey *localkey,
const struct pubkey *remotekey,
const struct sha256 *payment_hash,
const struct pubkey *revocationkey)
{
struct ripemd160 ripemd;
ripemd160(&ripemd, payment_hash->u.u8, sizeof(payment_hash->u));
return bitcoin_wscript_htlc_receive_ripemd(ctx, htlc_abstimeout,
localkey, remotekey,
&ripemd, revocationkey);
}
/* BOLT #3: /* BOLT #3:
* *
* ## HTLC-Timeout and HTLC-Success Transactions * ## HTLC-Timeout and HTLC-Success Transactions

14
bitcoin/script.h

@ -11,6 +11,7 @@ struct bitcoin_tx_input;
struct preimage; struct preimage;
struct pubkey; struct pubkey;
struct sha256; struct sha256;
struct ripemd160;
struct rel_locktime; struct rel_locktime;
struct abs_locktime; struct abs_locktime;
@ -141,6 +142,19 @@ u8 **bitcoin_htlc_receive_spend_preimage(const tal_t *ctx,
const struct preimage *preimage, const struct preimage *preimage,
const u8 *wscript); const u8 *wscript);
/* Underlying functions for penalties, where we only keep ripemd160 */
u8 *bitcoin_wscript_htlc_offer_ripemd160(const tal_t *ctx,
const struct pubkey *localkey,
const struct pubkey *remotekey,
const struct ripemd160 *payment_ripemd,
const struct pubkey *revocationkey);
u8 *bitcoin_wscript_htlc_receive_ripemd(const tal_t *ctx,
const struct abs_locktime *htlc_abstimeout,
const struct pubkey *localkey,
const struct pubkey *remotekey,
const struct ripemd160 *payment_ripemd,
const struct pubkey *revocationkey);
/* BOLT #3 HTLC-success/HTLC-timeout output */ /* BOLT #3 HTLC-success/HTLC-timeout output */
u8 *bitcoin_wscript_htlc_tx(const tal_t *ctx, u8 *bitcoin_wscript_htlc_tx(const tal_t *ctx,
u16 to_self_delay, u16 to_self_delay,

Loading…
Cancel
Save