The scriptSig when evaluated populates the stack so opcodes can operate on them. A witness is essentially a list of data elements, quite similar to the script stack (the witness is passed in as the script stack in fact)
OP_0 when evaluated pushes a _zero length_ value onto the stack, hence the 00 (the varlen) in the witness serialization. OP_1 (51 in decimal) pushes 0x01 to the stack, so when serialized would be 0101. It may help to consider the entire witness structure as vector<vector<data element>> and it's length must equal the number of inputs - so a non-segwit input must have a zero sized witness. On 5/26/19 12:56 AM, Aymeric Vitte via bitcoin-dev wrote: > I realized recently that my segwit implementation was not correct, > basically some time ago, wrongly reading the specs (and misleaded by > what follows), I thought that scriptsig would go into witness data as it > was, but that's not the case, op_pushdata is replaced by varlen > > Now reading correctly the specs, they seem to be not totally correct, > then the first question is: why OP_0 is 00 in witness data and not 0100? > Does this apply to other op_codes? This does not look logical at all > > The second question is: why for non segwit inputs there is a 00 length > in segwit data, what is the rational for that? It should just be nothing > since you don't need this to reconciliate things > > _______________________________________________ > bitcoin-dev mailing list > bitcoin-dev@lists.linuxfoundation.org > https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev _______________________________________________ bitcoin-dev mailing list bitcoin-dev@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev