Skip to content

Commit fd3d80c

Browse files
committed
Merge bitcoin/bitcoin#33047: test: check proper OP_2ROT behavior
b94c635 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 61ea7f4..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 ACK b94c635 l0rinc: ACK b94c635 w0xlt: ACK bitcoin/bitcoin@b94c635 Tree-SHA512: 077d83faedcf444b9489928e1601c96bee91ee5c793a494e7e6fa34eabd216ab8706b5fed3d979fba910bd39f3f917c8562380e79cd35d6b7487ad68ca409d5f
2 parents 1119ac5 + b94c635 commit fd3d80c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/test/data/script_tests.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
["25 24 23 22 21 20", "2ROT 2DROP 2DROP DROP 23 EQUAL", "P2SH,STRICTENC", "OK"],
106106
["25 24 23 22 21 20", "2ROT 2ROT 22 EQUAL", "P2SH,STRICTENC", "OK"],
107107
["25 24 23 22 21 20", "2ROT 2ROT 2ROT 20 EQUAL", "P2SH,STRICTENC", "OK"],
108+
["1 2 3 4 5 6", "2ROT DEPTH 6 EQUAL", "P2SH,STRICTENC", "OK"],
108109
["1 0", "SWAP 1 EQUALVERIFY 0 EQUAL", "P2SH,STRICTENC", "OK"],
109110
["0 1", "TUCK DEPTH 3 EQUALVERIFY SWAP 2DROP", "P2SH,STRICTENC", "OK"],
110111
["13 14", "2DUP ROT EQUALVERIFY EQUAL", "P2SH,STRICTENC", "OK"],

0 commit comments

Comments
 (0)