Repository: paritytech/parity-bitcoin (language: rust)

Issue:
Testnet sync fails
original report: https://github.com/paritytech/parity-bitcoin/issues/256#issuecomment-486513490

Not able to sync here are the logs.
```
2019-04-25 04:12:45 UTC WARN sync Disconnecting from peer#8 due to DoS: Provided wrong block 00000000762e42a93e991540475b68b53875c6a680a12142e4ec4e529372b0b5
2019-04-25 04:12:45 UTC WARN sync Block "00000000532452241b0698fa4477b5d3f534474cf716c8adec0ab0f7c27e7b58" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000035e4944906bfe9ddc0aa5c61a3caf28cbbe4ea8ef8b70245cf62bdf1" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000000000021f62a388394e74802f3c0eeb85b6df6329449f672f8d68469" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000007f5d3fc4cb447eb2aadacd407685c8a3455a6c63ca0a7baa05471946" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000000000004b1b55522ed640f6c001a78cc2262c5bc44edd83905f2f9c94" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000ecb3a6e5de8b7448352616d3331f05cd80e3997ad6b254b4471c93cd" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000180e8c413fe3356aae046a679b936eb42dd63c8a495d53d7eb5316f9" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000000000607f3b63b88fdc6e982c9e7f41608159b374cacd5faa106442" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Disconnecting from peer#6 due to DoS: Provided wrong block 00000000000000607f3b63b88fdc6e982c9e7f41608159b374cacd5faa106442
2019-04-25 04:12:45 UTC WARN sync Block "00000000aa654dd4e8d6125589e38de7e63f4a61a353a285b8b307f3624a2480" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000cd01007346f9a3d384a507f97afb164c057bcd1694ca20bb3302bb8d" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000fb0350a72d7316a2006de44e74c16b56843a29bd85e0535d71edbc5b" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000008f71fb3f76a19075987a5d5653efce9bab90474497c9e1151ac94b69" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000ecae98e551fde86596f9e258d28edefd956f1e6919c268332804b668" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000000d06f29dd5e64158ec77e24b3ca31f44cf00c98811f5066b6372589" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000009c9d3caa3798795c8e2d5e4613c1e328326b320d84a42da757c805e2" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000b42ba387d5aaa3538ceca124b8dbed81a8ce1f30b5930921028523a9" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000001ec8485222050b30fa01d1d533e0fe078621b5bdbdf952554d9882a1" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000043c451414ce57f16aa003d049a10dd17fe8a78e10ad8155df6f0b08f" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000018d44ffaf43b24e03279c265e65cf977d06d712a234d5c0f496f1bab" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Disconnecting from peer#9 due to DoS: Provided wrong block 0000000018d44ffaf43b24e03279c265e65cf977d06d712a234d5c0f496f1bab
2019-04-25 04:12:45 UTC WARN sync Block "000000000000000d3ac2a97b849a8c07de9b1c90bf5eca59d250471fbe74e28e" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000983506c1c339a0e1724f9e991d12d145dd7bf007d43002f06efe7bfc" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000000000005e08730ba3f127b6ffded03dbdf3b8f126f407ea41953f2bb0" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000f9665be95764d03b8461299b26ff3ebd79c8b1d34d8bc9821b495de6" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000003c49d4fc961df496402e4c964cebd5575c1544f2dde77450f50ccc4b" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000047ffe9617e94dccebd180a138f7e98a1b7bbcead39ff91cb2d45e852" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000099ec48cd2c9c2e735f9b7eaca31c91f5c0ae4c092ff2e0d204a801ff" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000007149ca321592a95425fb8c7ca4a7f8bab5784e24b47dd40c6df2eba4" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000096241c386a46b9c797939792409718cddc468bc3084541402b050ee0" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000000329f7f432b59f4258ebe5fed86c7e765853eabb3c907096ca579c" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000000001619ea1539b0fed74bbb17f9a1d82540e32795ee0ab059da4fbcb" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000b6b1ecb9a8f4bf16259d66eed9a4a44423c4b352a40c442099886faa" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000000bb87f1b4d5f184b3fe0b8ae0a5d57f461d03918b65837d521b629" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000000757108bfd52009a86312a2857aeefebaee308824d0c050021725d" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000000007959f81c3b02e8a76093f3de8654d3128ab36096383f306e7a07" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000000006d7388caf9ddaf487784eacb2631d3c67cb84b9797b8c7412df26" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000000025e58181f6b00eb78008421a390d0e9a0a4e77ed98122ba448911" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Disconnecting from peer#4 due to DoS: Provided wrong block 0000000000025e58181f6b00eb78008421a390d0e9a0a4e77ed98122ba448911
2019-04-25 04:12:45 UTC WARN sync Block "0000000000000023b3a7cc6402d4e40cd47e5eaa98ae96f742b1041834513fef" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "0000000019d37425fb61ad6b40588461162aff6a9af3ac9a029022a665debc73" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000008d92ef120135de41cf098f155c4bd0493592f6b2a6427dbfbbaa6def" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000e33d8bf9b4f0b31a2e3d3ce79675880652c1e5e5f4d2de835a6e085f" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000008f810ac7664cef4966ce94ef325b6a3c19b0ff96b77e6087f23b4f66" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000001ea4824c5338e857d60a2a6fb69cd6c203ec4ccf877f260bfd67cfb2" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000008f3c3306cfd12002394cc3579b3acc36a63c3e872ebfdcb42fb4c028" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000897e7e8cb2fda0b7c874a12fbf01c576b390bec418f6949074577f14" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000000178f0c743a1dccf948e2b955d875b3ff8d892b5175fcb4b5f1b69ef" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000fb5c98174952cc33b42a9b63c46781a053247e5c37e39b06d6fbb923" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "000000001895a99c50386158bd44324d08d1edd596ba9b35560dbce967660053" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Block "00000000370719046d96bf9c3ec3a0d65d77f42140b34af94fc202364a907050" verification failed with error "Database(UnknownParent)"
2019-04-25 04:12:45 UTC WARN sync Disconnecting from peer#7 due to misbehavior: Provided dead-end block 00000000727315749ea87d22f203453038438c44e294a6c8f786bdae9c9a3d81
```



Discussion / hints:
always getting Inbound connections: (0/10)... and chain syncing stopped..
```
2019-04-25 07:53:24 UTC INFO p2p::p2p Inbound connections: (0/10)
2019-04-25 07:53:24 UTC INFO p2p::p2p Outbound connections: (0/10)
2019-04-25 07:53:24 UTC TRACE db canonize BestBlock { number: 1210152, hash: 000000003de68a5e9416dc8a61c67fc47a095c6a4bd9df45548455a30b55a919 }
2019-04-25 07:53:24 UTC TRACE db canonize BestBlock { number: 1210152, hash: 000000003de68a5e9416dc8a61c67fc47a095c6a4bd9df45548455a30b55a919 }
2019-04-25 07:53:24 UTC TRACE db canonize BestBlock { number: 1210153, hash: 00000000f069266125106c8de6a526c004a06851a347ae132d47fe5419e2ba85 }
2019-04-25 07:53:25 UTC TRACE db canonize BestBlock { number: 1210154, hash: 0000000042341251ff61a9549ca4de9597549347a0bcf697ed10f0419001a032 }
2019-04-25 07:53:25 UTC TRACE db canonize BestBlock { number: 1210155, hash: 00000000297862a76f327df51536befef374915a970bc27622a440c9ba890ef3 }
2019-04-25 07:53:25 UTC TRACE db canonize BestBlock { number: 1210156, hash: 000000008d9b09368b15bb23c3ec3196a4e56d577ce904853a4999f6c8bc51a9 }
2019-04-25 07:53:25 UTC TRACE db canonize BestBlock { number: 1210157, hash: 00000000aa8d0e286529edd073c7473c9221634fc067257e56b97abca7bc3021 }
2019-04-25 07:53:27 UTC WARN sync Block "00000000c7169675fc165bfeceb11b572129977ca9f9e6ca5953e3184cb403dd" verification failed with error "Transaction(95, Signature(0, SignatureNullDummy))"
2019-04-25 07:53:27 UTC WARN sync Disconnecting from peer#1 due to DoS: Provided wrong block 00000000c7169675fc165bfeceb11b572129977ca9f9e6ca5953e3184cb403dd
2019-04-25 07:53:27 UTC WARN sync Block "000000006acd2e4d0db279cbc1bd8451c0d0e392f335ed4f53908010e0f022f7" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000005dd7a5b98f03eee80bf51d06d9b92d4a347c168224175343b7cc937c" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "00000000fabb60e6738d361f62f44afcf1f62fa7e0cd8ac255909ac09e58a50b" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000001835a99880e6ed5725ee2e0d027307b44c7c6bf9f4930de7990ca960" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000001ace8407a21f2757843ce8a63b16fc1fce358c8abf8018f2363d1ad5" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000003d58f6af2c3bb18d87a7e5d8cf2fe5e03c75e1fd2d833602359d4409" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "00000000fd1652b95aa3139dabc96b2569d77fb9364089a0b851a3eb7da126f6" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "00000000906859d71cbfa41aadce8adde3cd01dfcf0515310813d4e19ff50e61" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "00000000ef22b5b3efe4392a42c482b5b592b5e4213e048f43f3d86c0e250f25" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000000edd18cab3c96553de54f603c702ecd91ce483d590971874c6811f99" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "00000000a4c7a964831746395f35024fdbeb7b06d80cdd6ebd3b7a26e5233c6f" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "0000000013728e7e41fffdf6f3fc0ee1339abaac3b0a13a7d15fc130b48e949c" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "00000000b0bec7dd4b7e394365b910d39ce3e23fa43f4bcd56cc24595858c2d9" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "0000000029e33b1ffa028aa1c925b2ce7bfb1912e9729fe583ce6a498ba15c29" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000001f92d0fc1e8e71e540c31f58984a4457d40dcc5871aaf24d31ce65e3" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "00000000a9d862e27259243bda4320b3a550fd96a509522bf4b512c2ede7eb00" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000002bcb3f89c1cac3835b38023b648ae28becb03de1a5fd0942b74d18d3" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:27 UTC WARN sync Block "000000003d2caf743d0623263235b73207a5e92a7d4bff261b904cbe0e7809bb" verification failed with error "Database(UnknownParent)"
2019-04-25 07:53:30 UTC WARN sync Disconnecting from peer#2 due to misbehavior: Provided dead-end block 000000002bcb3f89c1cac3835b38023b648ae28becb03de1a5fd0942b74d18d3
2019-04-25 07:53:31 UTC WARN sync Disconnecting from peer#4 due to misbehavior: Provided dead-end block 0000000098d9a551832dcd3f2f592ad94070b95e6a5c72be6e7138bae7b2e4bf
2019-04-25 07:53:31 UTC WARN sync Disconnecting from peer#3 due to misbehavior: Provided dead-end block 000000003d2caf743d0623263235b73207a5e92a7d4bff261b904cbe0e7809bb
2019-04-25 07:53:34 UTC INFO p2p::p2p Inbound connections: (0/10)
2019-04-25 07:53:34 UTC INFO p2p::p2p Outbound connections: (5/10)


```

Fix patch:
diff --git a/script/src/interpreter.rs b/script/src/interpreter.rs
index 0fb53971d..1376577b1 100644
--- a/script/src/interpreter.rs
+++ b/script/src/interpreter.rs
@@ -878,7 +878,7 @@ pub fn eval_script(
 				if v1 == v2 {
 					stack.push(vec![1].into());
 				} else {
-					stack.push(vec![0].into());
+					stack.push(Bytes::new());
 				}
 			},
 			Opcode::OP_EQUALVERIFY => {
@@ -995,7 +995,7 @@ pub fn eval_script(
 				if v2 <= v3 && v3 < v1 {
 					stack.push(vec![1].into());
 				} else {
-					stack.push(vec![0].into());
+					stack.push(Bytes::new());
 				}
 			},
 			Opcode::OP_RIPEMD160 => {
@@ -1044,7 +1044,7 @@ pub fn eval_script(
 						if success {
 							stack.push(vec![1].into());
 						} else {
-							stack.push(vec![0].into());
+							stack.push(Bytes::new());
 						}
 					},
 					Opcode::OP_CHECKSIGVERIFY if !success => {
@@ -1113,7 +1113,7 @@ pub fn eval_script(
 						if success {
 							stack.push(vec![1].into());
 						} else {
-							stack.push(vec![0].into());
+							stack.push(Bytes::new());
 						}
 					},
 					Opcode::OP_CHECKMULTISIGVERIFY if !success => {
@@ -1150,7 +1150,7 @@ pub fn eval_script(
 						if success {
 							stack.push(vec![1].into());
 						} else {
-							stack.push(vec![0].into());
+							stack.push(Bytes::new());
 						}
 					},
 					Opcode::OP_CHECKDATASIGVERIFY if !success => {
@@ -1269,7 +1269,7 @@ mod tests {
 			.push_opcode(Opcode::OP_EQUAL)
 			.into_script();
 		let result = Ok(false);
-		let stack = vec![vec![0].into()].into();
+		let stack = vec![Bytes::new()].into();
 		basic_test(&script, result, stack);
 	}
 
@@ -2101,7 +2101,7 @@ mod tests {
 			.push_opcode(Opcode::OP_WITHIN)
 			.into_script();
 		let result = Ok(false);
-		let stack = vec![vec![0].into()].into();
+		let stack = vec![Bytes::new()].into();
 		basic_test(&script, result, stack);
 	}
 
@@ -3958,7 +3958,7 @@ mod tests {
 			.push_data(&*pubkey)
 			.push_opcode(Opcode::OP_CHECKDATASIG)
 			.into_script();
-		basic_test_with_flags(&incorrect_signature_script, &correct_flags, Ok(false), vec![vec![0].into()].into());
+		basic_test_with_flags(&incorrect_signature_script, &correct_flags, Ok(false), vec![Bytes::new()].into());
 
 		// <sig> <msg> <pubKey> OP_CHECKDATASIG pops three elements and pushes false onto the stack if <sig> is an empty byte array.
 		let empty_signature_script = Builder::default()
@@ -3967,7 +3967,7 @@ mod tests {
 			.push_data(&*pubkey)
 			.push_opcode(Opcode::OP_CHECKDATASIG)
 			.into_script();
-		basic_test_with_flags(&empty_signature_script, &correct_flags, Ok(false), vec![vec![0].into()].into());
+		basic_test_with_flags(&empty_signature_script, &correct_flags, Ok(false), vec![Bytes::new()].into());
 
 		// <sig> <msg> <pubKey> OP_CHECKDATASIG pops three elements and pushes true onto the stack if <sig> is a valid signature of <msg> with respect to <pubKey>.
 		basic_test_with_flags(&correct_signature_script, &correct_flags, Ok(true), vec![vec![1].into()].into());
@@ -4046,4 +4046,29 @@ mod tests {
 		// Ok(false) means success here, because OP_CHECKDATASIGVERIFY leaves empty stack
 		basic_test_with_flags(&correct_signature_script, &correct_flags, Ok(false), vec![].into());
 	}
+
+	#[test]
+	fn op_equal_push_empty_bytes_to_stack() {
+		// tx #95 from testnet block:
+		// https://testnet.blockexplorer.com/block/00000000c7169675fc165bfeceb11b572129977ca9f9e6ca5953e3184cb403dd
+		// https://tbtc.bitaps.com/raw/transaction/27c94c0ca2f66fcc09d11b510e04d21adfe19f459673029e709024d7d9a7f4b4
+		// and its donor tx:
+		// https://tbtc.bitaps.com/raw/transaction/25e140942ecf79d24619908185a881f95d9ecb23a7be050f7c44cd378aae26eb
+		//
+		// the issue was that our comparison ops implementation (OP_EQUAL, OP_WITHIN, OP_CHECKSIG, ***)
+		// were pushing non-empty value (vec![0]) when comparison has failed
+		// => in combination with verify_nnulldummy this caused consensus issue
+
+		let tx: Transaction = "0100000001eb26ae8a37cd447c0f05bea723cb9e5df981a88581901946d279cf2e9440e1250000000091473044022057e887c4cb773a6ec513b285dde1209ee4213209c21bb9da9e284ffe7477979302201aba367cf84bf2c6ccfd1b18d2bec0d705e2acacfeb42324cdc0fe63fbe2524a01483045022100e3f2e5e2a0b6bb75f2a506d7b190d8ba48b1e9108dd4fc4a740fbc921d0067a3022070fccd6eec2415d6d75f7aa3d0604988ee84d856db2acde4cc01d9c43f0237a301ffffffff0100350c00000000001976a9149e2be3b4d5e7274e8fd739b09fc6fd223054616088ac00000000".into();
+		let signer: TransactionInputSigner = tx.into();
+		let checker = TransactionSignatureChecker {
+			signer: signer,
+			input_index: 0,
+			input_amount: 1000000,
+		};
+		let input: Script = "473044022057e887c4cb773a6ec513b285dde1209ee4213209c21bb9da9e284ffe7477979302201aba367cf84bf2c6ccfd1b18d2bec0d705e2acacfeb42324cdc0fe63fbe2524a01483045022100e3f2e5e2a0b6bb75f2a506d7b190d8ba48b1e9108dd4fc4a740fbc921d0067a3022070fccd6eec2415d6d75f7aa3d0604988ee84d856db2acde4cc01d9c43f0237a301".into();
+		let output: Script = "5253877c5121027fe085933328a89d0ad069071dee3bd4c908fddc852032356a318324c9ab0f6c210321e7c9eea060c099747ddcf741e9498a2b90fe8f362e2c85370722df0f88d1782102a5bc779306b40927648e73e144d430dc1b7c0730f6a3ab5bbd130374d8fe4a5a53af2102a70faff961b367875336396076a72293bf3adaa084404f8a5cbec23f41645b87ac".into();
+		let flags = VerificationFlags::default().verify_nulldummy(true);
+		assert_eq!(verify_script(&input, &output, &ScriptWitness::default(), &flags, &checker, SignatureVersion::Base), Ok(()));
+	}
 }


Test patch: