Ava Chow 347840164f
Merge bitcoin/bitcoin#32143: Fix 11-year-old mis-categorized error code in OP_IF evaluation
a7b581423e44c51fb7d177c5a15fe2cc2ab8aa43 Fix 11-year-old mis-categorized error code in OP_IF evaluation (Calin Culianu)

Pull request description:

  This was introduced by commit ab9edbd6b6eb3efbca11f16fa467c3c0ef905708.

  It appears the original author may have gotten tired and pasted the wrong error code into this 1 place. Every other situation where the value stack lacks the required number of arguments for the op-code, SCRIPT_ERR_INVALID_STACK_OPERATION is reported. Not so here.

  This commit fixes the situation.

  EDIT: Note this turns out to be a dupe of the abandoned #30359 .

ACKs for top commit:
  billymcbip:
    tACK a7b581423e44c51fb7d177c5a15fe2cc2ab8aa43
  achow101:
    ACK a7b581423e44c51fb7d177c5a15fe2cc2ab8aa43
  darosior:
    utACK a7b581423e44c51fb7d177c5a15fe2cc2ab8aa43
  sedited:
    ACK a7b581423e44c51fb7d177c5a15fe2cc2ab8aa43

Tree-SHA512: e8c01a3e2448b5d49b76a0cab3f38a2d0249b71beeb7d9d05d5ecc3812bd91d0bd1d0f78b809b6f4ccb73186fa119cb1ed3779a73284b83a67ae219ef378fa6c
2026-01-19 16:39:45 -08:00
..
2025-09-20 21:36:39 +02:00

Various test vectors

mainnet_alt.json

For easier testing the difficulty is maximally increased in the first (and only) retarget period, by producing blocks approximately 2 minutes apart.

The alternate mainnet chain was generated as follows:

  • use faketime to set node clock to 2 minutes after genesis block
  • mine a block using a CPU miner such as https://github.com/pooler/cpuminer
  • restart node with a faketime 2 minutes later
for i in {1..2016}
do
 t=$(( 1231006505 + $i * 120 ))
 faketime "`date -d @$t  +'%Y-%m-%d %H:%M:%S'`" \
 bitcoind -connect=0 -nocheckpoints -stopatheight=$i
done

The CPU miner is kept running as follows:

./minerd -u ... -p ... -o http://127.0.0.1:8332 --no-stratum \
        --coinbase-addr 1NQpH6Nf8QtR2HphLRcvuVqfhXBXsiWn8r \
        --algo sha256d --no-longpoll --scantime 3 --retry-pause 1

The payout address is derived from first BIP32 test vector master key:

pkh(xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi/44h/0h/0h/<0;1>/*)#fkjtr0yn

It uses pkh() because tr() outputs at low heights are not spendable (unexpected-witness).

This makes each block deterministic except for its timestamp and nonce, which are stored in mainnet_alt.json and used to reconstruct the chain without having to redo the proof-of-work.

The timestamp was not kept constant because at difficulty 1 it's not sufficient to only grind the nonce. Grinding the extra_nonce or version field instead would have required additional (stratum) software. It would also make it more complicated to reconstruct the blocks in this test.

The getblocktemplate RPC code needs to be patched to ignore not being connected to any peers, and to ignore the IBD status check.

On macOS use faketime "@$t" instead.