Skip to content

Commit 7bc64a8

Browse files
committed
test: properly check for per-tx sigops limit
Currently the per-tx sigops limit standardness check (bounded by `MAX_STANDARD_TX_SIGOPS_COST`, throwing "bad-txns-too-many-sigops" if exceeded) is only indirectly tested with the much higher per-block consensus limit (`MAX_BLOCK_SIGOPS_COST`), i.e. an increase in the limit would still pass all tests. Refine that by splitting up the invalid tx template `TooManySigops` in a per-block and a per-tx one. The involved functional tests taking use of these templates are `feature_block.py` and `p2p_invalid_txs.py`.
1 parent 3f83c74 commit 7bc64a8

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

test/functional/data/invalid_txs.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
MAX_MONEY,
3131
SEQUENCE_FINAL,
3232
)
33-
from test_framework.blocktools import create_tx_with_script, MAX_BLOCK_SIGOPS
33+
from test_framework.blocktools import (
34+
create_tx_with_script,
35+
MAX_BLOCK_SIGOPS,
36+
MAX_STANDARD_TX_SIGOPS,
37+
)
3438
from test_framework.script import (
3539
CScript,
3640
OP_0,
@@ -233,7 +237,7 @@ def get_tx(self):
233237
amount=(self.spend_avail // 2))
234238

235239

236-
class TooManySigops(BadTxTemplate):
240+
class TooManySigopsPerBlock(BadTxTemplate):
237241
reject_reason = "bad-txns-too-many-sigops"
238242
block_reject_reason = "bad-blk-sigops, out-of-bounds SigOpCount"
239243
expect_disconnect = False
@@ -245,6 +249,20 @@ def get_tx(self):
245249
output_script=lotsa_checksigs,
246250
amount=1)
247251

252+
253+
class TooManySigopsPerTransaction(BadTxTemplate):
254+
reject_reason = "bad-txns-too-many-sigops"
255+
expect_disconnect = False
256+
valid_in_block = True
257+
258+
def get_tx(self):
259+
lotsa_checksigs = CScript([OP_CHECKSIG] * (MAX_STANDARD_TX_SIGOPS + 1))
260+
return create_tx_with_script(
261+
self.spend_tx, 0,
262+
output_script=lotsa_checksigs,
263+
amount=1)
264+
265+
248266
def getDisabledOpcodeTemplate(opcode):
249267
""" Creates disabled opcode tx template class"""
250268
def get_tx(self):

test/functional/test_framework/blocktools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
MAX_BLOCK_SIGOPS = 20000
5151
MAX_BLOCK_SIGOPS_WEIGHT = MAX_BLOCK_SIGOPS * WITNESS_SCALE_FACTOR
52+
MAX_STANDARD_TX_SIGOPS = 4000
5253
MAX_STANDARD_TX_WEIGHT = 400000
5354

5455
# Genesis block time (regtest)

0 commit comments

Comments
 (0)