Commit fd3d80c
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: 077d83faedcf444b9489928e1601c96bee91ee5c793a494e7e6fa34eabd216ab8706b5fed3d979fba910bd39f3f917c8562380e79cd35d6b7487ad68ca409d5f1 file changed
+1
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
0 commit comments