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.
This commit is contained in:
Wilmer Paulino 2020-01-24 15:28:23 -08:00
parent 4021b2919c
commit 4930da65b0

View file

@ -36,15 +36,9 @@ func TraderKeyTweak(batchKey *btcec.PublicKey, secret [32]byte,
// AccountScript returns the witness script of an account on-chain.
//
// OP_IF
// <account expiry>
// OP_CHECKLOCKTIMEVERIFY
// OP_DROP
// <trader key>
// OP_CHECKSIG
// OP_ELSE
// OP_2 <trader key> <auctioneer key> OP_2
// OP_CHECKMULTISIG
// <trader_key> OP_CHECKSIGVERIFY
// <auctioneer_key> OP_CHECKSIG OP_IFDUP OP_NOTIF
// <account_expiry> 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()