bitcoin/src/bench
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
..
data Add deserialize + CheckBlock benchmarks, and a full block hex 2016-11-09 11:27:59 -08:00
.gitignore Ignore bench_bitcoin binary. 2015-10-06 17:46:12 +02:00
base58.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
bech32.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
bench.cpp Fix benchmarks filters 2020-01-28 17:10:15 +02:00
bench.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
bench_bitcoin.cpp Merge #17279: refactor: Remove redundant c_str() calls in formatting 2019-10-28 15:10:06 -04:00
block_assemble.cpp rpc: Remove mempool global from miner 2019-12-23 06:12:10 +07:00
ccoins_caching.cpp refactor: test/bench: dedup SetupDummyInputs() 2020-02-28 21:09:03 +01:00
chacha20.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
chacha_poly_aead.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
checkblock.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
checkqueue.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
coin_selection.cpp Refactor: Allow LegacyScriptPubKeyMan to be null 2020-01-23 16:34:28 -05:00
crypto_hash.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
data.cpp bench: Move generated data to a dedicated translation unit 2019-07-02 18:11:15 +01:00
data.h bench: Move generated data to a dedicated translation unit 2019-07-02 18:11:15 +01:00
duplicate_inputs.cpp [validation] Add CValidationState subclasses 2019-10-29 15:46:45 -04:00
examples.cpp scripted-diff: Replace MilliSleep with UninterruptibleSleep 2020-02-21 10:06:21 -08:00
gcs_filter.cpp blockfilter: Refactor GCS params into struct. 2018-11-06 09:12:54 -08:00
lockedpool.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
mempool_eviction.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
mempool_stress.cpp bench: Remove redundant copy constructor in mempool_stress 2019-11-01 18:15:53 -04:00
merkle_root.cpp Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
poly1305.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
prevector.cpp Drop defunct IS_TRIVIALLY_CONSTRUCTIBLE handling from prevector.h 2018-11-14 12:19:04 -05:00
rollingbloom.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
rpc_blockchain.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
rpc_mempool.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
util_time.cpp util: Add type safe GetTime 2019-05-23 14:12:32 -04:00
verify_script.cpp Merge #16902: O(1) OP_IF/NOTIF/ELSE/ENDIF script implementation 2020-03-14 21:03:45 +01:00
wallet_balance.cpp Refactor: Allow LegacyScriptPubKeyMan to be null 2020-01-23 16:34:28 -05:00