aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Sanders <gsanders87@gmail.com>2019-03-21 13:47:47 -0400
committerMarcoFalke <falke.marco@gmail.com>2019-05-20 12:25:06 -0400
commit86031083c71e257778e95e21e81532b310472358 (patch)
tree7c584af2be1f243293739dc9d6949eebff7ca314
parent5a58ddb6d558514c2f48543be0760bbf22698189 (diff)
Add test for superfluous witness record in deserialization
Github-Pull: #15893 Rebased-From: cc556e4a30b4a32eab6722f590489d89b2875de3
-rwxr-xr-xtest/functional/p2p_segwit.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py
index 8f8e89cf15..ff7f1dd0c9 100755
--- a/test/functional/p2p_segwit.py
+++ b/test/functional/p2p_segwit.py
@@ -37,6 +37,7 @@ from test_framework.messages import (
ser_vector,
sha256,
uint256_from_str,
+ FromHex,
)
from test_framework.mininode import (
P2PInterface,
@@ -81,6 +82,7 @@ from test_framework.util import (
hex_str_to_bytes,
sync_blocks,
sync_mempools,
+ assert_raises_rpc_error,
)
# The versionbit bit used to signal activation of SegWit
@@ -273,6 +275,7 @@ class SegWitTest(BitcoinTestFramework):
self.test_non_standard_witness()
self.test_upgrade_after_activation()
self.test_witness_sigops()
+ self.test_superfluous_witness()
# Individual tests
@@ -2039,5 +2042,31 @@ class SegWitTest(BitcoinTestFramework):
# TODO: test p2sh sigop counting
+ def test_superfluous_witness(self):
+ # Serialization of tx that puts witness flag to 1 always
+ def serialize_with_bogus_witness(tx):
+ flags = 1
+ r = b""
+ r += struct.pack("<i", tx.nVersion)
+ if flags:
+ dummy = []
+ r += ser_vector(dummy)
+ r += struct.pack("<B", flags)
+ r += ser_vector(tx.vin)
+ r += ser_vector(tx.vout)
+ if flags & 1:
+ if (len(tx.wit.vtxinwit) != len(tx.vin)):
+ # vtxinwit must have the same length as vin
+ tx.wit.vtxinwit = tx.wit.vtxinwit[:len(tx.vin)]
+ for i in range(len(tx.wit.vtxinwit), len(tx.vin)):
+ tx.wit.vtxinwit.append(CTxInWitness())
+ r += tx.wit.serialize()
+ r += struct.pack("<I", tx.nLockTime)
+ return r
+
+ raw = self.nodes[0].createrawtransaction([{"txid":"00"*32, "vout":0}], {self.nodes[0].getnewaddress():1})
+ tx = FromHex(CTransaction(), raw)
+ assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, serialize_with_bogus_witness(tx).hex())
+
if __name__ == '__main__':
SegWitTest().main()