Skip to content

Commit 4d4bd5e

Browse files
committed
Merge #17204: wallet: Do not turn OP_1NEGATE in scriptSig into 0x0181 in signing code (sipa)
dca2863 test: ensure OP_1NEGATE satisfies BIP62 minimal push rule (Jon Atack) e629d07 Do not turn OP_1NEGATE in scriptSig into 0x0181 in signing code (Pieter Wuille) Pull request description: A rebase of #13084 which additionally modifies the test code (unaddressed in the original, assuming sipa is too busy to deal with this at the moment). Relatively simple bugfix so it'd be good to have merged soon. Turning OP_1NEGATE into 0x0181 results in a larger-than-necessary data push instead of just actually using the OP_1NEGATE opcode (0x4f). This fails the minimal push rule of BIP 62 and makes the result non-standard. ACKs for top commit: fjahr: Code review ACK dca2863 luke-jr: ACK dca2863 jonatack: ACK dca2863 Tree-SHA512: 706d9a2ef20c809dea923e477a873e2fd60db8d0ae64289e510b766a38005c1f31ab0b5883f16b9c7863ff0d3f705e8e413f6121320028ac196b79c3184a4113
2 parents dabab06 + dca2863 commit 4d4bd5e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/script/sign.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ static CScript PushAll(const std::vector<valtype>& values)
186186
result << OP_0;
187187
} else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
188188
result << CScript::EncodeOP_N(v[0]);
189+
} else if (v.size() == 1 && v[0] == 0x81) {
190+
result << OP_1NEGATE;
189191
} else {
190192
result << v;
191193
}

src/test/transaction_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ static CScript PushAll(const std::vector<valtype>& values)
361361
result << OP_0;
362362
} else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
363363
result << CScript::EncodeOP_N(v[0]);
364+
} else if (v.size() == 1 && v[0] == 0x81) {
365+
result << OP_1NEGATE;
364366
} else {
365367
result << v;
366368
}

test/functional/rpc_signrawtransaction.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,30 @@ def verify_txn_with_witness_script(self, tx_type):
198198
assert_equal(spending_tx_signed['complete'], True)
199199
self.nodes[0].sendrawtransaction(spending_tx_signed['hex'])
200200

201+
def OP_1NEGATE_test(self):
202+
self.log.info("Test OP_1NEGATE (0x4f) satisfies BIP62 minimal push standardness rule")
203+
hex_str = (
204+
"0200000001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
205+
"FFFFFFFF00000000044F024F9CFDFFFFFF01F0B9F5050000000023210277777777"
206+
"77777777777777777777777777777777777777777777777777777777AC66030000"
207+
)
208+
prev_txs = [
209+
{
210+
"txid": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
211+
"vout": 0,
212+
"scriptPubKey": "A914AE44AB6E9AA0B71F1CD2B453B69340E9BFBAEF6087",
213+
"redeemScript": "4F9C",
214+
"amount": 1,
215+
}
216+
]
217+
txn = self.nodes[0].signrawtransactionwithwallet(hex_str, prev_txs)
218+
assert txn["complete"]
219+
201220
def run_test(self):
202221
self.successful_signing_test()
203222
self.script_verification_error_test()
204223
self.witness_script_test()
224+
self.OP_1NEGATE_test()
205225
self.test_with_lock_outputs()
206226

207227

0 commit comments

Comments
 (0)