diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -50,6 +50,7 @@ test/blockindex_tests.cpp \ test/blockstatus_tests.cpp \ test/bloom_tests.cpp \ + test/bswap_opcode_tests.cpp \ test/bswap_tests.cpp \ test/cashaddr_tests.cpp \ test/cashaddrenc_tests.cpp \ diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1235,6 +1235,22 @@ stacktop(-1) = std::move(n2); } 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; + // // Conversion operations // 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 << 23), }; #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 @@ -72,6 +72,7 @@ blockindex_tests.cpp blockstatus_tests.cpp bloom_tests.cpp + bswap_opcode_tests.cpp bswap_tests.cpp cashaddr_tests.cpp cashaddrenc_tests.cpp diff --git a/src/test/bswap_opcode_tests.cpp b/src/test/bswap_opcode_tests.cpp new file mode 100644 --- /dev/null +++ b/src/test/bswap_opcode_tests.cpp @@ -0,0 +1,128 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include