public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: Thomas Kerin <me@thomaskerin•io>
To: bitcoin-dev@lists•linuxfoundation.org, vitteaymeric@gmail•com
Subject: Re: [bitcoin-dev] Two questions about segwit implementation
Date: Sun, 26 May 2019 20:34:55 +0100	[thread overview]
Message-ID: <cbd7d991-ad8d-e311-661f-e93f05171522@thomaskerin.io> (raw)
In-Reply-To: <e537e781-e10f-7299-fddb-67fab74124c0@gmail.com>

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


  parent reply	other threads:[~2019-05-26 19:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-25 23:56 Aymeric Vitte
2019-05-26 14:33 ` Johnson Lau
2019-05-26 16:18   ` Aymeric Vitte
2019-05-26 16:28     ` Johnson Lau
2019-05-26 17:09       ` Aymeric Vitte
2019-05-26 17:24         ` Johnson Lau
2019-05-26 21:17           ` Aymeric Vitte
2019-05-26 17:54 ` Pieter Wuille
2019-05-26 19:34 ` Thomas Kerin [this message]
2019-05-27  7:26 ` Kostas Karasavvas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cbd7d991-ad8d-e311-661f-e93f05171522@thomaskerin.io \
    --to=me@thomaskerin$(echo .)io \
    --cc=bitcoin-dev@lists$(echo .)linuxfoundation.org \
    --cc=vitteaymeric@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox