From 4930da65b0ac082020fc32cc41b537bca941e299 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 24 Jan 2020 15:28:23 -0800 Subject: [PATCH] clmscript: use more efficient script construction for accounts The new construction saves about 35 bytes over the existing one. The reduction in size comes from only encoding each public key (the trader's and auctioneer's) once and not using the extra opcodes for OP_CHECKMULTISIG. --- clmscript/script.go | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/clmscript/script.go b/clmscript/script.go index c8c0e80..62b3cbd 100644 --- a/clmscript/script.go +++ b/clmscript/script.go @@ -36,15 +36,9 @@ func TraderKeyTweak(batchKey *btcec.PublicKey, secret [32]byte, // AccountScript returns the witness script of an account on-chain. // -// OP_IF -// -// OP_CHECKLOCKTIMEVERIFY -// OP_DROP -// -// OP_CHECKSIG -// OP_ELSE -// OP_2 OP_2 -// OP_CHECKMULTISIG +// OP_CHECKSIGVERIFY +// OP_CHECKSIG OP_IFDUP OP_NOTIF +// OP_CHECKLOCKTIMEVERIFY // OP_ENDIF func AccountScript(expiry uint32, traderKey, auctioneerKey, batchKey *btcec.PublicKey, secret [32]byte) ([]byte, error) { @@ -55,22 +49,16 @@ func AccountScript(expiry uint32, traderKey, auctioneerKey, builder := txscript.NewScriptBuilder() - builder.AddOp(txscript.OP_IF) - - builder.AddInt64(int64(expiry)) - builder.AddOp(txscript.OP_CHECKLOCKTIMEVERIFY) - builder.AddOp(txscript.OP_DROP) builder.AddData(tweakedTraderKey.SerializeCompressed()) + builder.AddOp(txscript.OP_CHECKSIGVERIFY) + + builder.AddData(tweakedAuctioneerKey.SerializeCompressed()) builder.AddOp(txscript.OP_CHECKSIG) - builder.AddOp(txscript.OP_ELSE) - - builder.AddOp(txscript.OP_2) - builder.AddData(tweakedTraderKey.SerializeCompressed()) - builder.AddData(tweakedAuctioneerKey.SerializeCompressed()) - builder.AddOp(txscript.OP_2) - builder.AddOp(txscript.OP_CHECKMULTISIG) - + builder.AddOp(txscript.OP_IFDUP) + builder.AddOp(txscript.OP_NOTIF) + builder.AddInt64(int64(expiry)) + builder.AddOp(txscript.OP_CHECKLOCKTIMEVERIFY) builder.AddOp(txscript.OP_ENDIF) script, err := builder.Script()