Commit 45dd785f authored by Tom Zander's avatar Tom Zander
Browse files

Follow whole-script sizelimit.

Also add unit test for the op_return limits.
parent a9d3c2ee
Pipeline #269987458 passed with stages
in 19 minutes and 3 seconds
......@@ -70,7 +70,7 @@ bool IsStandard(const CScript &scriptPubKey, Script::TxnOutType &whichType, int
} else if (whichType == Script::TX_NULL_DATA) {
if (!fAcceptDatacarrier)
return false;
dataUsed += scriptPubKey.size() - 3; // (-1 for OP_RETURN, -2 for the pushdata opcodes)
dataUsed += scriptPubKey.size();
}
return whichType != Script::TX_NONSTANDARD;
......
......@@ -34,7 +34,7 @@ constexpr uint32_t DefaultCheckLevel = 3;
constexpr int32_t DefaultBlockAcceptSize = 128000000;
constexpr bool DefaultAcceptDataCarrier = true;
constexpr int MaxOpReturnRelay = 220; //! bytes
constexpr int MaxOpReturnRelay = 223;
constexpr bool DefaultRelayPriority = true;
/** Default for setting that we download and accept blocks only (no transactions, no mempool) */
......
......@@ -334,14 +334,34 @@ void TransactionTests::test_IsStandard()
t.vout[0].scriptPubKey = CScript() << OP_RETURN
<< ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
QCOMPARE(Settings::MaxOpReturnRelay + 3, t.vout[0].scriptPubKey.size());
QCOMPARE(Settings::MaxOpReturnRelay, t.vout[0].scriptPubKey.size());
QVERIFY(IsStandardTx(t, reason));
// Multiple op-returns.
t.vout.push_back(t.vout.at(0));
t.vout[0].scriptPubKey = CScript() << OP_RETURN // 58 + 2 bytes
<< ParseHex("04678afdb0fe55482719bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38123456");
t.vout[1].scriptPubKey = CScript() << OP_RETURN // 103 + 3 bytes
<< ParseHex("04678afdb0fe55482719bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
QVERIFY(IsStandardTx(t, reason));
// limit is currently 223
t.vout.push_back(t.vout.at(0));
t.vout[2].scriptPubKey = CScript() << OP_RETURN // 57 + 2
<< ParseHex("04678afdb0fe55482719bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
QVERIFY(IsStandardTx(t, reason)); // exactly within limit.
// one byte over limit.
t.vout[2].scriptPubKey = t.vout[1].scriptPubKey;
QCOMPARE(IsStandardTx(t, reason), false);
QCOMPARE(reason, "oversize-op-return");
t.vout.resize(1);
// MAX_OP_RETURN_RELAY+1-byte TX_NULL_DATA (non-standard)
t.vout[0].scriptPubKey = CScript() << OP_RETURN
<< ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800"
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
QCOMPARE(Settings::MaxOpReturnRelay + 4, t.vout[0].scriptPubKey.size());
QCOMPARE(Settings::MaxOpReturnRelay + 1, t.vout[0].scriptPubKey.size());
QVERIFY(!IsStandardTx(t, reason));
// Data payload can be encoded in any way...
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment