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

Break up script/standard.{h/cpp} #28244

Merged
merged 9 commits into from Aug 17, 2023
Merged

Conversation

achow101
Copy link
Member

@achow101 achow101 commented Aug 9, 2023

Some future work needs to touch things in script/standard.{h/cpp}, however it is unclear if it is safe to do so as they are included in several different places that could effect standardness and consensus. It contains a mix of policy parameters, consensus parameters, and utilities only used by the wallet. This PR breaks up the various components and renames the files to clearly separate everything.

  • CTxDestination is moved to a new file src/addresstype.{cpp/h}
  • TaprootSpendData and TaprootBuilder (and their utility functions and structs) are moved to SigningProvider as these are used only during signing.
  • CScriptID is moved to script/script.h to be next to CScript.
  • MANDATORY_SCRIPT_VERIFY_FLAGS is moved to interpreter.h
  • The parameters DEFAULT_ACCEPT_DATACARRIER and MAX_OP_RETURN_RELAY are moved to policy.h
  • standard.{cpp/h} is renamed to solver.{cpp/h} since that's all that's left in the file after the above moves

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 9, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Sjors, MarcoFalke, murchandamus, ajtowns, darosior, theStack
Concept ACK ariard, russeree

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #bitcoin-core/gui/650 (Add Import to Wallet GUI by KolbyML)
  • #28230 (rpc: Add Arg() default helper by MarcoFalke)
  • #28200 (refactor: Remove unused includes from wallet.cpp by MarcoFalke)
  • #28193 (test: add script compression coverage for not-on-curve P2PK outputs by theStack)
  • #28122 (Silent Payments: Implement BIP352 by josibake)
  • #27926 (policy: make unstructured annex standard by joostjager)
  • #27850 (test: Add unit & functional test coverage for blockstore by pinheadmz)
  • #27260 (Enhanced error messages for invalid network prefix during address parsing. by russeree)
  • #26573 (Wallet: don't underestimate the fees when spending a Taproot output by darosior)
  • #26567 (Wallet: estimate the size of signed inputs using descriptors by darosior)
  • #26403 (policy: Ephemeral anchors by instagibbs)
  • #26291 (Update MANDATORY_SCRIPT_VERIFY_FLAGS by ajtowns)
  • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky)
  • #24128 (wallet: BIP 326 sequence based anti-fee-snipe for taproot inputs by MarcoFalke)
  • #21283 (Implement BIP 370 PSBTv2 by achow101)

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.

src/script/solver.h Outdated Show resolved Hide resolved
Copy link
Member

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Concept ACK

*
* @param[in] scriptPubKey Script to parse
* @param[out] vSolutionsRet Vector of parsed pubkeys and hashes
* @return The script type. TxoutType::NONSTANDARD represents a failed solve.
Copy link
Member

Choose a reason for hiding this comment

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

It could be noted what represents a “failed solve” is up to the caller. Actually TxoutType::WITNESS_UNKNOWN is considered as a failure in AreInputsStandard, as witness unknown is a special case of non-standardness for undefined segwit output.

Copy link
Member Author

Choose a reason for hiding this comment

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

leaving as is since it is only moved.

Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

ACK 3a6e49e

TBH, I’m not super familiar with the files that are being touched, but I verified that it’s almost exclusively code moves, and looked over the minuscule other changes (like adding and removing includes, extracting something into a function).

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

Concept ACK

However 34aca2d seems to move in the exact opposite direction of #26291. Thoughts @ajtowns & @instagibbs? We can easy move that constant again though.

Otherwise code review ACK 3a6e49e.

I dream of a future where validation.cpp is split between consensus and policy (and the former doesn't depend on policy.h).

What do kernel folks think of this separation? cc @TheCharlatan

Nit: maybe rename addresstype.{h,cpp} to address_type.

Did you use some script for b3af9ce?

src/script/script.h Outdated Show resolved Hide resolved
src/script/solver.h Show resolved Hide resolved
@@ -17,7 +17,6 @@
typedef std::vector<unsigned char> valtype;

CScriptID::CScriptID(const CScript& in) : BaseHash(Hash160(in)) {}
CScriptID::CScriptID(const ScriptHash& in) : BaseHash(static_cast<uint160>(in)) {}

ScriptHash::ScriptHash(const CScript& in) : BaseHash(Hash160(in)) {}
Copy link
Member

Choose a reason for hiding this comment

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

582708b: Note to other reviewers: we don't want to move ScriptHash into script.h because it has no business in consensusland. Since the constructor here needs ScriptHash, dropping it avoids the circular dependency.

src/script/standard.h Outdated Show resolved Hide resolved
@Sjors
Copy link
Member

Sjors commented Aug 10, 2023

Maybe cherry-pick 461259c instead of 34aca2d. Seems to compile and pass all tests.

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.

Approach ACK

src/script/interpreter.h Outdated Show resolved Hide resolved
src/script/standard.h Outdated Show resolved Hide resolved
src/wallet/rpc/coins.cpp Outdated Show resolved Hide resolved
src/interfaces/wallet.h Outdated Show resolved Hide resolved
@russeree
Copy link
Contributor

russeree commented Aug 12, 2023

tACK - Using checklevel of 4, assume valid=0, reindex=1 I was able to sync to the chain tip. This doesn't guarantee future consensus conflicts but should prove that there are not conflicts validating the 'main' chain. Testnet also validated successfully.

Full Settings

server=1
dbcache=16384
par=16
rpcthreads=8
rpcuser=bitcoin
rpcpassword=bitcoin
checkblocks=1
reindex=1
assumevalid=0
checklevel=4
maxconnections=0
listen=0
blocksonly=1
port=23766
rpcport=25765

Result:

image

ajtowns and others added 4 commits August 14, 2023 17:38
Replaces the constructor in CScriptID that converts a ScriptHash with a
function ToScriptID that does the same. This prepares for a move of
CScriptID to avoid a circular dependency.
CScriptID should be next to CScript just as CKeyID is next to CPubKey
TaprootSpendData and TaprootBuilder are used in signing in
SigningProvider contexts, so they should live near that.
CTxDestination is really our internal representation of an address and
doesn't really have anything to do with standard script types, so move
them to their own file.
Remove standard.h from files that don't use anything in it, and include
it in files that do.
Since script/standard only contains things that are used by the Solver
and its callers, rename the files to script/solver.
@achow101
Copy link
Member Author

Did you use some script for b3af9ce?

Ran IWYU with manual cleanup.

@theStack
Copy link
Contributor

Concept ACK

@Sjors
Copy link
Member

Sjors commented Aug 16, 2023

ACK 91d924e

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

ACK 91d924e 😇

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 91d924ede1b421df31c895f4f43359e453a09ca5 😇
hmHg3Qo/GQGeCKFKxGmHrg0EmWcpbYzmscRpSuTyu3LmtxqJWEsxftLwps2A5BuOvoJEocpFYxa/YP/1kWeZBw==

@@ -38,6 +37,11 @@ CKeyID ToKeyID(const WitnessV0KeyHash& key_hash)
return CKeyID{static_cast<uint160>(key_hash)};
Copy link
Member

Choose a reason for hiding this comment

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

unrelated: IIUC this creates a useless copy. Might be better to just retain the reference.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in #28284


#include <vector>

typedef std::vector<unsigned char> valtype;
Copy link
Member

Choose a reason for hiding this comment

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

7a172c7: nit: Any reason to put this in this scope, instead of in the only scope that uses it (one function)?

Also, could use using (C++11)?

#include <uint256.h>
#include <util/hash_type.h>

#include <vector>
Copy link
Member

Choose a reason for hiding this comment

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

7a172c7: nit:

addresstype.cpp should add these lines:
#include <cassert>
#include "crypto/sha256.h"   // for CSHA256
#include "span.h"            // for Span

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in #28284


#include <string>
#include <algorithm>
Copy link
Member

Choose a reason for hiding this comment

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

bacdb2e: nit:

script/solver.cpp should add these lines:
#include <cassert>              // for assert
#include "prevector.h"           // for operator-, prevector

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in #28284

// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include <addresstype.h>
Copy link
Member

Choose a reason for hiding this comment

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

7a172c7:nit: missing newline?

Copy link
Member

Choose a reason for hiding this comment

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

Fixed in #28284

@@ -657,6 +658,7 @@ libbitcoin_consensus_a_SOURCES = \
libbitcoin_common_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_common_a_SOURCES = \
addresstype.cpp \
Copy link
Member

Choose a reason for hiding this comment

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

nit in 7a172c7: Could keep this in the script directory, next to script/descriptor.cpp?

Copy link
Member

Choose a reason for hiding this comment

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

Yes or maybe have a new directory for everything that's "working with scripts" (addresstype, descriptor, signingprovider, ..).

Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

ACK 91d924e

@ajtowns
Copy link
Contributor

ajtowns commented Aug 17, 2023

ACK 91d924e

Copy link
Member

@darosior darosior 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 91d924e.

However i think you can just drop the largest commit here (7a172c7) and save a (+291, -247). It would also make more sense IMO. You state:

  • TaprootSpendData and TaprootBuilder (and their utility functions and structs) are moved to SigningProvider as these are used only during signing.
  • standard.{cpp/h} is renamed to solver.{cpp/h} since that's all that's left in the file after the above moves

But Taproot{Builder, SpendData} are more related to solving Taproots generally rather than to the "keystores" in signingprovider.h specifically. Since the file you move it from eventually becomes solver.h, i don't think it makes a lot of sense to move it.

@@ -657,6 +658,7 @@ libbitcoin_consensus_a_SOURCES = \
libbitcoin_common_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_common_a_SOURCES = \
addresstype.cpp \
Copy link
Member

Choose a reason for hiding this comment

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

Yes or maybe have a new directory for everything that's "working with scripts" (addresstype, descriptor, signingprovider, ..).

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.

Code-review ACK 91d924e

@fanquake fanquake merged commit 7ef2d4e into bitcoin:master Aug 17, 2023
15 checks passed
@sipa
Copy link
Member

sipa commented Aug 17, 2023

Posthumous concept ACK

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 17, 2023
sidhujag added a commit to syscoin/syscoin that referenced this pull request Aug 17, 2023
@ariard
Copy link
Member

ariard commented Aug 30, 2023

Post-merge code review ACK 91d924e.

fanquake added a commit that referenced this pull request Sep 19, 2023
…t scriptPubKey

ad0c469 wallet: Use CTxDestination in CRecipient rather than scriptPubKey (Andrew Chow)
07d3bdf Add PubKeyDestination for P2PK scripts (Andrew Chow)
1a98a51 Allow CNoDestination to represent a raw script (Andrew Chow)
8dd0670 Make WitnessUnknown members private (Andrew Chow)

Pull request description:

  For silent payments, we want to provide a `SilentPaymentsDestination` to be used as the recipient, which requires `CRecipient` to use something other than just the `scriptPubKey` as we cannot know the output script for a silent payment prior to transaction creation. `CTxDestination` seems like the obvious place to add a `SilentPaymentsDestination` as it is our internal representation of an address.

  In order to still allow paying to arbitrary scriptPubKeys (e.g. for data carrier outputs, or the user hand crafted a raw transaction that they have given to `fundrawtransaction`), `CNoDestination` is changed to contain raw scripts.

  Additionally, P2PK scripts are now interpreted as a new `PubKeyDestination` rather than `PKHash`. This results in some things that would have given an address for P2PK scripts to no longer do so. This is arguably more correct.

  `ExtractDestination`'s behavior is slightly changed for the above. It now returns `true` for those destinations that have addresses, so P2PK scripts now result in `false`. Even though it returns false for `CNoDestination`, the script will now be included in that `CNoDestination`.

  Builds on #28244

ACKs for top commit:
  josibake:
    ACK ad0c469

Tree-SHA512: ef3f8f3c7284779d9806c77c85b21caf910a79a1f7e7f1b51abcc0d7e074f14e00abf30f625a13075e41d94dad6202c10ddff462c0ee74c2ca4aab585b145a52
@josibake josibake mentioned this pull request Sep 26, 2023
15 tasks
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.

None yet