From 369ea2aa8e3837fc415720d6f3367fe00b27fce3 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 8 Mar 2020 14:59:15 -0700 Subject: [PATCH] client/clmscript: fix errors in witness size estimation In this commit, we fix a few lingering errors in witness size estimation. Both the witness paths were missing a single byte that signals the number of witness elements. We also convert the OP_DATAs in the witness script to a varint length, as that more accurately reflects the way the field is interpreted, as we provide the witness stack as is, rather than pushing elements onto the stack as if it were a sigScript. Finally, we add a missing byte for the size of the witness script itself. --- clmscript/script.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/clmscript/script.go b/clmscript/script.go index c748d37..37fd01d 100644 --- a/clmscript/script.go +++ b/clmscript/script.go @@ -34,19 +34,22 @@ const ( AccountWitnessScriptSize = 1 + 33 + 1 + 1 + 33 + 1 + 1 + 1 + 1 + 4 + 1 + 1 // MultiSigWitnessSize: 227 bytes - // - OP_DATA: 1 byte (trader_sig length) + // - num_witness_elements: 1 byte + // - trader_sig_varint_len: 1 byte // - : 73 bytes - // - OP_DATA: 1 byte (auctioneer_sig length) + // - auctioneer_sig_varint_len: 1 byte // - : 73 bytes + // - witness_script_varint_len: 1 byte // - : 79 bytes - MultiSigWitnessSize = 1 + 73 + 1 + 73 + AccountWitnessScriptSize + MultiSigWitnessSize = 1 + 1 + 73 + 1 + 73 + 1 + AccountWitnessScriptSize // ExpiryWitnessSize: 154 bytes - // - OP_DATA: 1 byte (trader_sig length) + // - num_witness_elements: 1 byte + // - trader_sig_varint_len: 1 byte (trader_sig length) // - : 73 bytes - // - OP_DATA: 1 byte (nil length) + // - witness_script_varint_len: 1 byte (nil length) // - : 79 bytes - ExpiryWitnessSize = 1 + 73 + 1 + AccountWitnessScriptSize + ExpiryWitnessSize = 1 + 1 + 73 + 1 + AccountWitnessScriptSize ) // TraderKeyTweak computes the tweak based on the current per-batch key and