Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into snark
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Mar 16, 2017
2 parents 7caceee + 0ecd316 commit c25ae98
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 78 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ before_script:
script:
- cd $TRAVIS_BUILD_DIR/build && ../scripts/tests.sh $TRAVIS_TESTS
after_success:
- cd $TRAVIS_BUILD_DIR/build
- make coverage.data
# Get CodeCov script (fixed commit) and upload coverage report.
- cd $TRAVIS_BUILD_DIR/build && bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/f81a7b47aef0fad3900e887a7ad9c96c0d12c47f/codecov) -a '>/dev/null 2>&1'
- bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/e7985c0ea6dd4d365403f389337f3b43b517fb35/codecov) -f coverage.data
deploy:
# This is the deploy target for the native build (Linux and macOS)
# which generates ZIPs per commit. We are in agreement that
Expand Down
14 changes: 6 additions & 8 deletions cmake/EthCompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,14 @@ if (PROFILING AND (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_C
endif ()

if (COVERAGE)
include(ProjectLcov)
set(CMAKE_CXX_FLAGS "-g --coverage ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-g --coverage ${CMAKE_C_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}")
find_program(LCOV_TOOL lcov)
message(STATUS "lcov tool: ${LCOV_TOOL}")
if (LCOV_TOOL)
add_custom_target(coverage.info
COMMAND ${LCOV_TOOL} -o ${CMAKE_BINARY_DIR}/coverage.info -c -d ${CMAKE_BINARY_DIR}
COMMAND ${LCOV_TOOL} -o ${CMAKE_BINARY_DIR}/coverage.info -r ${CMAKE_BINARY_DIR}/coverage.info '/usr*' '${CMAKE_BINARY_DIR}/deps/*' '${CMAKE_SOURCE_DIR}/deps/*'
)
endif()
add_custom_target(coverage.data
COMMAND ${LCOV_TOOL} -o ${CMAKE_BINARY_DIR}/coverage.data -c -d ${CMAKE_BINARY_DIR}
COMMAND ${LCOV_TOOL} -o ${CMAKE_BINARY_DIR}/coverage.data -r ${CMAKE_BINARY_DIR}/coverage.data '/usr*' '${CMAKE_SOURCE_DIR}/deps/*'
)
add_dependencies(coverage.data lcov)
endif ()
1 change: 1 addition & 0 deletions cmake/EthOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ macro(configure_project)
eth_default_option(ROCKSDB OFF)
eth_default_option(PARANOID OFF)
eth_default_option(MINIUPNPC ON)
eth_default_option(FASTCTEST OFF)

# components
eth_default_option(TESTS ON)
Expand Down
13 changes: 13 additions & 0 deletions cmake/ProjectLcov.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include(ExternalProject)

ExternalProject_Add(lcov
PREFIX ${CMAKE_SOURCE_DIR}/deps
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/linux-test-project/lcov/releases/download/v1.13/lcov-1.13.tar.gz
URL_HASH SHA256=44972c878482cc06a05fe78eaa3645cbfcbad6634615c3309858b207965d8a23
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/bin <INSTALL_DIR>/bin
)
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/deps/bin)
set(LCOV_TOOL ${CMAKE_SOURCE_DIR}/deps/bin/lcov)
2 changes: 2 additions & 0 deletions libdevcrypto/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ bool dev::SignatureStruct::isValid() const noexcept

Address dev::ZeroAddress = Address();

Address dev::MaxAddress = Address("0xffffffffffffffffffffffffffffffffffffffff");

Public dev::toPublic(Secret const& _secret)
{
auto* ctx = getCtx();
Expand Down
3 changes: 3 additions & 0 deletions libdevcrypto/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ using Address = h160;
/// The zero address.
extern Address ZeroAddress;

/// The last address.
extern Address MaxAddress;

/// A vector of Ethereum addresses.
using Addresses = h160s;

Expand Down
4 changes: 2 additions & 2 deletions libethashseal/Ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ void Ethash::verify(Strictness _s, BlockHeader const& _bi, BlockHeader const& _p

void Ethash::verifyTransaction(ImportRequirements::value _ir, TransactionBase const& _t, BlockHeader const& _bi) const
{
SealEngineFace::verifyTransaction(_ir, _t, _bi);

if (_ir & ImportRequirements::TransactionSignatures)
{
if (_bi.number() >= chainParams().u256Param("homsteadForkBlock"))
_t.checkLowS();
if (_bi.number() >= chainParams().u256Param("EIP158ForkBlock"))
{
int chainID(chainParams().u256Param("chainID"));
Expand Down
3 changes: 2 additions & 1 deletion libethcore/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ enum class ImportResult
AlreadyKnown,
Malformed,
OverbidGasPrice,
BadChain
BadChain,
ZeroSignature
};

struct ImportRequirements
Expand Down
6 changes: 4 additions & 2 deletions libethcore/SealEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ void SealEngineFace::populateFromParent(BlockHeader& _bi, BlockHeader const& _pa
_bi.populateFromParent(_parent);
}

void SealEngineFace::verifyTransaction(ImportRequirements::value _ir, TransactionBase const& _t, BlockHeader const&) const
void SealEngineFace::verifyTransaction(ImportRequirements::value _ir, TransactionBase const& _t, BlockHeader const& _bi) const
{
if (_ir & ImportRequirements::TransactionSignatures)
if ((_ir & ImportRequirements::TransactionSignatures) && _bi.number() < chainParams().u256Param("metropolisForkBlock") && _t.hasZeroSignature())
BOOST_THROW_EXCEPTION(InvalidSignature());
if (_bi.number() >= chainParams().u256Param("homsteadForkBlock") && (_ir & ImportRequirements::TransactionSignatures))
_t.checkLowS();
}

Expand Down
43 changes: 27 additions & 16 deletions libethcore/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,29 @@ TransactionBase::TransactionBase(bytesConstRef _rlpData, CheckTransaction _check
h256 r = rlp[field = 7].toInt<u256>();
h256 s = rlp[field = 8].toInt<u256>();

if (v > 36)
m_chainId = (v - 35) / 2;
else if (v == 27 || v == 28)
m_chainId = -4;
m_vrs = SignatureStruct{ r, s, v };

if (hasZeroSignature())
m_chainId = m_vrs.v;
else
BOOST_THROW_EXCEPTION(InvalidSignature());
{
if (v > 36)
m_chainId = (v - 35) / 2;
else if (v == 27 || v == 28)
m_chainId = -4;
else
BOOST_THROW_EXCEPTION(InvalidSignature());
m_vrs.v = v - (m_chainId * 2 + 35);

if (_checkSig >= CheckTransaction::Cheap && !m_vrs.isValid())
BOOST_THROW_EXCEPTION(InvalidSignature());
}

v = v - (m_chainId * 2 + 35);
if (_checkSig == CheckTransaction::Everything)
m_sender = sender();

if (rlp.itemCount() > 9)
BOOST_THROW_EXCEPTION(InvalidTransactionFormat() << errinfo_comment("to many fields in the transaction RLP"));

m_vrs = SignatureStruct{ r, s, v };
if (_checkSig >= CheckTransaction::Cheap && !m_vrs.isValid())
BOOST_THROW_EXCEPTION(InvalidSignature());
if (_checkSig == CheckTransaction::Everything)
m_sender = sender();
}
catch (Exception& _e)
{
Expand All @@ -111,10 +117,15 @@ Address const& TransactionBase::sender() const
{
if (!m_sender)
{
auto p = recover(m_vrs, sha3(WithoutSignature));
if (!p)
BOOST_THROW_EXCEPTION(InvalidSignature());
m_sender = right160(dev::sha3(bytesConstRef(p.data(), sizeof(p))));
if (hasZeroSignature())
m_sender = MaxAddress;
else
{
auto p = recover(m_vrs, sha3(WithoutSignature));
if (!p)
BOOST_THROW_EXCEPTION(InvalidSignature());
m_sender = right160(dev::sha3(bytesConstRef(p.data(), sizeof(p))));
}
}
return m_sender;
}
Expand Down
2 changes: 2 additions & 0 deletions libethcore/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class TransactionBase
/// @returns the signature of the transaction. Encodes the sender.
SignatureStruct const& signature() const { return m_vrs; }

bool hasZeroSignature() const { return !m_vrs.s && !m_vrs.r; }

void sign(Secret const& _priv); ///< Sign the transaction.

/// @returns amount of gas required for the basic payment.
Expand Down
35 changes: 19 additions & 16 deletions libethereum/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,26 @@ void Executive::initialize(Transaction const& _transaction)
BOOST_THROW_EXCEPTION(OutOfGasBase() << RequirementError((bigint)m_baseGasRequired, (bigint)m_t.gas()));
}

// Avoid invalid transactions.
u256 nonceReq;
try
if (!m_t.hasZeroSignature())
{
nonceReq = m_s.getNonce(m_t.sender());
}
catch (...)
{
clog(ExecutiveWarnChannel) << "Invalid Signature";
m_excepted = TransactionException::InvalidSignature;
throw;
}
if (m_t.nonce() != nonceReq)
{
clog(ExecutiveWarnChannel) << "Invalid Nonce: Require" << nonceReq << " Got" << m_t.nonce();
m_excepted = TransactionException::InvalidNonce;
BOOST_THROW_EXCEPTION(InvalidNonce() << RequirementError((bigint)nonceReq, (bigint)m_t.nonce()));
// Avoid invalid transactions.
u256 nonceReq;
try
{
nonceReq = m_s.getNonce(m_t.sender());
}
catch (InvalidSignature const&)
{
clog(ExecutiveWarnChannel) << "Invalid Signature";
m_excepted = TransactionException::InvalidSignature;
throw;
}
if (m_t.nonce() != nonceReq)
{
clog(ExecutiveWarnChannel) << "Invalid Nonce: Require" << nonceReq << " Got" << m_t.nonce();
m_excepted = TransactionException::InvalidNonce;
BOOST_THROW_EXCEPTION(InvalidNonce() << RequirementError((bigint)nonceReq, (bigint)m_t.nonce()));
}
}

// Avoid unaffordable transactions.
Expand Down
35 changes: 9 additions & 26 deletions libethereum/TransactionQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,15 @@ TransactionQueue::~TransactionQueue()

ImportResult TransactionQueue::import(bytesConstRef _transactionRLP, IfDropped _ik)
{
// Check if we already know this transaction.
h256 h = sha3(_transactionRLP);

Transaction t;
ImportResult ir;
try
{
UpgradableGuard l(m_lock);

ir = check_WITH_LOCK(h, _ik);
if (ir != ImportResult::Success)
return ir;

try
{
// Check validity of _transactionRLP as a transaction. To do this we just deserialise and attempt to determine the sender.
// If it doesn't work, the signature is bad.
// The transaction's nonce may yet be invalid (or, it could be "valid" but we may be missing a marginally older transaction).
t = Transaction(_transactionRLP, CheckTransaction::Everything);
UpgradeGuard ul(l);
// cdebug << "Importing" << t;
ir = manageImport_WITH_LOCK(h, t);
}
catch (...)
{
return ImportResult::Malformed;
}
Transaction t = Transaction(_transactionRLP, CheckTransaction::Everything);
return import(t, _ik);
}
catch (Exception const&)
{
return ImportResult::Malformed;
}
return ir;
}

ImportResult TransactionQueue::check_WITH_LOCK(h256 const& _h, IfDropped _ik)
Expand All @@ -100,6 +81,8 @@ ImportResult TransactionQueue::check_WITH_LOCK(h256 const& _h, IfDropped _ik)

ImportResult TransactionQueue::import(Transaction const& _transaction, IfDropped _ik)
{
if (_transaction.hasZeroSignature())
return ImportResult::ZeroSignature;
// Check if we already know this transaction.
h256 h = _transaction.sha3(WithSignature);

Expand Down
7 changes: 6 additions & 1 deletion scripts/runalltests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ git clone --recursive --depth 1 --single-branch https://github.com/ethereum/cpp-
cd tests
testHead=$(git rev-parse HEAD)
cd ..
cd cpp-ethereum
cd tests/RPCTests
npm install
cd $workdir/cpp-ethereum
cppHead=$(git rev-parse HEAD)

#Prepare test results
Expand All @@ -30,6 +32,9 @@ echo "tests repository at commit $testHead"
exec 2> $workdir/testlog.txt
timestart=$(date +%s.%N)
test/testeth -- --all --exectimelog
cd $workdir/tests/RPCTests
echo "#--------------RPC TESTS--------------"
node main.js $workdir/cpp-ethereum/build/eth/eth
timeend=$(date +%s.%N)
date=$(date +%Y-%m-%d)

Expand Down
23 changes: 19 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ add_subdirectory(external-dependencies)

set(SRC_LIST ${SRC_LIST} ${SRC})
# search for test names and create ctest tests
set(excludeSuites jsonrpc)
set(excludeSuites jsonrpc \"RandomTestCreationSuite\" shhrpc whisperDB whisperMessage whisper BlockQueueSuite)
set(allSuites jsonrpc)
foreach(file ${SRC_LIST})
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${file} test_list_raw REGEX "BOOST_.*TEST_(SUITE|CASE)")
set(TestSuite "DEFAULT")
Expand All @@ -39,13 +40,27 @@ foreach(file ${SRC_LIST})
if(NOT TestSuite MATCHES "DEFAULT")
if(ThirdLevelTestSuite STREQUAL "")
set(ThirdLevelTestSuite ${TestSuite}/)
if(FASTCTEST)
break()
endif()
endif()
endif()
string(SUBSTRING ${test} 6 -1 TestSuite)
if(FASTCTEST)
if (";${excludeSuites};" MATCHES ";${TestSuite};")
continue()
endif()
if (NOT ";${allSuites};" MATCHES ";${TestSuite};")
list(APPEND allSuites ${TestSuite})
add_test(NAME ${TestSuite} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test COMMAND testeth -t ${TestSuite})
endif()
endif()
elseif(test MATCHES "^CASE .*")
if(NOT test MATCHES "^CASE &createRandom.*")
string(SUBSTRING ${test} 5 -1 TestCase)
add_test(NAME ${ThirdLevelTestSuite}${TestSuite}/${TestCase} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test COMMAND testeth -t ${ThirdLevelTestSuite}${TestSuite}/${TestCase})
if(NOT FASTCTEST)
if(NOT test MATCHES "^CASE &createRandom.*")
string(SUBSTRING ${test} 5 -1 TestCase)
add_test(NAME ${ThirdLevelTestSuite}${TestSuite}/${TestCase} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test COMMAND testeth -t ${ThirdLevelTestSuite}${TestSuite}/${TestCase})
endif()
endif()
endif()
endforeach(test_raw)
Expand Down
Loading

0 comments on commit c25ae98

Please sign in to comment.