From 8f0140c542e6cbc70de5f061e4e28ceeca95a0c6 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 24 Jul 2015 16:00:11 +0930 Subject: [PATCH] script: remove now-unnecessary 2of2 ops. Signed-off-by: Rusty Russell --- bitcoin/script.c | 54 --------------------------------------------- bitcoin/script.h | 12 ---------- bitcoin/signature.c | 20 ----------------- bitcoin/signature.h | 6 ----- 4 files changed, 92 deletions(-) diff --git a/bitcoin/script.c b/bitcoin/script.c index 7b342d463..c7c0f1865 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -104,36 +104,6 @@ static void add_push_sig(u8 **scriptp, const struct bitcoin_signature *sig) #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. */ 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; } -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? */ bool is_pay_to_pubkey_hash(const u8 *script, size_t script_len) { diff --git a/bitcoin/script.h b/bitcoin/script.h index 2bf47ba96..798842024 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -15,11 +15,6 @@ struct bitcoin_signature { 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. */ 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 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). */ u8 *scriptsig_p2sh_anchor_commit(const tal_t *ctx, const struct bitcoin_signature *their_sig, diff --git a/bitcoin/signature.c b/bitcoin/signature.c index 34fb48a61..e6c6b7ed9 100644 --- a/bitcoin/signature.c +++ b/bitcoin/signature.c @@ -198,26 +198,6 @@ bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num, 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: // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers diff --git a/bitcoin/signature.h b/bitcoin/signature.h index 34692f539..e0c56e09e 100644 --- a/bitcoin/signature.h +++ b/bitcoin/signature.h @@ -40,12 +40,6 @@ bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num, const struct pubkey *key, 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. */ bool sig_valid(const struct signature *s);