Skip to content

Conversation

Empact
Copy link
Contributor

@Empact Empact commented Aug 3, 2018

fScriptChecks = false just short-circuits the entire function, so
passing it in is entirely useless.

This is extracted from #13233 /cc TheBlueMatt.

Recommend reviewing with git show --ignore-all-space, i.e.:
https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

@Empact Empact force-pushed the check-inputs-script-checks branch from b161464 to 1d7cc70 Compare August 3, 2018 18:10
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 3, 2018

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #16658 ([WIP] validation: Rename CheckInputs to CheckInputScripts by jnewbery)
  • #16486 ([consensus] skip bip30 checks when assumevalid is set for the block by pstratem)
  • #13204 (Faster sigcache nonce by JeremyRubin)

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.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

utACK 1d7cc70.

Recommend reviewing with git show --ignore-all-space

Also view with&w=1.

@Empact
Copy link
Contributor Author

Empact commented Aug 4, 2018

@practicalswift @TheBlueMatt deserves the credit. :)

@Empact Empact force-pushed the check-inputs-script-checks branch from 1d7cc70 to 7b471ea Compare August 7, 2018 15:32
@Empact
Copy link
Contributor Author

Empact commented Aug 7, 2018

Rebased for #13527

@Empact Empact force-pushed the check-inputs-script-checks branch from 7b471ea to 852c7aa Compare August 27, 2018 16:52
@Empact
Copy link
Contributor Author

Empact commented Aug 27, 2018

Rebased for #13083

@Empact
Copy link
Contributor Author

Empact commented Dec 12, 2018

Rebased for #14908, updated to single line coinbase check.

@jnewbery
Copy link
Contributor

Concept ACK, but this removes the quite useful comment about how assume valid works:

        // Skip script verification when connecting blocks under the	
         // assumevalid block. Assuming the assumevalid block is valid this
        // is safe because block merkle hashes are still computed and checked,
        // Of course, if an assumed valid block is invalid due to false scriptSigs
        // this optimization would allow an invalid chain to be accepted.

Perhaps you can incorporate that information after the line:

// This block is a member of the assumed verified chain and an ancestor of the best header.

@Empact Empact force-pushed the check-inputs-script-checks branch 2 times, most recently from 099f32e to d99bb14 Compare March 4, 2019 09:11
@Empact Empact force-pushed the check-inputs-script-checks branch from d99bb14 to dab9e84 Compare May 17, 2019 03:33
@Empact
Copy link
Contributor Author

Empact commented May 17, 2019

Rebased and I split the coinbase change into another commit.

Once again: https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

@jnewbery
Copy link
Contributor

Fails tx_validationcache_tests/checkinputs_test (both on travis and locally)

@Empact Empact force-pushed the check-inputs-script-checks branch from dab9e84 to 195dfcf Compare May 17, 2019 18:28
@Empact Empact force-pushed the check-inputs-script-checks branch 2 times, most recently from 8fed5a1 to 5b99467 Compare August 19, 2019 06:01
@Empact
Copy link
Contributor Author

Empact commented Aug 19, 2019

Rebased, and squashed the minor coinbase change.
https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

@jnewbery
Copy link
Contributor

utACK 5b99467

@fanquake
Copy link
Member

@TheBlueMatt @BugTheBlueMatt want to take a look here given it's your change.

Copy link
Contributor

@TheBlueMatt TheBlueMatt 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.

fScriptChecks = false just short-circuits the entire function, so
passing it in is entirely useless.
@Empact Empact force-pushed the check-inputs-script-checks branch from 5b99467 to 9b92538 Compare August 26, 2019 23:32
@Empact
Copy link
Contributor Author

Empact commented Aug 26, 2019

@TheBlueMatt thanks for pointing that out. Comment moved to AcceptToMemoryPoolWorker.

@TheBlueMatt
Copy link
Contributor

utACK 9b92538. Checked diff had no functional change and new comment copy looks correct.

Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

ACK 9b92538 - Notes / testing below.

CheckInputs() is called from:

  1. CheckInputsFromMempoolAndCache() - fScriptChecks was true

  2. AcceptToMemoryPoolWorker() - 3 times and fScriptChecks was always true

  3. CChainState::ConnectBlock() - fScriptChecks is true unless

    1. we have an assumeValid hash and
    2. GetBlockProofEquivalentTime() is <= 1’209’600 seconds ( 2 weeks)

Changes to CheckInputs():

  1. Drop the fScriptChecks parameter.
  2. IsCoinBase() check is now clearer. i.e
if (!tx.IsCoinBase()) {
    // do input checking
}
return true

is now:

if (tx.IsCoinBase()) return true;
// do input checking
return true
  1. Brackets around the pvChecks check.
  2. Moved the "The first loop above does.." comment to AcceptToMemoryPoolWorker.
  3. Moved "Skip script verification.." to ConnectBlock.

Added some logging and tested:

  • Given a garbage -assumevalid=garbage hash fScriptChecks was true (early IBD).
  • Modified CheckInputs() to return false - checked that we drop into the ConnectBlock error.
  • Modified CheckInputs() to return false and ran with -assumevalid=garbage - checked that we drop into the ConnectBlock error.

Other thought. It looks like everywhere we call CheckInputs() we are already checking prior that the tx is not a coinbase. Although I cannot see a downside to a belt-and-suspenders check inside CheckInputs().

@jnewbery can you re-review here?

@kallewoof
Copy link
Contributor

kallewoof commented Sep 1, 2019

ACK 9b92538

Verified that function does essentially nothing if the flag is false.

@ajtowns
Copy link
Contributor

ajtowns commented Sep 2, 2019

ACK 9b92538 ; code review, checked tests work. Looks right to me, and fanquake's notes make sense. Could change the coinbase early exit to assert(!tx.IsCoinBase());.

@fanquake
Copy link
Member

fanquake commented Sep 2, 2019

Could change the coinbase early exit to assert(!tx.IsCoinBase());

I think that can be discussed / done in a follow up. We've got ACKs, so I'm merging this.

Thanks to those of you that I harassed for review for following up. Post-merge ACKs still welcome.

fanquake added a commit that referenced this pull request Sep 2, 2019
9b92538 Remove unused fScriptChecks parameter from CheckInputs (Matt Corallo)

Pull request description:

  fScriptChecks = false just short-circuits the entire function, so
  passing it in is entirely useless.

  This is extracted from #13233 /cc TheBlueMatt.

  Recommend reviewing with `git show --ignore-all-space`, i.e.:
  https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

ACKs for top commit:
  TheBlueMatt:
    utACK 9b92538. Checked diff had no functional change and new comment copy looks correct.
  kallewoof:
    ACK 9b92538
  ajtowns:
    ACK 9b92538 ; code review, checked tests work. Looks right to me, and fanquake's notes make sense. Could change the coinbase early exit to `assert(!tx.IsCoinBase());`.
  fanquake:
    ACK 9b92538 - Notes / testing below.

Tree-SHA512: add253a3e8cf4b33eddbc49efcec333c14b5ea61c7d34e43230351d40cff6adc919a75b91c72c4de8647a395284db74a61639f4c67848d4b2fec3a705b557790
@fanquake fanquake merged commit 9b92538 into bitcoin:master Sep 2, 2019
@laanwj
Copy link
Member

laanwj commented Sep 2, 2019

Posthumous ACK 9b92538

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.

post-merge ACK 9b92538 with one comment nit.

@@ -773,15 +773,17 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
constexpr unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS;

// Check against previous transactions
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
// The first loop above does all the inexpensive checks.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really confusing comment here. "The first loop" refers to the checks inside CheckTxInputs() call on L566, which has been moved around since the comment was first written.

I'll fix this comment in a follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

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

Being addressed in #16658.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 3, 2019
…Inputs

9b92538 Remove unused fScriptChecks parameter from CheckInputs (Matt Corallo)

Pull request description:

  fScriptChecks = false just short-circuits the entire function, so
  passing it in is entirely useless.

  This is extracted from bitcoin#13233 /cc TheBlueMatt.

  Recommend reviewing with `git show --ignore-all-space`, i.e.:
  https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

ACKs for top commit:
  TheBlueMatt:
    utACK 9b92538. Checked diff had no functional change and new comment copy looks correct.
  kallewoof:
    ACK 9b92538
  ajtowns:
    ACK 9b92538 ; code review, checked tests work. Looks right to me, and fanquake's notes make sense. Could change the coinbase early exit to `assert(!tx.IsCoinBase());`.
  fanquake:
    ACK 9b92538 - Notes / testing below.

Tree-SHA512: add253a3e8cf4b33eddbc49efcec333c14b5ea61c7d34e43230351d40cff6adc919a75b91c72c4de8647a395284db74a61639f4c67848d4b2fec3a705b557790
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 29, 2020
Summary:
Remove unused fScriptChecks parameter from CheckInputs (Matt Corallo)

Pull request description:

  fScriptChecks = false just short-circuits the entire function, so
  passing it in is entirely useless.

  This is extracted from #13233 /cc TheBlueMatt.

  Recommend reviewing with `git show --ignore-all-space`, i.e.:
  https://github.com/bitcoin/bitcoin/pull/13868/files?w=1

---

Backport of Core [[bitcoin/bitcoin#13868 | PR13868]]

Test Plan:
  ninja check check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7628
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
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.

10 participants