diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -51,6 +51,7 @@ test/blockstatus_tests.cpp \ test/bloom_tests.cpp \ test/bswap_tests.cpp \ + test/byteswap_tests.cpp \ test/cashaddr_tests.cpp \ test/cashaddrenc_tests.cpp \ test/checkdatasig_tests.cpp \ diff --git a/src/qt/test/compattests.cpp b/src/qt/test/compattests.cpp --- a/src/qt/test/compattests.cpp +++ b/src/qt/test/compattests.cpp @@ -16,7 +16,7 @@ #include void CompatTests::bswapTests() { - // Sibling in bitcoin/src/test/bswap_tests.cpp + // Sibling in bitcoin/src/test/byteswap_tests.cpp uint16_t u1 = 0x1234; uint32_t u2 = 0x56789abc; uint64_t u3 = 0xdef0123456789abc; diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1300,6 +1300,22 @@ } } break; + case OP_BSWAP: { + if (!(flags & SCRIPT_ENABLE_OP_BSWAP)) { + return set_error(serror, ScriptError::BAD_OPCODE); + } + + // (in -- out) + if (stack.size() < 1) { + return set_error( + serror, ScriptError::INVALID_STACK_OPERATION); + } + + valtype &data = stacktop(-1); + + std::reverse(data.begin(), data.end()); + } break; + default: return set_error(serror, ScriptError::BAD_OPCODE); } diff --git a/src/script/script_flags.h b/src/script/script_flags.h --- a/src/script/script_flags.h +++ b/src/script/script_flags.h @@ -105,6 +105,9 @@ // Whether to allow new OP_CHECKMULTISIG logic to trigger. (new multisig // logic verifies faster, and only allows Schnorr signatures) SCRIPT_ENABLE_SCHNORR_MULTISIG = (1U << 21), + + // Whether the new OP_BSWAP opcode can be used. + SCRIPT_ENABLE_OP_BSWAP = (1U << 22), }; #endif // BITCOIN_SCRIPT_SCRIPT_FLAGS_H diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -73,6 +73,7 @@ blockstatus_tests.cpp bloom_tests.cpp bswap_tests.cpp + byteswap_tests.cpp cashaddr_tests.cpp cashaddrenc_tests.cpp checkdatasig_tests.cpp diff --git a/src/test/bswap_tests.cpp b/src/test/bswap_tests.cpp --- a/src/test/bswap_tests.cpp +++ b/src/test/bswap_tests.cpp @@ -1,26 +1,126 @@ -// Copyright (c) 2016 The Bitcoin Core developers +// Copyright (c) 2018 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include +#include