Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/LIMXTEC/BitCore into 0.9.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
limxdev committed May 2, 2020
2 parents b253389 + 1c6e04f commit 0606cbc
Show file tree
Hide file tree
Showing 19 changed files with 1,286 additions and 36 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 90)
define(_CLIENT_VERSION_REVISION, 9)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2020)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand Down
5 changes: 4 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,11 @@ crypto_libbitcoin_crypto_base_a_SOURCES += \
crypto/sph_whirlpool.h \
crypto/sponge.c \
crypto/sponge.h \
crypto/tiger.cpp \
crypto/sph_tiger.h \
crypto/x11.h \
crypto/x16r.h
crypto/x16r.h \
crypto/x16rv2.h


if USE_ASM
Expand Down
1 change: 1 addition & 0 deletions src/consensus/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const int64_t MAX_BLOCK_SIGOPS_COST = 500000; // BTX: 80000
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100;
static const int COINBASE_MATURITY_2 = 576;
static const int COINBASE_MATURITY_3 = 4032;

static const int WITNESS_SCALE_FACTOR = 4;

Expand Down
24 changes: 23 additions & 1 deletion src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe

bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee)
{
int AHeight = chainActive.Height();
// are the actual inputs available?
if (!inputs.HaveInputs(tx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-missingorspent", false,
Expand All @@ -225,12 +226,33 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, c
// If prev is coinbase, check that it's matured
// if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < COINBASE_MATURITY) {
// BTX BEGIN
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < (!sporkManager.IsSporkActive(SPORK_BTX_15_COINBASE_MATURITY_STAGE_2)? COINBASE_MATURITY : COINBASE_MATURITY_2 )) {
if (AHeight < 590000)
{
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < COINBASE_MATURITY)
{
return state.Invalid(false,
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
}
}
else
{
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < (!sporkManager.IsSporkActive(SPORK_BTX_16_COINBASE_MATURITY_STAGE_3)? COINBASE_MATURITY_2 : COINBASE_MATURITY_3 ))
{
return state.Invalid(false,
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
}
}
/*
if (coin.IsCoinBase() && nSpendHeight - coin.nHeight < (!sporkManager.IsSporkActive(SPORK_BTX_16_COINBASE_MATURITY_STAGE_3)? COINBASE_MATURITY_2 : COINBASE_MATURITY_3 )) {
return state.Invalid(false,
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
strprintf("tried to spend coinbase at depth %d", nSpendHeight - coin.nHeight));
}
*/
// BTX END

// Check for negative or overflow input values
nValueIn += coin.out.nValue;
if (!MoneyRange(coin.out.nValue) || !MoneyRange(nValueIn)) {
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/tx_verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define BITCORE_CONSENSUS_TX_VERIFY_H

#include <amount.h>

#include <validation.h>
#include <stdint.h>
#include <vector>

Expand Down
25 changes: 13 additions & 12 deletions src/crypto/md_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@
* ==========================(LICENSE BEGIN)============================
*
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Expand Down Expand Up @@ -121,24 +121,24 @@
#ifndef CLOSE_ONLY

#ifdef SPH_UPTR
static void
void
SPH_XCAT(HASH, _short)(void *cc, const void *data, size_t len)
#else
void
SPH_XCAT(sph_, HASH)(void *cc, const void *data, size_t len)
#endif
{
SPH_XCAT(sph_, SPH_XCAT(HASH, _context)) *sc;
size_t current;
unsigned current;

sc = cc;
sc = (SPH_XCAT(sph_, SPH_XCAT(HASH, _context))*) cc;
#if SPH_64
current = (unsigned)sc->count & (SPH_BLEN - 1U);
#else
current = (unsigned)sc->count_low & (SPH_BLEN - 1U);
#endif
while (len > 0) {
size_t clen;
unsigned clen;
#if !SPH_64
sph_u32 clow, clow2;
#endif
Expand Down Expand Up @@ -181,7 +181,7 @@ SPH_XCAT(sph_, HASH)(void *cc, const void *data, size_t len)
SPH_XCAT(HASH, _short)(cc, data, len);
return;
}
sc = cc;
sc = (SPH_XCAT(sph_, SPH_XCAT(HASH, _context))*) cc;
#if SPH_64
current = (unsigned)sc->count & (SPH_BLEN - 1U);
#else
Expand All @@ -203,7 +203,7 @@ SPH_XCAT(sph_, HASH)(void *cc, const void *data, size_t len)
#endif
orig_len = len;
while (len >= SPH_BLEN) {
RFUN(data, SPH_VAL);
RFUN((const unsigned char*)data, SPH_VAL);
len -= SPH_BLEN;
data = (const unsigned char *)data + SPH_BLEN;
}
Expand Down Expand Up @@ -235,7 +235,7 @@ SPH_XCAT(sph_, HASH)(void *cc, const void *data, size_t len)
* Perform padding and produce result. The context is NOT reinitialized
* by this function.
*/
static void
void
SPH_XCAT(HASH, _addbits_and_close)(void *cc,
unsigned ub, unsigned n, void *dst, unsigned rnum)
{
Expand All @@ -245,7 +245,8 @@ SPH_XCAT(HASH, _addbits_and_close)(void *cc,
sph_u32 low, high;
#endif

sc = cc;
sc = (SPH_XCAT(sph_, SPH_XCAT(HASH, _context))*) cc;

#if SPH_64
current = (unsigned)sc->count & (SPH_BLEN - 1U);
#else
Expand Down Expand Up @@ -339,7 +340,7 @@ SPH_XCAT(HASH, _addbits_and_close)(void *cc,
#endif
}

static void
void
SPH_XCAT(HASH, _close)(void *cc, void *dst, unsigned rnum)
{
SPH_XCAT(HASH, _addbits_and_close)(cc, 0, 0, dst, rnum);
Expand Down
191 changes: 191 additions & 0 deletions src/crypto/sph_tiger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/* $Id: sph_tiger.h 216 2010-06-08 09:46:57Z tp $ */
/**
* Tiger / Tiger-2 interface.
*
* Tiger has been published in: R. Anderson, E. Biham, "Tiger: A Fast
* New Hash Function", Fast Software Encryption - FSE'96, LNCS 1039,
* Springer (1996), pp. 89--97.
*
* Tiger2 has never been formally published, but it was described as
* identical to Tiger, except for the padding which is the same in
* Tiger2 as it is in MD4. Fortunately, an implementation of Tiger2
* was submitted to NESSIE, which produced test vectors; the sphlib
* implementation of Tiger2 is compatible with the NESSIE test vectors.
*
* ==========================(LICENSE BEGIN)============================
*
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ===========================(LICENSE END)=============================
*
* @file sph_tiger.h
* @author Thomas Pornin <[email protected]>
*/

#ifndef BITCORE_CRYPTO_SPH_TIGER_H
#define BITCORE_CRYPTO_SPH_TIGER_H

#include <stddef.h>
#include <crypto/sph_types.h>

#if SPH_64

/**
* Output size (in bits) for Tiger.
*/
#define SPH_SIZE_tiger 192

/**
* Output size (in bits) for Tiger2.
*/
#define SPH_SIZE_tiger2 192

/**
* This structure is a context for Tiger computations: it contains the
* intermediate values and some data from the last entered block. Once
* a Tiger computation has been performed, the context can be reused for
* another computation.
*
* The contents of this structure are private. A running Tiger computation
* can be cloned by copying the context (e.g. with a simple
* <code>memcpy()</code>).
*/
typedef struct {
#ifndef DOXYGEN_IGNORE
unsigned char buf[64]; /* first field, for alignment */
sph_u64 val[3];
sph_u64 count;
#endif
} sph_tiger_context;

/**
* Initialize a Tiger context. This process performs no memory allocation.
*
* @param cc the Tiger context (pointer to
* a <code>sph_tiger_context</code>)
*/
void sph_tiger_init(void *cc);

/**
* Process some data bytes. It is acceptable that <code>len</code> is zero
* (in which case this function does nothing).
*
* @param cc the Tiger context
* @param data the input data
* @param len the input data length (in bytes)
*/
void sph_tiger(void *cc, const void *data, size_t len);

/**
* Terminate the current Tiger computation and output the result into the
* provided buffer. The destination buffer must be wide enough to
* accomodate the result (24 bytes). The context is automatically
* reinitialized.
*
* @param cc the Tiger context
* @param dst the destination buffer
*/
void sph_tiger_close(void *cc, void *dst);

/**
* Apply the Tiger compression function on the provided data. The
* <code>msg</code> parameter contains the 8 64-bit input blocks,
* as numerical values (hence after the little-endian decoding). The
* <code>val</code> parameter contains the 3 64-bit input blocks for
* the compression function; the output is written in place in this
* array.
*
* @param msg the message block (8 values)
* @param val the function 192-bit input and output
*/
void sph_tiger_comp(const sph_u64 msg[8], sph_u64 val[3]);

/**
* This structure is a context for Tiger2 computations. It is identical
* to the Tiger context, and they may be freely exchanged, since the
* difference between Tiger and Tiger2 resides solely in the padding, which
* is computed only in the last computation step.
*/
typedef sph_tiger_context sph_tiger2_context;

#ifdef DOXYGEN_IGNORE
/**
* Initialize a Tiger2 context. This function is identical to
* <code>sph_tiger_init()</code>.
*
* @param cc the Tiger2 context (pointer to
* a <code>sph_tiger2_context</code>)
*/
void sph_tiger2_init(void *cc);
#endif

#ifndef DOXYGEN_IGNORE
#define sph_tiger2_init sph_tiger_init
#endif

#ifdef DOXYGEN_IGNORE
/**
* Process some data bytes. This function is identical to
* <code>sph_tiger()</code>.
*
* @param cc the Tiger2 context
* @param data the input data
* @param len the input data length (in bytes)
*/
void sph_tiger2(void *cc, const void *data, size_t len);
#endif

#ifndef DOXYGEN_IGNORE
#define sph_tiger2 sph_tiger
#endif

/**
* Terminate the current Tiger2 computation and output the result into the
* provided buffer. The destination buffer must be wide enough to
* accomodate the result (24 bytes). The context is automatically
* reinitialized. Note that this function is NOT identical to
* <code>sph_tiger2_close()</code>: this is the exact and unique point
* where Tiger and Tiger2 differ.
*
* @param cc the Tiger context
* @param dst the destination buffer
*/
void sph_tiger2_close(void *cc, void *dst);

#ifdef DOXYGEN_IGNORE
/**
* Apply the Tiger2 compression function, which is identical to the Tiger
* compression function.
*
* @param msg the message block (8 values)
* @param val the function 192-bit input and output
*/
void sph_tiger2_comp(const sph_u64 msg[8], sph_u64 val[3]);
#endif

#ifndef DOXYGEN_IGNORE
#define sph_tiger2_comp sph_tiger_comp
#endif

#endif

#endif // BITCORE_CRYPTO_SPH_TIGER_H
Loading

0 comments on commit 0606cbc

Please sign in to comment.