Browse Source

Reject block versions lower than 4

Closes #1556
pull/4/head
Jack Grigg 8 years ago
parent
commit
80f4cdcf8f
No known key found for this signature in database GPG Key ID: 6A6914DAFBEA00DA
  1. 1
      src/Makefile.gtest.include
  2. 2
      src/consensus/consensus.h
  3. 31
      src/gtest/test_checkblock.cpp
  4. 5
      src/main.cpp

1
src/Makefile.gtest.include

@ -5,6 +5,7 @@ bin_PROGRAMS += zcash-gtest
zcash_gtest_SOURCES = \
gtest/main.cpp \
gtest/utils.cpp \
gtest/test_checkblock.cpp \
gtest/test_checktransaction.cpp \
gtest/json_test_vectors.cpp \
gtest/json_test_vectors.h \

2
src/consensus/consensus.h

@ -6,6 +6,8 @@
#ifndef BITCOIN_CONSENSUS_CONSENSUS_H
#define BITCOIN_CONSENSUS_CONSENSUS_H
/** The minimum allowed block version (network rule) */
static const int32_t MIN_BLOCK_VERSION = 4;
/** The minimum allowed transaction version (network rule) */
static const int32_t MIN_TX_VERSION = 1;
/** The maximum allowed size for a serialized block, in bytes (network rule) */

31
src/gtest/test_checkblock.cpp

@ -0,0 +1,31 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "consensus/validation.h"
#include "main.h"
class MockCValidationState : public CValidationState {
public:
MOCK_METHOD5(DoS, bool(int level, bool ret,
unsigned char chRejectCodeIn, std::string strRejectReasonIn,
bool corruptionIn));
MOCK_METHOD3(Invalid, bool(bool ret,
unsigned char _chRejectCode, std::string _strRejectReason));
MOCK_METHOD1(Error, bool(std::string strRejectReasonIn));
MOCK_CONST_METHOD0(IsValid, bool());
MOCK_CONST_METHOD0(IsInvalid, bool());
MOCK_CONST_METHOD0(IsError, bool());
MOCK_CONST_METHOD1(IsInvalid, bool(int &nDoSOut));
MOCK_CONST_METHOD0(CorruptionPossible, bool());
MOCK_CONST_METHOD0(GetRejectCode, unsigned char());
MOCK_CONST_METHOD0(GetRejectReason, std::string());
};
TEST(CheckBlock, VersionTooLow) {
CBlock block;
block.nVersion = 1;
MockCValidationState state;
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "version-too-low", false)).Times(1);
EXPECT_FALSE(CheckBlock(block, state, false, false));
}

5
src/main.cpp

@ -2940,6 +2940,11 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW)
{
// Check block version
if (block.nVersion < MIN_BLOCK_VERSION)
return state.DoS(100, error("CheckBlockHeader(): block version too low"),
REJECT_INVALID, "version-too-low");
// Check Equihash solution is valid
if (fCheckPOW && !CheckEquihashSolution(&block, Params()))
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),

Loading…
Cancel
Save