Merge branch 'master' into segwit

This commit is contained in:
Luke Dashjr
2016-11-22 10:52:02 +00:00
7 changed files with 1482 additions and 11 deletions

12
.gitignore vendored
View File

@@ -1,3 +1,10 @@
*.gcov
*.gcda
*.gcno
vgcore*
core*
*.orig
*.rej
*~
*.so
*.o
@@ -24,3 +31,8 @@ config.*
ii
ar-lib
compile
test-driver
test
test-suite.log
test.log
test.trs

139
.travis.yml Normal file
View File

@@ -0,0 +1,139 @@
os: linux
language: c
compiler: gcc
sudo: false
env:
global:
- PKG_CONFIG_LIBDIR="$HOME/lib/pkgconfig"
- OPTS="--prefix=$HOME"
matrix:
include:
# Normal build
- addons:
apt:
packages:
- build-essential
- libjansson-dev
- libgcrypt11-dev
env: CFLAGS="-Wall" AM_CFLAGS='-Werror'
# clang
- compiler: clang
addons:
apt:
packages:
- build-essential
- libjansson-dev
- libgcrypt11-dev
env: CFLAGS="-Wall -fsanitize=undefined -fno-sanitize-recover -fsanitize=address"
# clang
- compiler: clang
addons:
apt:
packages:
- build-essential
env:
- BUILD_LIBS=1
JANSSON_VERSION=v2.1
CFLAGS="-O0 -ggdb -Wall -fsanitize=undefined -fno-sanitize-recover -fsanitize=memory -fPIE -pie"
LDFLAGS="-fsanitize=memory -fPIE -pie -L$HOME/lib"
# w/o libgcrypt
- addons:
apt:
packages:
- build-essential
- libjansson-dev
# Win32
- addons:
apt:
packages:
- gcc-mingw-w64-i686
- binutils-mingw-w64-i686
- mingw-w64-dev
- wine
env:
- CROSS_TARGET=i686-w64-mingw32
EXEEXT=.exe
BUILD_LIBS=1
WINE_TESTS=1
OPTS="$OPTS --disable-static"
JANSSON_VERSION=v2.4
# Win64
- addons:
apt:
packages:
- gcc-mingw-w64-x86-64
- binutils-mingw-w64-x86-64
- mingw-w64-dev
- wine
env:
- CROSS_TARGET=x86_64-w64-mingw32
EXEEXT=.exe
BUILD_LIBS=1
WINE_TESTS=1
OPTS="$OPTS --disable-static"
JANSSON_VERSION=v2.4
exclude:
- compiler: gcc
# TODO: Linux32 (or 64) & OS X
script:
- if [ -n "$CROSS_TARGET" ]; then
unset CC;
TARGET_OPTS="$TARGET_OPTS --host=$CROSS_TARGET";
fi
- if [ -n "$BUILD_LIBS" ]; then
OPTS="$OPTS --with-gpg-error-prefix=$HOME";
git clone git://git.gnupg.org/libgpg-error.git -b libgpg-error-1.13 --depth 1;
pushd libgpg-error;
./autogen.sh;
./configure $TARGET_OPTS $OPTS --disable-languages --disable-doc;
make;
if [ -z "$WINE_TESTS" ]; then
LD_LIBRARY_PATH="$HOME/lib" make check;
fi;
make install;
popd;
OPTS="$OPTS --with-libgcrypt-prefix=$HOME";
git clone git://git.gnupg.org/libgcrypt.git -b libgcrypt-1.5.4 --depth 1;
pushd libgcrypt;
./autogen.sh;
./configure $TARGET_OPTS $OPTS --disable-ciphers --disable-pubkey-ciphers --disable-random --disable-asm;
make;
if [ -z "$WINE_TESTS" ]; then
LD_LIBRARY_PATH="$HOME/lib" make check;
fi;
make install;
popd;
git clone https://github.com/akheron/jansson.git -b "$JANSSON_VERSION" --depth 1;
pushd jansson;
autoreconf -f -i;
./configure $TARGET_OPTS $OPTS;
make AM_CFLAGS= ;
if [ -z "$WINE_TESTS" ]; then
LD_LIBRARY_PATH="$HOME/lib" make check;
fi;
make install;
popd;
fi
- git clone git://github.com/bitcoin/libbase58 -b v0.1.4 --depth 1
- pushd libbase58
- ./autogen.sh
- ./configure $TARGET_OPTS $OPTS
- make
- if [ -z "$WINE_TESTS" ]; then
LD_LIBRARY_PATH="$HOME/lib" make check;
fi
- make install
- popd
-
- ./autogen.sh
- ./configure $TARGET_OPTS $OPTS $CONFIGURE_OPTS || { tail -n 1000 config.log; false; };
- make
- make example$EXEEXT
- if [ -z "$WINE_TESTS" ]; then
LSAN_OPTIONS=1 LD_LIBRARY_PATH="$HOME/lib" make check;
else
ln -s $HOME/bin/*.dll .libs/;
LSAN_OPTIONS=1 WINEDLLPATH="$PWD/.libs" wine .libs/test.exe;
fi
- make install

View File

@@ -50,14 +50,20 @@ dist_noinst_DATA = \
AUTHORS COPYING README \
example.c \
testinput.c
if HAVE_LIBGCRYPT
noinst_PROGRAMS = test
test_SOURCES = test.c
test_CFLAGS = $(libbase58_CFLAGS) $(JANSSON_CFLAGS) $(LIBGCRYPT_CFLAGS)
test_LDADD = $(libbase58_LIBS) libblkmaker-@LIBBLKMAKER_API_VERSION@.la libblkmaker_jansson-@LIBBLKMAKER_API_VERSION@.la $(JANSSON_LIBS) $(LIBGCRYPT_LIBS)
TESTS = test
if CAN_COMPILE_EXAMPLE
EXTRA_PROGRAMS = example
example_SOURCES = example.c
example_LDADD = libblkmaker-$(LIBBLKMAKER_API_VERSION).la libblkmaker_jansson-$(LIBBLKMAKER_API_VERSION).la $(LIBGCRYPT_LIBS)
example_CFLAGS = $(LIBGCRYPT_CFLAGS)
example_CFLAGS = $(libbase58_CFLAGS) $(JANSSON_CFLAGS) $(LIBGCRYPT_CFLAGS)
example_LDADD = $(libbase58_LIBS) libblkmaker-@LIBBLKMAKER_API_VERSION@.la libblkmaker_jansson-@LIBBLKMAKER_API_VERSION@.la $(JANSSON_LIBS) $(LIBGCRYPT_LIBS)
else
example:
@echo "libgcrypt is required to build the example, but was not found"
@echo "libgcrypt is required to build the example, but was not found"
.PHONY: example
endif

View File

@@ -176,6 +176,12 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
return 0;
}
if (!tmpl->cbvalue) {
// TODO: Figure it out from the existing cbtxn
*inout_newcb = false;
return 0;
}
*inout_newcb = true;
if (scriptsz >= 0xfd)
@@ -473,8 +479,9 @@ bool _blkmk_append_cb(blktemplate_t * const tmpl, void * const vout, const void
unsigned char *in = tmpl->cbtxn->data;
size_t insz = tmpl->cbtxn->datasz;
if (in[cbScriptSigLen] > libblkmaker_coinbase_size_limit - appendsz)
if (appendsz > libblkmaker_coinbase_size_limit || in[cbScriptSigLen] > libblkmaker_coinbase_size_limit - appendsz) {
return false;
}
const unsigned long pretx_size = libblkmaker_blkheader_size + blkmk_varint_encode_size(1 + tmpl->txncount);
if (pretx_size + tmpl->cbtxn->datasz + tmpl->txns_datasz + appendsz > tmpl->sizelimit) {
@@ -504,7 +511,7 @@ bool _blkmk_append_cb(blktemplate_t * const tmpl, void * const vout, const void
out[cbScriptSigLen] += appendsz;
memcpy(outExtranonce, append, appendsz);
const int16_t sigops_counted = (tmpl->cbtxn->sigops_ - orig_scriptSig_sigops) + blkmk_count_sigops(&out[cbScriptSigLen + 1], out[cbScriptSigLen], tmpl->_bip141_sigops);
const int16_t sigops_counted = tmpl->cbtxn->sigops_ + blkmk_count_sigops(&out[cbScriptSigLen + 1], out[cbScriptSigLen], tmpl->_bip141_sigops) - orig_scriptSig_sigops;
if (tmpl->txns_sigops >= 0 && tmpl->txns_sigops + sigops_counted > tmpl->sigoplimit) {
// Overflowed :(
if (out == in) {
@@ -536,6 +543,9 @@ ssize_t blkmk_append_coinbase_safe2(blktemplate_t * const tmpl, const void * con
if (extranoncesz < sizeof(unsigned int))
extranoncesz = sizeof(unsigned int);
}
if (extranoncesz > libblkmaker_coinbase_size_limit || tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit || extranoncesz + tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit) {
return -5;
}
size_t availsz = libblkmaker_coinbase_size_limit - extranoncesz - tmpl->cbtxn->data[cbScriptSigLen];
{
const unsigned long pretx_size = libblkmaker_blkheader_size + blkmk_varint_encode_size(1 + tmpl->txncount);

View File

@@ -51,18 +51,18 @@ PKG_CHECK_MODULES([libbase58],[libbase58])
AC_CHECK_LIB([ws2_32], [strchr])
dnl libgcrypt necessary to build example.c with "make example"
dnl libgcrypt necessary to build tests and example
dnl check for libgcrypt:
m4_ifdef([AM_PATH_LIBGCRYPT], [
AM_PATH_LIBGCRYPT([],
[
can_compile_example=yes
have_libgcrypt=yes
],[
can_compile_example=no
have_libgcrypt=no
])
],[
m4_warn([syntax], [AM_PATH_LIBGCRYPT missing; example will not be available])
m4_warn([syntax], [AM_PATH_LIBGCRYPT missing; example and tests will not be available])
])
AM_CONDITIONAL([CAN_COMPILE_EXAMPLE], [test x$can_compile_example = xyes])
AM_CONDITIONAL([HAVE_LIBGCRYPT], [test x$have_libgcrypt = xyes])
AC_OUTPUT

View File

@@ -9,7 +9,11 @@
#include <inttypes.h>
#include <stdint.h>
#ifndef WIN32
#include <arpa/inet.h>
#else
#include <winsock2.h>
#endif
#include <gcrypt.h>
#include <libbase58.h>
@@ -127,4 +131,5 @@ int main(int argc, char**argv) {
send_json(req);
}
blktmpl_free(tmpl);
return 0;
}

1299
test.c Normal file

File diff suppressed because it is too large Load Diff