Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIP 325: Clarify that scriptWitness is a stack, not a byte string #978

Merged
merged 1 commit into from
Oct 5, 2020
Merged

BIP 325: Clarify that scriptWitness is a stack, not a byte string #978

merged 1 commit into from
Oct 5, 2020

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Aug 22, 2020

Strictly speaking the bip isn't wrong. It just happens that an empty byte vector is serialized identical to an empty vector of any other type, but it takes the reader an extra step. Thus, the minor fixup suggestion.

@gmaxwell
Copy link
Contributor

Is it leaking Bitcoin Core implementation details into the document to bring up vectors here? The word 'vector' isn't otherwise in this BIP.

Wouldn't it just be accurate to make it say that it's encoded just like BIP141? The compactsize count followed by the items (if there are any) is just how vectors in the software get encoded.

It just happens that an empty byte vector is serialized identical to an empty vector of any other type, but it takes the reader an extra step. Thus, the minor fixup suggestion.
@maflcko
Copy link
Member Author

maflcko commented Aug 22, 2020

Wouldn't it just be accurate to make it say that it's encoded just like BIP141?

Jup. Thx & done

@maflcko
Copy link
Member Author

maflcko commented Aug 25, 2020

cc @kallewoof

@kallewoof
Copy link
Contributor

ACK

Please merge at your convenience (ping @luke-jr).

@ajtowns
Copy link
Contributor

ajtowns commented Sep 3, 2020

Huh? An empty vector of any type is serialised as a 1-byte block where that byte is \x00 (indicating the size of the vector is zero), the text of the BIP and the corresponding code currently has it serialized as a 0-byte block. Unless I'm missing something, this is a change, not a clarification

@maflcko
Copy link
Member Author

maflcko commented Sep 3, 2020

Currently the serializer can choose whether to serialize it as a 0-byte-block or a 1-byte-block (\x00). Is there any reason to allow this freedom and require implementations to deal with the edge case?

@ajtowns
Copy link
Contributor

ajtowns commented Sep 3, 2020

Hmm, I thought there was code that would error out in the 1-byte-\x00 case, but doesn't look like there ever was. Don't think there's any reason for the freedom; the intent was just to save a byte in every block when you don't need witness data. Changing this would require a chain restart of the current default signet I believe.

@kallewoof
Copy link
Contributor

kallewoof commented Sep 3, 2020

I'm not sure why it would require a reset since the default signet doesn't accept empty witnesses. (It does; I thought we used the witness, not the scriptSig.)

@maflcko
Copy link
Member Author

maflcko commented Sep 3, 2020

If a reset is needed can be tested by running a reindex with the following diff:

- if (!v.empty()) v >> tx_spending.vin[0].scriptWitness.stack;
+ v >> tx_spending.vin[0].scriptWitness.stack;

@kallewoof
Copy link
Contributor

Thanks - yeah, it fails as we're using the scriptSig, not the scriptWitness. Alas.

@ajtowns
Copy link
Contributor

ajtowns commented Sep 5, 2020

I think there's a problem with signet's difficulty adjustments that requires a chain restart, so I think that makes the code simplification (at the cost of an extra byte per block) worthwile.

@ajtowns
Copy link
Contributor

ajtowns commented Sep 8, 2020

ACK, the code PR has been updated to match this change

@kallewoof
Copy link
Contributor

ACK, ping @luke-jr

@luke-jr luke-jr merged commit c4c4077 into bitcoin:master Oct 5, 2020
@maflcko maflcko deleted the patch-1 branch November 17, 2021 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants