Skip to content

Commit

Permalink
client/clmscript: fix errors in witness size estimation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Roasbeef committed Mar 10, 2020
1 parent 18d4ffb commit dd39460
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions client/clmscript/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// - <trader_sig>: 73 bytes
// - OP_DATA: 1 byte (auctioneer_sig length)
// - auctioneer_sig_varint_len: 1 byte
// - <auctioneer_sig>: 73 bytes
// - witness_script_varint_len: 1 byte
// - <witness_script>: 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)
// - <trader_sig>: 73 bytes
// - OP_DATA: 1 byte (nil length)
// - witness_script_varint_len: 1 byte (nil length)
// - <witness_script>: 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
Expand Down

0 comments on commit dd39460

Please sign in to comment.