mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-24 06:11:12 +02:00
Merge bitcoin/bitcoin#33047: test: check proper OP_2ROT behavior
b94c6356a2
test: check proper OP_2ROT behavior (brunoerg) Pull request description: According to corecheck, the following mutant is not caught by any test (https://corecheck.dev/mutation/src/script/interpreter.cpp). ```diff diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 61ea7f4503..4f6fa34836 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -746,7 +746,6 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); valtype vch1 = stacktop(-6); valtype vch2 = stacktop(-5); - stack.erase(stack.end()-6, stack.end()-4); stack.push_back(vch1); stack.push_back(vch2); } ``` It means we're not testing the behavior of the OP_2ROT opcode properly. The normal behavior is: `[1, 2, 3, 4, 5, 6] → OP_2ROT → [3, 4, 5, 6, 1, 2]` (6 elements). However, by deleting the `erase`, it becomes: `[1, 2, 3, 4, 5, 6] → OP_2ROT → [1, 2, 3, 4, 5, 6, 1, 2] (8 elements)` which is obviously wrong. In `script_tests.json`, we have some test cases that includes the OP_2ROT which correctly tests the move part of 2ROT but not the erase one. See: ``` ["25 24 23 22 21 20", "2ROT 24 EQUAL", "P2SH,STRICTENC", "OK"], ["25 24 23 22 21 20", "2ROT DROP 25 EQUAL", "P2SH,STRICTENC", "OK"], ["25 24 23 22 21 20", "2ROT 2DROP 20 EQUAL", "P2SH,STRICTENC", "OK"], ["25 24 23 22 21 20", "2ROT 2DROP DROP 21 EQUAL", "P2SH,STRICTENC", "OK"], ["25 24 23 22 21 20", "2ROT 2DROP 2DROP 22 EQUAL", "P2SH,STRICTENC", "OK"], ["25 24 23 22 21 20", "2ROT 2DROP 2DROP DROP 23 EQUAL", "P2SH,STRICTENC", "OK"], ["25 24 23 22 21 20", "2ROT 2ROT 22 EQUAL", "P2SH,STRICTENC", "OK"], ["25 24 23 22 21 20", "2ROT 2ROT 2ROT 20 EQUAL", "P2SH,STRICTENC", "OK"], ``` That said, this PR adds one more test case to the case mentioned. ACKs for top commit: maflcko: lgtm ACKb94c6356a2
l0rinc: ACKb94c6356a2
w0xlt: ACKb94c6356a2
Tree-SHA512: 077d83faedcf444b9489928e1601c96bee91ee5c793a494e7e6fa34eabd216ab8706b5fed3d979fba910bd39f3f917c8562380e79cd35d6b7487ad68ca409d5f
This commit is contained in:
@@ -105,6 +105,7 @@
|
||||
["25 24 23 22 21 20", "2ROT 2DROP 2DROP DROP 23 EQUAL", "P2SH,STRICTENC", "OK"],
|
||||
["25 24 23 22 21 20", "2ROT 2ROT 22 EQUAL", "P2SH,STRICTENC", "OK"],
|
||||
["25 24 23 22 21 20", "2ROT 2ROT 2ROT 20 EQUAL", "P2SH,STRICTENC", "OK"],
|
||||
["1 2 3 4 5 6", "2ROT DEPTH 6 EQUAL", "P2SH,STRICTENC", "OK"],
|
||||
["1 0", "SWAP 1 EQUALVERIFY 0 EQUAL", "P2SH,STRICTENC", "OK"],
|
||||
["0 1", "TUCK DEPTH 3 EQUALVERIFY SWAP 2DROP", "P2SH,STRICTENC", "OK"],
|
||||
["13 14", "2DUP ROT EQUALVERIFY EQUAL", "P2SH,STRICTENC", "OK"],
|
||||
|
Reference in New Issue
Block a user