Skip to content

Conversation

sipa
Copy link
Member

@sipa sipa commented Jan 25, 2020

This is a refactoring cherry-picked out of #17977. As it touches consensus code, I don't think this would ordinarily meet the bar for review cost vs benefit. However, it simplifies the changes for Taproot significantly, and if it's going to be necessitated by inclusion of that code, I may as well give it some additional attention by PRing it independently.

@sipa
Copy link
Member Author

sipa commented Jan 25, 2020

A change like this was originally suggested by @JeremyRubin here: sipa#116

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 26, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@JeremyRubin
Copy link
Contributor

I'm generally a big fan of cleaning up this consensus logic such that the code is "tree-like" and terminates at leaf branches, rather than having interleaved "dag-like" branches that merge into a common exit point. One of the key advantages of code structured in this way is it's much easier to see, at a glance, exactly how many "versions" (i.e., combinations of flags) we support. Otherwise, with N things that could either be on or off you get something like 2**N potential execution traces which makes it really hard to write tests for all flows (coverage is not enough).

It's a code style that I think we should strive to use when possible, and it makes me a bit extreme in that I go as far as to think we should re-write some other consensus logic (see #15969) to be more in line with this style.

I say the above here not to advocate for more expansive changes at this time, but more so that other reviewers can appropriately discount my ACKs here if you disagree with this viewpoint.

That this makes Taproot simpler to review and implement is a plus, but I think these changes stand on their own.

Concept ACK + lite CR-ack, untested.

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Jan 26, 2020

Code review ACK.

I like the approach of trying to get small refactors onto the codebase that can be independently reviewed to make the taproot PR more reviewable.

@Empact
Copy link
Contributor

Empact commented Jan 30, 2020

Code Review ACK 1e1e28c

Copy link
Contributor

@ajtowns ajtowns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 1e1e28c ; nits only, none of which seem worth fixing

@sipa sipa force-pushed the 202001_execute_witness branch from 1e1e28c to 139f7ff Compare February 7, 2020 03:25
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 139f7ff

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 139f7ff

A couple of nits inline.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 139f7ff mod comments

@fjahr
Copy link
Contributor

fjahr commented Feb 12, 2020

Code review ACK 139f7ff

Verified the changes are a pure refactor. Also ran test locally. I agree with both of @jnewbery s comments but can also be merged as it is right now.

This removes the unclear reliance on "falling through" to get to the
script execution part.

Also fix some code style issues.
@sipa sipa force-pushed the 202001_execute_witness branch from 139f7ff to c8e24dd Compare February 12, 2020 19:32
@sipa
Copy link
Member Author

sipa commented Feb 12, 2020

I've made a few invasive changes here, which will need re-review.

@fjahr
Copy link
Contributor

fjahr commented Feb 12, 2020

Re-ACK c8e24dd

New changes addressed the review comments.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c8e24dd

@theStack
Copy link
Contributor

re-ACK c8e24dd
Checked that since my previous ACK 139f7ff the following changes have been made:

  • s/ExecuteWitnessProgram/ExecuteWitnessScript
  • pass script stack to ExecuteWitnessScript as const_iterator pair (and create local copy)
    instead of rvalue reference
  • use range-based for loop for stack item size check
  • in success case, just return true instead of the not needed set_success(...)
  • removed the assertion for unreachable code, put the bottom part in an else-branch instead and intentionally have no return statement at the end of the function (if it is ever reached, the compiler would spit out a warning, indicating a flawed logic above)

@Empact
Copy link
Contributor

Empact commented Feb 17, 2020

Code Review Re-ACK c8e24dd

nit: could use cbegin/cend

@ajtowns
Copy link
Contributor

ajtowns commented Feb 19, 2020

ACK c8e24dd

@NicolasDorier
Copy link
Contributor

Code Review reACK

@jnewbery
Copy link
Contributor

ACK c8e24dd

@laanwj laanwj merged commit e5cb0df into bitcoin:master Mar 13, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 14, 2020
…ssProgram()

c8e24dd [REFACTOR] Abstract out script execution out of VerifyWitnessProgram() (Pieter Wuille)

Pull request description:

  This is a refactoring cherry-picked out of bitcoin#17977. As it touches consensus code, I don't think this would ordinarily meet the bar for review cost vs benefit. However, it simplifies the changes for Taproot significantly, and if it's going to be necessitated by inclusion of that code, I may as well give it some additional attention by PRing it independently.

ACKs for top commit:
  fjahr:
    Re-ACK c8e24dd
  theStack:
    re-ACK bitcoin@c8e24dd
  Empact:
    Code Review Re-ACK bitcoin@c8e24dd
  ajtowns:
    ACK c8e24dd
  jnewbery:
    ACK c8e24dd
  jonatack:
    ACK c8e24dd

Tree-SHA512: 96c2aa5d2f9c7c802bcc008f5cde55b1dfedfaf42e34101331e6c0d594acdf6437661102dc939718f0877c20451336855dfbaa8aa8f57d9e722a7fa7329e3a46
fanquake added a commit that referenced this pull request Mar 27, 2020
2b0fcff Make VerifyWitnessProgram use a Span stack (Pieter Wuille)

Pull request description:

  Here is a follow-up to #18002, again with the goal of simplifying (potential) BIP341 code.

  Instead of passing a begin and end iterator of the initial stack to `ExecuteWitnessScript`, they are turned into a `Span<const valtype>`, representing a span of `valtype`s in memory. This allows `VerifyWitnessProgram` to operate on that span directly, instead of juggling iterators around (which would be exacerbated by #17977 if trying to avoid copying the stack).

ACKs for top commit:
  ajtowns:
    ACK 2b0fcff
  elichai:
    ReACK on the diff 2b0fcff
  instagibbs:
    re-ACK 2b0fcff
  theStack:
    re-ACK 2b0fcff
  Empact:
    ACK 2b0fcff
  jnewbery:
    utACK 2b0fcff

Tree-SHA512: 38eb4ce17f1947674c1c274caa40feb6ea8266bd96134d9cf1bc41e6fbf1114d4dde6c7a9e26e1ca8f3d0155429ef0911cc8ec0c1037d8fe7d6ec7f9e7184e93
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
…ssProgram()

c8e24dd [REFACTOR] Abstract out script execution out of VerifyWitnessProgram() (Pieter Wuille)

Pull request description:

  This is a refactoring cherry-picked out of bitcoin#17977. As it touches consensus code, I don't think this would ordinarily meet the bar for review cost vs benefit. However, it simplifies the changes for Taproot significantly, and if it's going to be necessitated by inclusion of that code, I may as well give it some additional attention by PRing it independently.

ACKs for top commit:
  fjahr:
    Re-ACK c8e24dd
  theStack:
    re-ACK bitcoin@c8e24dd
  Empact:
    Code Review Re-ACK bitcoin@c8e24dd
  ajtowns:
    ACK c8e24dd
  jnewbery:
    ACK c8e24dd
  jonatack:
    ACK c8e24dd

Tree-SHA512: 96c2aa5d2f9c7c802bcc008f5cde55b1dfedfaf42e34101331e6c0d594acdf6437661102dc939718f0877c20451336855dfbaa8aa8f57d9e722a7fa7329e3a46
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.