0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-05 10:17:30 -05:00
bitcoin-bitcoin-core/src/script
Wladimir J. van der Laan 67dfd18f44
Merge #16902: O(1) OP_IF/NOTIF/ELSE/ENDIF script implementation
e6e622e5a0 Implement O(1) OP_IF/NOTIF/ELSE/ENDIF logic (Pieter Wuille)
d0e8f4d5d8 [refactor] interpreter: define interface for vfExec (Anthony Towns)
89fb241c54 Benchmark script verification with 100 nested IFs (Pieter Wuille)

Pull request description:

  While investigating what mechanisms are possible to maximize the per-opcode verification cost of scripts, I noticed that the logic for determining whether a particular opcode is to be executed is O(n) in the nesting depth. This issue was also pointed out by Sergio Demian Lerner in https://bitslog.wordpress.com/2017/04/17/new-quadratic-delays-in-bitcoin-scripts/, and this PR implements a variant of the O(1) algorithm suggested there.

  This is not a problem currently, because even with a nesting depth of 100 (the maximum possible right now due to the 201 ops limit), the slowdown caused by this on my machine is around 70 ns per opcode (or 0.25 s per block) at worst, far lower than what is possible with other opcodes.

  This PR mostly serves as a proof of concept that it's possible to avoid it, which may be relevant in discussions around increasing the opcode limits in future script versions. Without it, the execution time of scripts can grow quadratically with the nesting depth, which very quickly becomes unreasonable.

  This improves upon #14245 by completely removing the `vfExec` vector.

ACKs for top commit:
  jnewbery:
    Code review ACK e6e622e5a0
  MarcoFalke:
    ACK e6e622e5a0 🐴
  fjahr:
    ACK e6e622e5a0
  ajtowns:
    ACK e6e622e5a0
  laanwj:
    concept and code review ACK e6e622e5a0
  jonatack:
    ACK e6e622e5a0 code review, build, benches, fuzzing

Tree-SHA512: 1dcfac3411ff04773de461959298a177f951cb5f706caa2734073bcec62224d7cd103767cfeef85cd129813e70c14c74fa8f1e38e4da70ec38a0f615aab1f7f7
2020-03-14 21:03:45 +01:00
..
bitcoinconsensus.cpp Drop unused GetType() from CSizeComputer 2018-09-11 00:58:05 -04:00
bitcoinconsensus.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
descriptor.cpp Cache parent xpub inside of BIP32PubkeyProvider 2020-03-07 10:13:47 -05:00
descriptor.h Add DescriptorCache* read_cache and DescriptorCache* write_cache to Expand and GetPubKey 2020-03-07 10:13:47 -05:00
interpreter.cpp Merge #16902: O(1) OP_IF/NOTIF/ELSE/ENDIF script implementation 2020-03-14 21:03:45 +01:00
interpreter.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
keyorigin.h Remove unused includes 2019-10-15 22:56:43 +00:00
script.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
script.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
script_error.cpp Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
script_error.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
sigcache.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
sigcache.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
sign.cpp Clear any input_errors for an input after it is signed 2020-03-09 11:16:20 -04:00
sign.h Refactor rawtransaction's SignTransaction into generic SignTransaction function 2020-03-08 12:26:27 -04:00
signingprovider.cpp Move WatchOnly stuff from SigningProvider to CWallet 2019-07-09 16:20:18 -04:00
signingprovider.h wallet: Improve LegacyScriptPubKeyMan::CanProvide script recognition 2020-02-12 11:48:30 -05:00
standard.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
standard.h Merge #17924: Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash 2020-01-16 19:23:33 +01:00