|
89 | 89 | MAX_SIGOP_COST = 80000 |
90 | 90 |
|
91 | 91 | SEGWIT_HEIGHT = 120 |
| 92 | +MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS = 210 |
| 93 | +MAX_STANDARD_WITNESS_INPUT_STACK_ITEM_SIZE = 80 |
| 94 | +MAX_STANDARD_WITNESS_SCRIPT_SIZE = 7100 |
| 95 | +# Extra restrictions make tests easier |
| 96 | +assert MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS < 403 and (MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS % 2) == 0 |
| 97 | +assert MAX_STANDARD_WITNESS_SCRIPT_SIZE % 50 == 0 |
92 | 98 |
|
93 | 99 | class UTXO(): |
94 | 100 | """Used to keep track of anyone-can-spend outputs that we can use in the tests.""" |
@@ -1797,10 +1803,12 @@ def test_non_standard_witness(self): |
1797 | 1803 |
|
1798 | 1804 | # Create scripts for tests |
1799 | 1805 | scripts = [] |
1800 | | - scripts.append(CScript([OP_DROP] * 100)) |
1801 | | - scripts.append(CScript([OP_DROP] * 99)) |
1802 | | - scripts.append(CScript([pad * 59] * 59 + [OP_DROP] * 60)) |
1803 | | - scripts.append(CScript([pad * 59] * 59 + [OP_DROP] * 61)) |
| 1806 | + scripts.append(CScript([OP_2DROP] * (MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS // 2))) |
| 1807 | + scripts.append(CScript([OP_2DROP] * (MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS // 2 - 1) + [OP_DROP])) |
| 1808 | + scripts.append(CScript([pad * 48] * (MAX_STANDARD_WITNESS_SCRIPT_SIZE // 50) + [OP_DROP] * (MAX_STANDARD_WITNESS_SCRIPT_SIZE // 50))) |
| 1809 | + scripts.append(CScript([pad * 48] * (MAX_STANDARD_WITNESS_SCRIPT_SIZE // 50) + [OP_DROP] * (MAX_STANDARD_WITNESS_SCRIPT_SIZE // 50 + 1))) |
| 1810 | + assert len(scripts[2]) == MAX_STANDARD_WITNESS_SCRIPT_SIZE |
| 1811 | + assert len(scripts[3]) == MAX_STANDARD_WITNESS_SCRIPT_SIZE + 1 |
1804 | 1812 |
|
1805 | 1813 | p2wsh_scripts = [] |
1806 | 1814 |
|
@@ -1840,45 +1848,45 @@ def test_non_standard_witness(self): |
1840 | 1848 | p2sh_txs.append(p2sh_tx) |
1841 | 1849 |
|
1842 | 1850 | # Testing native P2WSH |
1843 | | - # Witness stack size, excluding witnessScript, over 100 is non-standard |
1844 | | - p2wsh_txs[0].wit.vtxinwit[0].scriptWitness.stack = [pad] * 101 + [scripts[0]] |
| 1851 | + # Witness stack size, excluding witnessScript, over MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS is non-standard |
| 1852 | + p2wsh_txs[0].wit.vtxinwit[0].scriptWitness.stack = [pad] * (MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS + 1) + [scripts[0]] |
1845 | 1853 | test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[0], True, False, 'bad-witness-nonstandard') |
1846 | 1854 | # Non-standard nodes should accept |
1847 | 1855 | test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[0], True, True) |
1848 | 1856 |
|
1849 | | - # Stack element size over 80 bytes is non-standard |
1850 | | - p2wsh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 81] * 100 + [scripts[1]] |
| 1857 | + # Stack element size over MAX_STANDARD_WITNESS_INPUT_STACK_ITEM_SIZE bytes is non-standard |
| 1858 | + p2wsh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * (MAX_STANDARD_WITNESS_INPUT_STACK_ITEM_SIZE + 1)] * MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS + [scripts[1]] |
1851 | 1859 | test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[1], True, False, 'bad-witness-nonstandard') |
1852 | 1860 | # Non-standard nodes should accept |
1853 | 1861 | test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[1], True, True) |
1854 | | - # Standard nodes should accept if element size is not over 80 bytes |
1855 | | - p2wsh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 80] * 100 + [scripts[1]] |
| 1862 | + # Standard nodes should accept if element size is not over MAX_STANDARD_WITNESS_INPUT_STACK_ITEM_SIZE |
| 1863 | + p2wsh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * MAX_STANDARD_WITNESS_INPUT_STACK_ITEM_SIZE] * MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS + [scripts[1]] |
1856 | 1864 | test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[1], True, True) |
1857 | 1865 |
|
1858 | | - # witnessScript size at 3600 bytes is standard |
1859 | | - p2wsh_txs[2].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, scripts[2]] |
| 1866 | + # witnessScript size at 7100 bytes is standard |
| 1867 | + p2wsh_txs[2].wit.vtxinwit[0].scriptWitness.stack = [pad, scripts[2]] |
1860 | 1868 | test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[2], True, True) |
1861 | 1869 | test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[2], True, True) |
1862 | 1870 |
|
1863 | | - # witnessScript size at 3601 bytes is non-standard |
1864 | | - p2wsh_txs[3].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, pad, scripts[3]] |
| 1871 | + # witnessScript size at 7101 bytes is non-standard |
| 1872 | + p2wsh_txs[3].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, scripts[3]] |
1865 | 1873 | test_transaction_acceptance(self.nodes[1], self.std_node, p2wsh_txs[3], True, False, 'bad-witness-nonstandard') |
1866 | 1874 | # Non-standard nodes should accept |
1867 | 1875 | test_transaction_acceptance(self.nodes[0], self.test_node, p2wsh_txs[3], True, True) |
1868 | 1876 |
|
1869 | 1877 | # Repeating the same tests with P2SH-P2WSH |
1870 | | - p2sh_txs[0].wit.vtxinwit[0].scriptWitness.stack = [pad] * 101 + [scripts[0]] |
| 1878 | + p2sh_txs[0].wit.vtxinwit[0].scriptWitness.stack = [pad] * (MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS + 1) + [scripts[0]] |
1871 | 1879 | test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[0], True, False, 'bad-witness-nonstandard') |
1872 | 1880 | test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[0], True, True) |
1873 | | - p2sh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 81] * 100 + [scripts[1]] |
| 1881 | + p2sh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * (MAX_STANDARD_WITNESS_INPUT_STACK_ITEM_SIZE + 1)] * MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS + [scripts[1]] |
1874 | 1882 | test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[1], True, False, 'bad-witness-nonstandard') |
1875 | 1883 | test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[1], True, True) |
1876 | | - p2sh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * 80] * 100 + [scripts[1]] |
| 1884 | + p2sh_txs[1].wit.vtxinwit[0].scriptWitness.stack = [pad * MAX_STANDARD_WITNESS_INPUT_STACK_ITEM_SIZE] * MAX_STANDARD_WITNESS_INPUT_STACK_ITEMS + [scripts[1]] |
1877 | 1885 | test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[1], True, True) |
1878 | | - p2sh_txs[2].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, scripts[2]] |
| 1886 | + p2sh_txs[2].wit.vtxinwit[0].scriptWitness.stack = [pad, scripts[2]] |
1879 | 1887 | test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[2], True, True) |
1880 | 1888 | test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[2], True, True) |
1881 | | - p2sh_txs[3].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, pad, scripts[3]] |
| 1889 | + p2sh_txs[3].wit.vtxinwit[0].scriptWitness.stack = [pad, pad, scripts[3]] |
1882 | 1890 | test_transaction_acceptance(self.nodes[1], self.std_node, p2sh_txs[3], True, False, 'bad-witness-nonstandard') |
1883 | 1891 | test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_txs[3], True, True) |
1884 | 1892 |
|
|
0 commit comments