Compare commits

...

10 Commits

Author SHA1 Message Date
a8c3a2f4f2 Update Makefile.new.am 2024-09-14 22:56:02 +02:00
8122343d8b Update Makefile.am 2024-09-14 22:55:56 +02:00
0d069272f3 Update Makefile.am 2024-09-14 22:55:50 +02:00
e81eb0fc81 Update INSTALL 2024-09-14 22:55:45 +02:00
5a537fe0f8 Update configure.ac 2024-09-14 22:55:38 +02:00
604186fb9c Update .gitignore 2024-09-14 22:55:33 +02:00
95e2745a15 Create libneobytesconsensus.pc.in 2024-09-14 22:55:26 +02:00
f000210b2c Delete libbitcoinconsensus.pc.in 2024-09-14 22:55:20 +02:00
edbeec022a Create neobytescoinconsensus.cpp 2024-09-14 22:55:14 +02:00
88ea13f20a Create neobytescoinconsensus.h 2024-09-14 22:55:09 +02:00
9 changed files with 198 additions and 31 deletions

2
.gitignore vendored
View File

@ -123,7 +123,7 @@ share/BitcoindComparisonTool.jar
.autotools
/doc/doxygen/
libbitcoinconsensus.pc
libneobytesconsensus.pc
src/qt/neobytes-qt.bash
qa/pull-tester/tests-config.sh

View File

@ -1,5 +1,5 @@
Building NeoBytes
=================
See doc/build-*.md for instructions on building the various
elements of the NeoBytes Core reference implementation of NeoBytes.
See doc/build-*.md for instructions on building neobytesd,
the intended-for-services, no-graphical-interface, reference
implementation of NeoBytes.

View File

@ -6,7 +6,7 @@ GZIP_ENV="-9n"
if BUILD_BITCOIN_LIBS
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libbitcoinconsensus.pc
pkgconfig_DATA = libneobytesconsensus.pc
endif
BITCOIND_BIN=$(top_builddir)/src/neobytesd$(EXEEXT)

View File

@ -789,7 +789,7 @@ AC_MSG_CHECKING([whether to build libraries])
AM_CONDITIONAL([BUILD_BITCOIN_LIBS], [test x$build_bitcoin_libs = xyes])
if test x$build_bitcoin_libs = xyes; then
AC_DEFINE(HAVE_CONSENSUS_LIB, 1, [Define this symbol if the consensus lib has been built])
AC_CONFIG_FILES([libbitcoinconsensus.pc:libbitcoinconsensus.pc.in])
AC_CONFIG_FILES([libneobytesconsensus.pc:libneobytesconsensus.pc.in])
fi
AC_MSG_RESULT($build_bitcoin_libs)

View File

@ -3,9 +3,9 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: Bitcoin Core consensus library
Description: Library for the Bitcoin consensus protocol.
Name: NeoBytes Core consensus library
Description: Library for the NeoBytes consensus protocol.
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lbitcoinconsensus
Libs: -L${libdir} -lneobytesconsensus
Cflags: -I${includedir}
Requires.private: libcrypto

View File

@ -44,8 +44,8 @@ EXTRA_LIBRARIES += libbitcoin_zmq.a
endif
if BUILD_BITCOIN_LIBS
lib_LTLIBRARIES = libbitcoinconsensus.la
LIBBITCOIN_CONSENSUS=libbitcoinconsensus.la
lib_LTLIBRARIES = libneobytesconsensus.la
LIBBITCOIN_CONSENSUS=libneobytesconsensus.la
else
LIBBITCOIN_CONSENSUS=
endif
@ -454,10 +454,10 @@ neobytes_tx_LDADD = \
neobytes_tx_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
#
# bitcoinconsensus library #
# neobytescoinconsensus library #
if BUILD_BITCOIN_LIBS
include_HEADERS = script/bitcoinconsensus.h
libbitcoinconsensus_la_SOURCES = \
include_HEADERS = script/neobytescoinconsensus.h
libneobytesconsensus_la_SOURCES = \
crypto/hmac_sha512.cpp \
crypto/ripemd160.cpp \
crypto/sha1.cpp \
@ -466,20 +466,20 @@ libbitcoinconsensus_la_SOURCES = \
hash.cpp \
primitives/transaction.cpp \
pubkey.cpp \
script/bitcoinconsensus.cpp \
script/neobytescoinconsensus.cpp \
script/interpreter.cpp \
script/script.cpp \
uint256.cpp \
utilstrencodings.cpp
if GLIBC_BACK_COMPAT
libbitcoinconsensus_la_SOURCES += compat/glibc_compat.cpp
libneobytesconsensus_la_SOURCES += compat/glibc_compat.cpp
endif
libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1)
libbitcoinconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL
libbitcoinconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libneobytesconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libneobytesconsensus_la_LIBADD = $(LIBSECP256K1)
libneobytesconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL
libneobytesconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
endif
#

View File

@ -58,8 +58,8 @@ EXTRA_LIBRARIES += libbitcoin_zmq.a
endif
if BUILD_BITCOIN_LIBS
lib_LTLIBRARIES = libbitcoinconsensus.la
LIBBITCOIN_CONSENSUS=libbitcoinconsensus.la
lib_LTLIBRARIES = libneobytesconsensus.la
LIBBITCOIN_CONSENSUS=libneobytesconsensus.la
else
LIBBITCOIN_CONSENSUS=
endif
@ -456,10 +456,10 @@ neobytes_tx_LDADD = \
neobytes_tx_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS)
#
# bitcoinconsensus library #
# neobytescoinconsensus library #
if BUILD_BITCOIN_LIBS
include_HEADERS = script/bitcoinconsensus.h
libbitcoinconsensus_la_SOURCES = \
include_HEADERS = script/neobytescoinconsensus.h
libneobytesconsensus_la_SOURCES = \
crypto/hmac_sha512.cpp \
crypto/ripemd160.cpp \
crypto/sha1.cpp \
@ -468,20 +468,20 @@ libbitcoinconsensus_la_SOURCES = \
hash.cpp \
primitives/transaction.cpp \
pubkey.cpp \
script/bitcoinconsensus.cpp \
script/neobytescoinconsensus.cpp \
script/interpreter.cpp \
script/script.cpp \
uint256.cpp \
utilstrencodings.cpp
if GLIBC_BACK_COMPAT
libbitcoinconsensus_la_SOURCES += compat/glibc_compat.cpp
libneobytesconsensus_la_SOURCES += compat/glibc_compat.cpp
endif
libbitcoinconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libbitcoinconsensus_la_LIBADD = $(LIBSECP256K1)
libbitcoinconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL
libbitcoinconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libneobytesconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libneobytesconsensus_la_LIBADD = $(LIBSECP256K1)
libneobytesconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL
libneobytesconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
endif
#

View File

@ -0,0 +1,98 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "neobytescoinconsensus.h"
#include "primitives/transaction.h"
#include "pubkey.h"
#include "script/interpreter.h"
#include "version.h"
namespace {
/** A class that deserializes a single CTransaction one time. */
class TxInputStream
{
public:
TxInputStream(int nTypeIn, int nVersionIn, const unsigned char *txTo, size_t txToLen) :
m_type(nTypeIn),
m_version(nVersionIn),
m_data(txTo),
m_remaining(txToLen)
{}
TxInputStream& read(char* pch, size_t nSize)
{
if (nSize > m_remaining)
throw std::ios_base::failure(std::string(__func__) + ": end of data");
if (pch == NULL)
throw std::ios_base::failure(std::string(__func__) + ": bad destination buffer");
if (m_data == NULL)
throw std::ios_base::failure(std::string(__func__) + ": bad source buffer");
memcpy(pch, m_data, nSize);
m_remaining -= nSize;
m_data += nSize;
return *this;
}
template<typename T>
TxInputStream& operator>>(T& obj)
{
::Unserialize(*this, obj, m_type, m_version);
return *this;
}
private:
const int m_type;
const int m_version;
const unsigned char* m_data;
size_t m_remaining;
};
inline int set_error(neobytesconsensus_error* ret, neobytesconsensus_error serror)
{
if (ret)
*ret = serror;
return 0;
}
struct ECCryptoClosure
{
ECCVerifyHandle handle;
};
ECCryptoClosure instance_of_eccryptoclosure;
}
int neobytesconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
const unsigned char *txTo , unsigned int txToLen,
unsigned int nIn, unsigned int flags, neobytesconsensus_error* err)
{
try {
TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen);
CTransaction tx;
stream >> tx;
if (nIn >= tx.vin.size())
return set_error(err, neobytesconsensus_ERR_TX_INDEX);
if (tx.GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION) != txToLen)
return set_error(err, neobytesconsensus_ERR_TX_SIZE_MISMATCH);
// Regardless of the verification result, the tx did not error.
set_error(err, neobytesconsensus_ERR_OK);
return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), flags, TransactionSignatureChecker(&tx, nIn), NULL);
} catch (const std::exception&) {
return set_error(err, neobytesconsensus_ERR_TX_DESERIALIZE); // Error deserializing
}
}
unsigned int neobytesconsensus_version()
{
// Just use the API version for now
return NEOBYTESCONSENSUS_API_VER;
}

View File

@ -0,0 +1,69 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_NEOBYTESCONSENSUS_H
#define BITCOIN_NEOBYTESCONSENSUS_H
#if defined(BUILD_BITCOIN_INTERNAL) && defined(HAVE_CONFIG_H)
#include "config/neobytes-config.h"
#if defined(_WIN32)
#if defined(DLL_EXPORT)
#if defined(HAVE_FUNC_ATTRIBUTE_DLLEXPORT)
#define EXPORT_SYMBOL __declspec(dllexport)
#else
#define EXPORT_SYMBOL
#endif
#endif
#elif defined(HAVE_FUNC_ATTRIBUTE_VISIBILITY)
#define EXPORT_SYMBOL __attribute__ ((visibility ("default")))
#endif
#elif defined(MSC_VER) && !defined(STATIC_LIBNEOBYTESCONSENSUS)
#define EXPORT_SYMBOL __declspec(dllimport)
#endif
#ifndef EXPORT_SYMBOL
#define EXPORT_SYMBOL
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define NEOBYTESCONSENSUS_API_VER 0
typedef enum neobytesconsensus_error_t
{
neobytesconsensus_ERR_OK = 0,
neobytesconsensus_ERR_TX_INDEX,
neobytesconsensus_ERR_TX_SIZE_MISMATCH,
neobytesconsensus_ERR_TX_DESERIALIZE,
} neobytesconsensus_error;
/** Script verification flags */
enum
{
neobytesconsensus_SCRIPT_FLAGS_VERIFY_NONE = 0,
neobytesconsensus_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts
neobytesconsensus_SCRIPT_FLAGS_VERIFY_DERSIG = (1U << 2), // enforce strict DER (BIP66) compliance
neobytesconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
};
/// Returns 1 if the input nIn of the serialized transaction pointed to by
/// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under
/// the additional constraints specified by flags.
/// If not NULL, err will contain an error/success code for the operation
EXPORT_SYMBOL int neobytesconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
const unsigned char *txTo , unsigned int txToLen,
unsigned int nIn, unsigned int flags, neobytesconsensus_error* err);
EXPORT_SYMBOL unsigned int neobytesconsensus_version();
#ifdef __cplusplus
} // extern "C"
#endif
#undef EXPORT_SYMBOL
#endif // BITCOIN_NEOBYTESCONSENSUS_H