script: remove now-unnecessary 2of2 ops.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2015-07-24 16:00:11 +09:30
parent f78ea05fc5
commit 8f0140c542
4 changed files with 0 additions and 92 deletions

View File

@ -104,36 +104,6 @@ static void add_push_sig(u8 **scriptp, const struct bitcoin_signature *sig)
#endif #endif
} }
/* FIXME: permute? */
/* Is a < b? (If equal we don't care) */
static bool key_less(const struct pubkey *a, const struct pubkey *b)
{
/* Shorter one wins. */
if (pubkey_len(a) != pubkey_len(b))
return pubkey_len(a) < pubkey_len(b);
return memcmp(a->key, b->key, pubkey_len(a)) < 0;
}
/* tal_count() gives the length of the script. */
u8 *bitcoin_redeem_2of2(const tal_t *ctx,
const struct pubkey *key1,
const struct pubkey *key2)
{
u8 *script = tal_arr(ctx, u8, 0);
add_number(&script, 2);
if (key_less(key1, key2)) {
add_push_key(&script, key1);
add_push_key(&script, key2);
} else {
add_push_key(&script, key2);
add_push_key(&script, key1);
}
add_number(&script, 2);
add_op(&script, OP_CHECKMULTISIG);
return script;
}
/* tal_count() gives the length of the script. */ /* tal_count() gives the length of the script. */
u8 *bitcoin_redeem_single(const tal_t *ctx, const struct pubkey *key) u8 *bitcoin_redeem_single(const tal_t *ctx, const struct pubkey *key)
{ {
@ -183,30 +153,6 @@ u8 *scriptsig_p2sh_single_sig(const tal_t *ctx,
return script; return script;
} }
u8 *scriptsig_p2sh_2of2(const tal_t *ctx,
const struct bitcoin_signature *sig1,
const struct bitcoin_signature *sig2,
const struct pubkey *key1,
const struct pubkey *key2)
{
u8 *script = tal_arr(ctx, u8, 0);
u8 *redeemscript;
/* OP_CHECKMULTISIG has an out-by-one bug, which MBZ */
add_number(&script, 0);
/* sig order should match key order. */
if (key_less(key1, key2)) {
add_push_sig(&script, sig1);
add_push_sig(&script, sig2);
} else {
add_push_sig(&script, sig2);
add_push_sig(&script, sig1);
}
redeemscript = bitcoin_redeem_2of2(script, key1, key2);
add_push_bytes(&script, redeemscript, tal_count(redeemscript));
return script;
}
/* Is this a normal pay to pubkey hash? */ /* Is this a normal pay to pubkey hash? */
bool is_pay_to_pubkey_hash(const u8 *script, size_t script_len) bool is_pay_to_pubkey_hash(const u8 *script, size_t script_len)
{ {

View File

@ -15,11 +15,6 @@ struct bitcoin_signature {
enum sighash_type stype; enum sighash_type stype;
}; };
/* tal_count() gives the length of the script. */
u8 *bitcoin_redeem_2of2(const tal_t *ctx,
const struct pubkey *key1,
const struct pubkey *key2);
/* tal_count() gives the length of the script. */ /* tal_count() gives the length of the script. */
u8 *bitcoin_redeem_single(const tal_t *ctx, const struct pubkey *key); u8 *bitcoin_redeem_single(const tal_t *ctx, const struct pubkey *key);
@ -48,13 +43,6 @@ u8 *scriptsig_pay_to_pubkeyhash(const tal_t *ctx,
const struct pubkey *key, const struct pubkey *key,
const struct bitcoin_signature *sig); const struct bitcoin_signature *sig);
/* Create an input script to accept pay to pubkey */
u8 *scriptsig_p2sh_2of2(const tal_t *ctx,
const struct bitcoin_signature *sig1,
const struct bitcoin_signature *sig2,
const struct pubkey *key1,
const struct pubkey *key2);
/* Create an input script to spend anchor output (commit version). */ /* Create an input script to spend anchor output (commit version). */
u8 *scriptsig_p2sh_anchor_commit(const tal_t *ctx, u8 *scriptsig_p2sh_anchor_commit(const tal_t *ctx,
const struct bitcoin_signature *their_sig, const struct bitcoin_signature *their_sig,

View File

@ -198,26 +198,6 @@ bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num,
return ret; return ret;
} }
bool check_2of2_sig(struct bitcoin_tx *tx, size_t input_num,
const u8 *redeemscript, size_t redeemscript_len,
const struct pubkey *key1, const struct pubkey *key2,
const struct bitcoin_signature *sig1,
const struct bitcoin_signature *sig2)
{
struct sha256_double hash;
assert(input_num < tx->input_count);
sha256_tx_one_input(tx, input_num, redeemscript, redeemscript_len,
&hash);
/* We only use SIGHASH_ALL for the moment. */
if (sig1->stype != SIGHASH_ALL || sig2->stype != SIGHASH_ALL)
return false;
return check_signed_hash(&hash, &sig1->sig, key1)
&& check_signed_hash(&hash, &sig2->sig, key2);
}
/* Stolen direct from bitcoin/src/script/sign.cpp: /* Stolen direct from bitcoin/src/script/sign.cpp:
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2009-2014 The Bitcoin Core developers

View File

@ -40,12 +40,6 @@ bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num,
const struct pubkey *key, const struct pubkey *key,
const struct bitcoin_signature *sig); const struct bitcoin_signature *sig);
bool check_2of2_sig(struct bitcoin_tx *tx, size_t input_num,
const u8 *redeemscript, size_t redeemscript_len,
const struct pubkey *key1, const struct pubkey *key2,
const struct bitcoin_signature *sig1,
const struct bitcoin_signature *sig2);
/* Signature must have low S value. */ /* Signature must have low S value. */
bool sig_valid(const struct signature *s); bool sig_valid(const struct signature *s);