mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
Remove 'Proof of Work' code
This commit is contained in:
committed by
Vinnie Falco
parent
dcdc341d0f
commit
28b70a7b9a
@@ -1845,18 +1845,6 @@
|
|||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\OrderBook.h">
|
<ClInclude Include="..\..\src\ripple\app\misc\OrderBook.h">
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\PowResult.h">
|
|
||||||
</ClInclude>
|
|
||||||
<ClCompile Include="..\..\src\ripple\app\misc\ProofOfWork.cpp">
|
|
||||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\ProofOfWork.h">
|
|
||||||
</ClInclude>
|
|
||||||
<ClCompile Include="..\..\src\ripple\app\misc\ProofOfWorkFactory.cpp">
|
|
||||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\ProofOfWorkFactory.h">
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\SHAMapStore.h">
|
<ClInclude Include="..\..\src\ripple\app\misc\SHAMapStore.h">
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClCompile Include="..\..\src\ripple\app\misc\SHAMapStoreImp.cpp">
|
<ClCompile Include="..\..\src\ripple\app\misc\SHAMapStoreImp.cpp">
|
||||||
@@ -2916,15 +2904,6 @@
|
|||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\Print.cpp">
|
<ClCompile Include="..\..\src\ripple\rpc\handlers\Print.cpp">
|
||||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\ProofCreate.cpp">
|
|
||||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\ProofSolve.cpp">
|
|
||||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\ProofVerify.cpp">
|
|
||||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\Random.cpp">
|
<ClCompile Include="..\..\src\ripple\rpc\handlers\Random.cpp">
|
||||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -2730,21 +2730,6 @@
|
|||||||
<ClInclude Include="..\..\src\ripple\app\misc\OrderBook.h">
|
<ClInclude Include="..\..\src\ripple\app\misc\OrderBook.h">
|
||||||
<Filter>ripple\app\misc</Filter>
|
<Filter>ripple\app\misc</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\PowResult.h">
|
|
||||||
<Filter>ripple\app\misc</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClCompile Include="..\..\src\ripple\app\misc\ProofOfWork.cpp">
|
|
||||||
<Filter>ripple\app\misc</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\ProofOfWork.h">
|
|
||||||
<Filter>ripple\app\misc</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClCompile Include="..\..\src\ripple\app\misc\ProofOfWorkFactory.cpp">
|
|
||||||
<Filter>ripple\app\misc</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\ProofOfWorkFactory.h">
|
|
||||||
<Filter>ripple\app\misc</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\ripple\app\misc\SHAMapStore.h">
|
<ClInclude Include="..\..\src\ripple\app\misc\SHAMapStore.h">
|
||||||
<Filter>ripple\app\misc</Filter>
|
<Filter>ripple\app\misc</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -4014,15 +3999,6 @@
|
|||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\Print.cpp">
|
<ClCompile Include="..\..\src\ripple\rpc\handlers\Print.cpp">
|
||||||
<Filter>ripple\rpc\handlers</Filter>
|
<Filter>ripple\rpc\handlers</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\ProofCreate.cpp">
|
|
||||||
<Filter>ripple\rpc\handlers</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\ProofSolve.cpp">
|
|
||||||
<Filter>ripple\rpc\handlers</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\ProofVerify.cpp">
|
|
||||||
<Filter>ripple\rpc\handlers</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\ripple\rpc\handlers\Random.cpp">
|
<ClCompile Include="..\..\src\ripple\rpc\handlers\Random.cpp">
|
||||||
<Filter>ripple\rpc\handlers</Filter>
|
<Filter>ripple\rpc\handlers</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include <ripple/app/impl/BasicApp.h>
|
#include <ripple/app/impl/BasicApp.h>
|
||||||
#include <ripple/app/main/Tuning.h>
|
#include <ripple/app/main/Tuning.h>
|
||||||
#include <ripple/app/misc/ProofOfWorkFactory.h>
|
|
||||||
#include <ripple/app/paths/FindPaths.h>
|
#include <ripple/app/paths/FindPaths.h>
|
||||||
#include <ripple/basics/Log.h>
|
#include <ripple/basics/Log.h>
|
||||||
#include <ripple/basics/LoggedTimings.h>
|
#include <ripple/basics/LoggedTimings.h>
|
||||||
@@ -188,7 +187,6 @@ public:
|
|||||||
std::unique_ptr <LoadFeeTrack> mFeeTrack;
|
std::unique_ptr <LoadFeeTrack> mFeeTrack;
|
||||||
std::unique_ptr <IHashRouter> mHashRouter;
|
std::unique_ptr <IHashRouter> mHashRouter;
|
||||||
std::unique_ptr <Validations> mValidations;
|
std::unique_ptr <Validations> mValidations;
|
||||||
std::unique_ptr <ProofOfWorkFactory> mProofOfWorkFactory;
|
|
||||||
std::unique_ptr <LoadManager> m_loadManager;
|
std::unique_ptr <LoadManager> m_loadManager;
|
||||||
beast::DeadlineTimer m_sweepTimer;
|
beast::DeadlineTimer m_sweepTimer;
|
||||||
|
|
||||||
@@ -330,8 +328,6 @@ public:
|
|||||||
|
|
||||||
, mValidations (make_Validations ())
|
, mValidations (make_Validations ())
|
||||||
|
|
||||||
, mProofOfWorkFactory (make_ProofOfWorkFactory ())
|
|
||||||
|
|
||||||
, m_loadManager (LoadManager::New (*this, m_logs.journal("LoadManager")))
|
, m_loadManager (LoadManager::New (*this, m_logs.journal("LoadManager")))
|
||||||
|
|
||||||
, m_sweepTimer (this)
|
, m_sweepTimer (this)
|
||||||
@@ -507,11 +503,6 @@ public:
|
|||||||
return *m_deprecatedUNL;
|
return *m_deprecatedUNL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProofOfWorkFactory& getProofOfWorkFactory ()
|
|
||||||
{
|
|
||||||
return *mProofOfWorkFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
SHAMapStore& getSHAMapStore () override
|
SHAMapStore& getSHAMapStore () override
|
||||||
{
|
{
|
||||||
return *m_shaMapStore;
|
return *m_shaMapStore;
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ class NetworkOPs;
|
|||||||
class OrderBookDB;
|
class OrderBookDB;
|
||||||
class Overlay;
|
class Overlay;
|
||||||
class PathRequests;
|
class PathRequests;
|
||||||
class ProofOfWorkFactory;
|
|
||||||
class STLedgerEntry;
|
class STLedgerEntry;
|
||||||
class TransactionMaster;
|
class TransactionMaster;
|
||||||
class Validations;
|
class Validations;
|
||||||
@@ -108,7 +107,6 @@ public:
|
|||||||
virtual LoadFeeTrack& getFeeTrack () = 0;
|
virtual LoadFeeTrack& getFeeTrack () = 0;
|
||||||
virtual LoadManager& getLoadManager () = 0;
|
virtual LoadManager& getLoadManager () = 0;
|
||||||
virtual Overlay& overlay () = 0;
|
virtual Overlay& overlay () = 0;
|
||||||
virtual ProofOfWorkFactory& getProofOfWorkFactory () = 0;
|
|
||||||
virtual UniqueNodeList& getUNL () = 0;
|
virtual UniqueNodeList& getUNL () = 0;
|
||||||
virtual Validations& getValidations () = 0;
|
virtual Validations& getValidations () = 0;
|
||||||
virtual NodeStore::Database& getNodeStore () = 0;
|
virtual NodeStore::Database& getNodeStore () = 0;
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#ifndef RIPPLE_POWRESULT_H_INCLUDED
|
|
||||||
#define RIPPLE_POWRESULT_H_INCLUDED
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
enum PowResult
|
|
||||||
{
|
|
||||||
powOK = 0,
|
|
||||||
powREUSED = 1, // already submitted
|
|
||||||
powBADNONCE = 2, // you didn't solve it
|
|
||||||
powEXPIRED = 3, // time is up
|
|
||||||
powCORRUPT = 4,
|
|
||||||
powTOOEASY = 5, // the difficulty increased too much while you solved it
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
#include <boost/regex.hpp>
|
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
// VFALCO TODO Move these to a header
|
|
||||||
const uint256 ProofOfWork::sMinTarget ("00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
|
||||||
|
|
||||||
ProofOfWork::ProofOfWork (std::string const& token,
|
|
||||||
int iterations,
|
|
||||||
uint256 const& challenge,
|
|
||||||
uint256 const& target)
|
|
||||||
: mToken (token)
|
|
||||||
, mChallenge (challenge)
|
|
||||||
, mTarget (target)
|
|
||||||
, mIterations (iterations)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ProofOfWork::ProofOfWork (std::string const& token)
|
|
||||||
{
|
|
||||||
std::vector<std::string> fields;
|
|
||||||
boost::split (fields, token, boost::algorithm::is_any_of ("-"));
|
|
||||||
|
|
||||||
if (fields.size () != 5)
|
|
||||||
throw std::runtime_error ("invalid token");
|
|
||||||
|
|
||||||
mToken = token;
|
|
||||||
mChallenge.SetHex (fields[0]);
|
|
||||||
mTarget.SetHex (fields[1]);
|
|
||||||
mIterations = beast::lexicalCast <int> (fields[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProofOfWork::isValid () const
|
|
||||||
{
|
|
||||||
if ((mIterations <= kMaxIterations) && (mTarget >= sMinTarget))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
WriteLog (lsWARNING, ProofOfWork) << "Invalid PoW: " << mIterations << ", " << mTarget;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint64_t ProofOfWork::getDifficulty (uint256 const& target, int iterations)
|
|
||||||
{
|
|
||||||
// calculate the approximate number of hashes required to solve this proof of work
|
|
||||||
if ((iterations > kMaxIterations) || (target < sMinTarget))
|
|
||||||
{
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Iterations:" << iterations;
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "MaxIterat: " << kMaxIterations;
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Target: " << target;
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "MinTarget: " << sMinTarget;
|
|
||||||
throw std::runtime_error ("invalid proof of work target/iteration");
|
|
||||||
}
|
|
||||||
|
|
||||||
// more iterations means more hashes per iteration but also a larger final hash
|
|
||||||
std::uint64_t difficulty = iterations + (iterations / 8);
|
|
||||||
|
|
||||||
// Multiply the number of hashes needed by 256 for each leading zero byte in the difficulty
|
|
||||||
const unsigned char* ptr = target.begin ();
|
|
||||||
|
|
||||||
while (*ptr == 0)
|
|
||||||
{
|
|
||||||
difficulty *= 256;
|
|
||||||
++ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
difficulty = (difficulty * 256) / (*ptr + 1);
|
|
||||||
|
|
||||||
return difficulty;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint256 getSHA512Half (const std::vector<uint256>& vec)
|
|
||||||
{
|
|
||||||
return Serializer::getSHA512Half (vec.front ().begin (), vec.size () * (256 / 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint256 ProofOfWork::solve (int maxIterations) const
|
|
||||||
{
|
|
||||||
if (!isValid ())
|
|
||||||
throw std::runtime_error ("invalid proof of work target/iteration");
|
|
||||||
|
|
||||||
uint256 nonce;
|
|
||||||
RandomNumbers::getInstance ().fill (&nonce);
|
|
||||||
|
|
||||||
std::vector<uint256> buf2;
|
|
||||||
buf2.resize (mIterations);
|
|
||||||
|
|
||||||
std::vector<uint256> buf1;
|
|
||||||
buf1.resize (3);
|
|
||||||
buf1[0] = mChallenge;
|
|
||||||
|
|
||||||
while (maxIterations > 0)
|
|
||||||
{
|
|
||||||
buf1[1] = nonce;
|
|
||||||
buf1[2].zero ();
|
|
||||||
|
|
||||||
for (int i = (mIterations - 1); i >= 0; --i)
|
|
||||||
{
|
|
||||||
buf1[2] = getSHA512Half (buf1);
|
|
||||||
buf2[i] = buf1[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getSHA512Half (buf2) <= mTarget)
|
|
||||||
return nonce;
|
|
||||||
|
|
||||||
++nonce;
|
|
||||||
--maxIterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
return uint256 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProofOfWork::checkSolution (uint256 const& solution) const
|
|
||||||
{
|
|
||||||
if (mIterations > kMaxIterations)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::vector<uint256> buf1;
|
|
||||||
buf1.push_back (mChallenge);
|
|
||||||
buf1.push_back (solution);
|
|
||||||
buf1.push_back (uint256 ());
|
|
||||||
|
|
||||||
std::vector<uint256> buf2;
|
|
||||||
buf2.resize (mIterations);
|
|
||||||
|
|
||||||
for (int i = (mIterations - 1); i >= 0; --i)
|
|
||||||
{
|
|
||||||
buf1[2] = getSHA512Half (buf1);
|
|
||||||
buf2[i] = buf1[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
return getSHA512Half (buf2) <= mTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProofOfWork::validateToken (std::string const& strToken)
|
|
||||||
{
|
|
||||||
static boost::regex const reToken (
|
|
||||||
"[[:xdigit:]]{64}-"
|
|
||||||
"[[:xdigit:]]{64}-"
|
|
||||||
"[[:digit:]]+-"
|
|
||||||
"[[:digit:]]+-"
|
|
||||||
"[[:xdigit:]]{64}",
|
|
||||||
boost::regex_constants::optimize);
|
|
||||||
|
|
||||||
boost::smatch smMatch;
|
|
||||||
|
|
||||||
return boost::regex_match (strToken, smMatch, reToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool ProofOfWork::calcResultInfo (PowResult powCode, std::string& strToken, std::string& strHuman)
|
|
||||||
{
|
|
||||||
struct PowResultInfo
|
|
||||||
{
|
|
||||||
PowResult code;
|
|
||||||
char const* token;
|
|
||||||
char const* text;
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
PowResultInfo const results[] =
|
|
||||||
{
|
|
||||||
{ powOK, "powOK", "Valid proof-of-work." },
|
|
||||||
{ powREUSED, "powREUSED", "Proof-of-work has already been used." },
|
|
||||||
{ powBADNONCE, "powBADNONCE", "The solution does not meet the required difficulty." },
|
|
||||||
{ powEXPIRED, "powEXPIRED", "Token is expired." },
|
|
||||||
{ powCORRUPT, "powCORRUPT", "Invalid token." },
|
|
||||||
{ powTOOEASY, "powTOOEASY", "Difficulty has increased since token was issued." },
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& result : results)
|
|
||||||
{
|
|
||||||
if (powCode == result.code)
|
|
||||||
{
|
|
||||||
strToken = result.token;
|
|
||||||
strHuman = result.text;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // ripple
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#ifndef RIPPLE_PROOFOFWORK_H
|
|
||||||
#define RIPPLE_PROOFOFWORK_H
|
|
||||||
|
|
||||||
#include <ripple/app/misc/PowResult.h>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
class ProofOfWork : beast::LeakChecked <ProofOfWork>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
kMaxIterations = (1 << 23)
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::shared_ptr <ProofOfWork> pointer;
|
|
||||||
|
|
||||||
ProofOfWork (std::string const& token,
|
|
||||||
int iterations,
|
|
||||||
uint256 const& challenge,
|
|
||||||
uint256 const& target);
|
|
||||||
|
|
||||||
explicit ProofOfWork (std::string const& token);
|
|
||||||
|
|
||||||
bool isValid () const;
|
|
||||||
|
|
||||||
uint256 solve (int maxIterations = 2 * kMaxIterations) const;
|
|
||||||
bool checkSolution (uint256 const& solution) const;
|
|
||||||
|
|
||||||
std::string const& getToken () const
|
|
||||||
{
|
|
||||||
return mToken;
|
|
||||||
}
|
|
||||||
uint256 const& getChallenge () const
|
|
||||||
{
|
|
||||||
return mChallenge;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint64_t getDifficulty () const
|
|
||||||
{
|
|
||||||
return getDifficulty (mTarget, mIterations);
|
|
||||||
}
|
|
||||||
|
|
||||||
// approximate number of hashes needed to solve
|
|
||||||
static std::uint64_t getDifficulty (uint256 const& target, int iterations);
|
|
||||||
|
|
||||||
static bool validateToken (std::string const& strToken);
|
|
||||||
|
|
||||||
static bool calcResultInfo (PowResult powCode, std::string& strToken, std::string& strHuman);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string mToken;
|
|
||||||
uint256 mChallenge;
|
|
||||||
uint256 mTarget;
|
|
||||||
int mIterations;
|
|
||||||
|
|
||||||
static const uint256 sMinTarget;
|
|
||||||
static const int maxIterations;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,428 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include <ripple/app/misc/ProofOfWorkFactory.h>
|
|
||||||
#include <ripple/crypto/RandomNumbers.h>
|
|
||||||
#include <beast/unit_test/suite.h>
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
#include <boost/bimap/bimap.hpp>
|
|
||||||
#include <boost/bimap/multiset_of.hpp>
|
|
||||||
#include <boost/bimap/unordered_set_of.hpp>
|
|
||||||
#include <beast/cxx14/memory.h> // <memory>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
class ProofOfWorkFactoryImp
|
|
||||||
: public ProofOfWorkFactory
|
|
||||||
, public beast::LeakChecked <ProofOfWorkFactoryImp>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef boost::bimaps::bimap< boost::bimaps::multiset_of<time_t>,
|
|
||||||
boost::bimaps::unordered_set_of<uint256> > powMap_t;
|
|
||||||
|
|
||||||
typedef powMap_t::value_type powMap_vt;
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ProofOfWorkFactoryImp ()
|
|
||||||
: mValidTime (180)
|
|
||||||
{
|
|
||||||
setDifficulty (1);
|
|
||||||
RandomNumbers::getInstance ().fillBytes (mSecret.begin (), mSecret.size ());
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
numPowEntries = kMaxDifficulty + 1
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PowEntry
|
|
||||||
{
|
|
||||||
const char* target;
|
|
||||||
int iterations;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector <PowEntry> PowEntries;
|
|
||||||
|
|
||||||
static PowEntries const& getPowEntries ()
|
|
||||||
{
|
|
||||||
struct StaticPowEntries
|
|
||||||
{
|
|
||||||
StaticPowEntries ()
|
|
||||||
{
|
|
||||||
// VFALCO TODO Make this array know its own size.
|
|
||||||
//
|
|
||||||
PowEntry entries [numPowEntries] =
|
|
||||||
{
|
|
||||||
// target iterations hashes memory
|
|
||||||
{ "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 65536 }, // 1451874, 2 MB
|
|
||||||
{ "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 2177811, 3 MB
|
|
||||||
{ "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 3538944, 3 MB
|
|
||||||
{ "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 4355623, 6 MB
|
|
||||||
|
|
||||||
{ "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 131072}, // 4718592, 4 MB
|
|
||||||
{ "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 5807497, 8 MB
|
|
||||||
{ "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 7077888, 6 MB
|
|
||||||
{ "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 9437184, 8 MB
|
|
||||||
|
|
||||||
{ "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 14155776, 12MB
|
|
||||||
{ "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 28311552, 12MB
|
|
||||||
{ "00CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 92919965, 8 MB
|
|
||||||
{ "00CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 139379948, 12MB
|
|
||||||
|
|
||||||
{ "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 150994944, 8 MB
|
|
||||||
{ "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 226492416, 12MB
|
|
||||||
{ "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 49152 }, // 278759896, 1.5MB
|
|
||||||
{ "003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 301989888, 8 MB
|
|
||||||
|
|
||||||
{ "003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 452984832, 12MB
|
|
||||||
{ "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 905969664, 3 MB
|
|
||||||
{ "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 1115039586, 6 MB
|
|
||||||
{ "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 1486719448 8 MB
|
|
||||||
|
|
||||||
{ "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 2230079172 12MB
|
|
||||||
{ "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 2415919104, 8 MB
|
|
||||||
{ "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 3623878656, 12MB
|
|
||||||
{ "0003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 7247757312, 12MB
|
|
||||||
|
|
||||||
{ "0000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 23787511177, 8 MB
|
|
||||||
{ "0000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 35681266766, 12MB
|
|
||||||
{ "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 131072}, // 38654705664, 4 MB
|
|
||||||
{ "00007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 38654705664, 8 MB
|
|
||||||
|
|
||||||
{ "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 57982058496, 6 MB
|
|
||||||
{ "00007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 57982058496, 12MB
|
|
||||||
{ "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 77309411328, 8 MB
|
|
||||||
};
|
|
||||||
|
|
||||||
data.reserve (numPowEntries);
|
|
||||||
|
|
||||||
for (int i = 0; i < numPowEntries; ++i)
|
|
||||||
data.push_back (entries [i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector <PowEntry> data;
|
|
||||||
};
|
|
||||||
|
|
||||||
static StaticPowEntries list;
|
|
||||||
|
|
||||||
return list.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
static int getPowEntry (uint256 const& target, int iterations)
|
|
||||||
{
|
|
||||||
PowEntries const& entries (getPowEntries ());
|
|
||||||
|
|
||||||
for (int i = 0; i < numPowEntries; ++i)
|
|
||||||
{
|
|
||||||
if (entries [i].iterations == iterations)
|
|
||||||
{
|
|
||||||
uint256 t;
|
|
||||||
t.SetHex (entries [i].target);
|
|
||||||
|
|
||||||
if (t == target)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ProofOfWork getProof ()
|
|
||||||
{
|
|
||||||
// challenge - target - iterations - time - validator
|
|
||||||
static boost::format f ("%s-%s-%d-%d");
|
|
||||||
|
|
||||||
int now = static_cast<int> (time (nullptr) / 4);
|
|
||||||
|
|
||||||
uint256 challenge;
|
|
||||||
RandomNumbers::getInstance ().fillBytes (challenge.begin (), challenge.size ());
|
|
||||||
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
|
|
||||||
std::string s = boost::str (boost::format (f) % to_string (challenge) %
|
|
||||||
to_string (mTarget) % mIterations % now);
|
|
||||||
std::string c = to_string (mSecret) + s;
|
|
||||||
s += "-" + to_string (Serializer::getSHA512Half (c));
|
|
||||||
|
|
||||||
return ProofOfWork (s, mIterations, challenge, mTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
PowResult checkProof (std::string const& token, uint256 const& solution)
|
|
||||||
{
|
|
||||||
// VFALCO COmmented this out because Dave said it wasn't used
|
|
||||||
// and also we dont have the lexicalCast from a vector of strings to a time_t
|
|
||||||
|
|
||||||
// challenge - target - iterations - time - validator
|
|
||||||
|
|
||||||
std::vector<std::string> fields;
|
|
||||||
boost::split (fields, token, boost::algorithm::is_any_of ("-"));
|
|
||||||
|
|
||||||
if (fields.size () != 5)
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " is corrupt";
|
|
||||||
return powCORRUPT;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string v = to_string (mSecret) + fields[0] + "-" +
|
|
||||||
fields[1] + "-" + fields[2] + "-" + fields[3];
|
|
||||||
|
|
||||||
if (fields[4] != to_string (Serializer::getSHA512Half (v)))
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad token";
|
|
||||||
return powCORRUPT;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint256 challenge, target;
|
|
||||||
challenge.SetHex (fields[0]);
|
|
||||||
target.SetHex (fields[1]);
|
|
||||||
|
|
||||||
time_t t;
|
|
||||||
#if 0
|
|
||||||
// Broken with lexicalCast<> changes
|
|
||||||
t = beast::lexicalCast <time_t> (fields[3]);
|
|
||||||
#else
|
|
||||||
t = static_cast <time_t> (beast::lexicalCast <std::uint64_t> (fields [3]));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
time_t now = time (nullptr);
|
|
||||||
|
|
||||||
int iterations = beast::lexicalCast <int> (fields[2]);
|
|
||||||
|
|
||||||
{
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
|
|
||||||
if ((t * 4) > (now + mValidTime))
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has expired";
|
|
||||||
return powEXPIRED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((iterations != mIterations) || (target != mTarget)) && getPowEntry (target, iterations) < (mPowEntry - 2))
|
|
||||||
{
|
|
||||||
// difficulty has increased more than two times since PoW requested
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Difficulty has increased since PoW requested";
|
|
||||||
return powTOOEASY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProofOfWork pow (token, iterations, challenge, target);
|
|
||||||
|
|
||||||
if (!pow.checkSolution (solution))
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad nonce";
|
|
||||||
return powBADNONCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
|
|
||||||
if (!mSolvedChallenges.insert (powMap_vt (now, challenge)).second)
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has been reused";
|
|
||||||
return powREUSED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return powOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void sweep ()
|
|
||||||
{
|
|
||||||
time_t expire = time (nullptr) - mValidTime;
|
|
||||||
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
powMap_t::left_map::iterator it = mSolvedChallenges.left.begin ();
|
|
||||||
|
|
||||||
if (it == mSolvedChallenges.left.end ())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (it->first >= expire)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mSolvedChallenges.left.erase (it);
|
|
||||||
}
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void loadHigh ()
|
|
||||||
{
|
|
||||||
time_t now = time (nullptr);
|
|
||||||
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
|
|
||||||
if (mLastDifficultyChange == now)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (mPowEntry == 30)
|
|
||||||
return;
|
|
||||||
|
|
||||||
++mPowEntry;
|
|
||||||
mLastDifficultyChange = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void loadLow ()
|
|
||||||
{
|
|
||||||
time_t now = time (nullptr);
|
|
||||||
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
|
|
||||||
if (mLastDifficultyChange == now)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (mPowEntry == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
--mPowEntry;
|
|
||||||
mLastDifficultyChange = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void setDifficulty (int i)
|
|
||||||
{
|
|
||||||
assert ((i >= 0) && (i <= kMaxDifficulty));
|
|
||||||
time_t now = time (nullptr);
|
|
||||||
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
mPowEntry = i;
|
|
||||||
PowEntries const& entries (getPowEntries ());
|
|
||||||
mIterations = entries [i].iterations;
|
|
||||||
mTarget.SetHex (entries [i].target);
|
|
||||||
mLastDifficultyChange = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
std::uint64_t getDifficulty ()
|
|
||||||
{
|
|
||||||
return ProofOfWork::getDifficulty (mTarget, mIterations);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint256 const& getSecret () const
|
|
||||||
{
|
|
||||||
return mSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSecret (uint256 const& secret)
|
|
||||||
{
|
|
||||||
mSecret = secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
typedef RippleMutex LockType;
|
|
||||||
typedef std::lock_guard <LockType> ScopedLockType;
|
|
||||||
LockType mLock;
|
|
||||||
|
|
||||||
uint256 mSecret;
|
|
||||||
int mIterations;
|
|
||||||
uint256 mTarget;
|
|
||||||
time_t mLastDifficultyChange;
|
|
||||||
int mValidTime;
|
|
||||||
int mPowEntry;
|
|
||||||
|
|
||||||
powMap_t mSolvedChallenges;
|
|
||||||
};
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
std::unique_ptr<ProofOfWorkFactory> make_ProofOfWorkFactory ()
|
|
||||||
{
|
|
||||||
return std::make_unique<ProofOfWorkFactoryImp>();
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class ProofOfWork_test : public beast::unit_test::suite
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void run ()
|
|
||||||
{
|
|
||||||
using namespace ripple;
|
|
||||||
|
|
||||||
ProofOfWorkFactoryImp gen;
|
|
||||||
ProofOfWork pow = gen.getProof ();
|
|
||||||
|
|
||||||
uint256 solution = pow.solve (16777216);
|
|
||||||
|
|
||||||
expect (! solution.isZero (), "Should be solved");
|
|
||||||
|
|
||||||
expect (pow.checkSolution (solution), "Should be checked");
|
|
||||||
|
|
||||||
// Why is this emitted?
|
|
||||||
//WriteLog (lsDEBUG, ProofOfWork) << "A bad nonce error is expected";
|
|
||||||
|
|
||||||
PowResult r = gen.checkProof (pow.getToken (), uint256 ());
|
|
||||||
|
|
||||||
expect (r == powBADNONCE, "Should show bad nonce for empty solution");
|
|
||||||
|
|
||||||
expect (gen.checkProof (pow.getToken (), solution) == powOK, "Solution should check with issuer");
|
|
||||||
|
|
||||||
//WriteLog (lsDEBUG, ProofOfWork) << "A reused nonce error is expected";
|
|
||||||
|
|
||||||
expect (gen.checkProof (pow.getToken (), solution) == powREUSED, "Reuse solution should be detected");
|
|
||||||
|
|
||||||
#ifdef SOLVE_POWS
|
|
||||||
|
|
||||||
for (int i = 0; i < 12; ++i)
|
|
||||||
{
|
|
||||||
gen.setDifficulty (i);
|
|
||||||
ProofOfWork pow = gen.getProof ();
|
|
||||||
WriteLog (lsINFO, ProofOfWork) << "Level: " << i << ", Estimated difficulty: " << pow.getDifficulty ();
|
|
||||||
uint256 solution = pow.solve (131072);
|
|
||||||
|
|
||||||
if (solution.isZero ())
|
|
||||||
{
|
|
||||||
//WriteLog (lsINFO, ProofOfWork) << "Giving up";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//WriteLog (lsINFO, ProofOfWork) << "Solution found";
|
|
||||||
|
|
||||||
if (gen.checkProof (pow.getToken (), solution) != powOK)
|
|
||||||
{
|
|
||||||
//WriteLog (lsFATAL, ProofOfWork) << "Solution fails";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE_MANUAL(ProofOfWork,ripple_app,ripple);
|
|
||||||
|
|
||||||
} // ripple
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#ifndef RIPPLE_PROOFOFWORKFACTORY_H_INCLUDED
|
|
||||||
#define RIPPLE_PROOFOFWORKFACTORY_H_INCLUDED
|
|
||||||
|
|
||||||
#include <ripple/app/misc/PowResult.h>
|
|
||||||
#include <ripple/app/misc/ProofOfWork.h>
|
|
||||||
#include <ripple/types/base_uint.h>
|
|
||||||
#include <beast/cxx14/memory.h> // <memory>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
class ProofOfWorkFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
kMaxDifficulty = 30,
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~ProofOfWorkFactory () { }
|
|
||||||
|
|
||||||
virtual ProofOfWork getProof () = 0;
|
|
||||||
|
|
||||||
virtual PowResult checkProof (std::string const& token, uint256 const& solution) = 0;
|
|
||||||
|
|
||||||
virtual std::uint64_t getDifficulty () = 0;
|
|
||||||
|
|
||||||
virtual void setDifficulty (int i) = 0;
|
|
||||||
|
|
||||||
virtual void loadHigh () = 0;
|
|
||||||
|
|
||||||
virtual void loadLow () = 0;
|
|
||||||
|
|
||||||
virtual void sweep () = 0;
|
|
||||||
|
|
||||||
virtual uint256 const& getSecret () const = 0;
|
|
||||||
|
|
||||||
virtual void setSecret (uint256 const& secret) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unique_ptr<ProofOfWorkFactory> make_ProofOfWorkFactory ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -856,74 +856,6 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMPing> const& m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
PeerImp::onMessage (std::shared_ptr <protocol::TMProofWork> const& m)
|
|
||||||
{
|
|
||||||
if (m->has_response ())
|
|
||||||
{
|
|
||||||
// this is an answer to a proof of work we requested
|
|
||||||
if (m->response ().size () != (256 / 8))
|
|
||||||
return charge (Resource::feeInvalidRequest);
|
|
||||||
|
|
||||||
uint256 response;
|
|
||||||
memcpy (response.begin (), m->response ().data (), 256 / 8);
|
|
||||||
|
|
||||||
// VFALCO TODO Use a dependency injection here
|
|
||||||
PowResult r = getApp().getProofOfWorkFactory ().checkProof (
|
|
||||||
m->token (), response);
|
|
||||||
|
|
||||||
if (r == powOK)
|
|
||||||
// credit peer
|
|
||||||
// WRITEME
|
|
||||||
return;
|
|
||||||
|
|
||||||
// return error message
|
|
||||||
// WRITEME
|
|
||||||
if (r != powTOOEASY)
|
|
||||||
charge (Resource::feeBadProofOfWork);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->has_result ())
|
|
||||||
{
|
|
||||||
// this is a reply to a proof of work we sent
|
|
||||||
// WRITEME
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->has_target () && m->has_challenge () && m->has_iterations ())
|
|
||||||
{
|
|
||||||
// this is a challenge
|
|
||||||
// WRITEME: Reject from inbound connections
|
|
||||||
|
|
||||||
uint256 challenge, target;
|
|
||||||
|
|
||||||
if ((m->challenge ().size () != (256 / 8)) || (
|
|
||||||
m->target ().size () != (256 / 8)))
|
|
||||||
return charge (Resource::feeInvalidRequest);
|
|
||||||
|
|
||||||
memcpy (challenge.begin (), m->challenge ().data (), 256 / 8);
|
|
||||||
memcpy (target.begin (), m->target ().data (), 256 / 8);
|
|
||||||
ProofOfWork::pointer pow = std::make_shared<ProofOfWork> (
|
|
||||||
m->token (), m->iterations (), challenge, target);
|
|
||||||
|
|
||||||
if (!pow->isValid ())
|
|
||||||
return charge (Resource::feeInvalidRequest);
|
|
||||||
|
|
||||||
#if 0 // Until proof of work is completed, don't do it
|
|
||||||
getApp().getJobQueue ().addJob (
|
|
||||||
jtPROOFWORK,
|
|
||||||
"recvProof->doProof",
|
|
||||||
std::bind (&PeerImp::doProofOfWork, std::placeholders::_1,
|
|
||||||
std::weak_ptr <PeerImp> (shared_from_this ()), pow));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p_journal_.info << "Bad proof of work";
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PeerImp::onMessage (std::shared_ptr <protocol::TMCluster> const& m)
|
PeerImp::onMessage (std::shared_ptr <protocol::TMCluster> const& m)
|
||||||
{
|
{
|
||||||
@@ -1621,38 +1553,6 @@ PeerImp::doFetchPack (const std::shared_ptr<protocol::TMGetObjectByHash>& packet
|
|||||||
packet, hash, UptimeTimer::getInstance ().getElapsedSeconds ()));
|
packet, hash, UptimeTimer::getInstance ().getElapsedSeconds ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
PeerImp::doProofOfWork (Job&, std::weak_ptr <PeerImp> peer,
|
|
||||||
ProofOfWork::pointer pow)
|
|
||||||
{
|
|
||||||
if (peer.expired ())
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint256 solution = pow->solve ();
|
|
||||||
|
|
||||||
if (solution.isZero ())
|
|
||||||
{
|
|
||||||
p_journal_.warning << "Failed to solve proof of work";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Peer::ptr pptr (peer.lock ());
|
|
||||||
|
|
||||||
if (pptr)
|
|
||||||
{
|
|
||||||
protocol::TMProofWork reply;
|
|
||||||
reply.set_token (pow->getToken ());
|
|
||||||
reply.set_response (solution.begin (), solution.size ());
|
|
||||||
pptr->send (std::make_shared<Message> (
|
|
||||||
reply, protocol::mtPROOFOFWORK));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// WRITEME: Save solved proof of work for new connection
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PeerImp::checkTransaction (Job&, int flags,
|
PeerImp::checkTransaction (Job&, int flags,
|
||||||
STTx::pointer stx)
|
STTx::pointer stx)
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
#include <ripple/overlay/predicates.h>
|
#include <ripple/overlay/predicates.h>
|
||||||
#include <ripple/overlay/impl/ProtocolMessage.h>
|
#include <ripple/overlay/impl/ProtocolMessage.h>
|
||||||
#include <ripple/overlay/impl/OverlayImpl.h>
|
#include <ripple/overlay/impl/OverlayImpl.h>
|
||||||
#include <ripple/app/misc/ProofOfWork.h>
|
|
||||||
#include <ripple/app/misc/ProofOfWorkFactory.h>
|
|
||||||
#include <ripple/core/Config.h>
|
#include <ripple/core/Config.h>
|
||||||
#include <ripple/core/LoadFeeTrack.h>
|
#include <ripple/core/LoadFeeTrack.h>
|
||||||
#include <ripple/protocol/Protocol.h>
|
#include <ripple/protocol/Protocol.h>
|
||||||
@@ -371,7 +369,6 @@ public:
|
|||||||
|
|
||||||
void onMessage (std::shared_ptr <protocol::TMHello> const& m);
|
void onMessage (std::shared_ptr <protocol::TMHello> const& m);
|
||||||
void onMessage (std::shared_ptr <protocol::TMPing> const& m);
|
void onMessage (std::shared_ptr <protocol::TMPing> const& m);
|
||||||
void onMessage (std::shared_ptr <protocol::TMProofWork> const& m);
|
|
||||||
void onMessage (std::shared_ptr <protocol::TMCluster> const& m);
|
void onMessage (std::shared_ptr <protocol::TMCluster> const& m);
|
||||||
void onMessage (std::shared_ptr <protocol::TMGetPeers> const& m);
|
void onMessage (std::shared_ptr <protocol::TMGetPeers> const& m);
|
||||||
void onMessage (std::shared_ptr <protocol::TMPeers> const& m);
|
void onMessage (std::shared_ptr <protocol::TMPeers> const& m);
|
||||||
@@ -421,9 +418,6 @@ private:
|
|||||||
void
|
void
|
||||||
doFetchPack (const std::shared_ptr<protocol::TMGetObjectByHash>& packet);
|
doFetchPack (const std::shared_ptr<protocol::TMGetObjectByHash>& packet);
|
||||||
|
|
||||||
void
|
|
||||||
doProofOfWork (Job&, std::weak_ptr <PeerImp> peer, ProofOfWork::pointer pow);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
checkTransaction (Job&, int flags, STTx::pointer stx);
|
checkTransaction (Job&, int flags, STTx::pointer stx);
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ invokeProtocolMessage (Buffers const& buffers, Handler& handler)
|
|||||||
{
|
{
|
||||||
case protocol::mtHELLO: ec = detail::invoke<protocol::TMHello> (type, buffers, handler); break;
|
case protocol::mtHELLO: ec = detail::invoke<protocol::TMHello> (type, buffers, handler); break;
|
||||||
case protocol::mtPING: ec = detail::invoke<protocol::TMPing> (type, buffers, handler); break;
|
case protocol::mtPING: ec = detail::invoke<protocol::TMPing> (type, buffers, handler); break;
|
||||||
case protocol::mtPROOFOFWORK: ec = detail::invoke<protocol::TMProofWork> (type, buffers, handler); break;
|
|
||||||
case protocol::mtCLUSTER: ec = detail::invoke<protocol::TMCluster> (type, buffers, handler); break;
|
case protocol::mtCLUSTER: ec = detail::invoke<protocol::TMCluster> (type, buffers, handler); break;
|
||||||
case protocol::mtGET_PEERS: ec = detail::invoke<protocol::TMGetPeers> (type, buffers, handler); break;
|
case protocol::mtGET_PEERS: ec = detail::invoke<protocol::TMGetPeers> (type, buffers, handler); break;
|
||||||
case protocol::mtPEERS: ec = detail::invoke<protocol::TMPeers> (type, buffers, handler); break;
|
case protocol::mtPEERS: ec = detail::invoke<protocol::TMPeers> (type, buffers, handler); break;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ extern Charge const feeInvalidRequest; // A request that we can immediate
|
|||||||
extern Charge const feeRequestNoReply; // A request that we cannot satisfy
|
extern Charge const feeRequestNoReply; // A request that we cannot satisfy
|
||||||
extern Charge const feeInvalidSignature; // An object whose signature we had to check and it failed
|
extern Charge const feeInvalidSignature; // An object whose signature we had to check and it failed
|
||||||
extern Charge const feeUnwantedData; // Data we have no use for
|
extern Charge const feeUnwantedData; // Data we have no use for
|
||||||
extern Charge const feeBadProofOfWork; // Proof of work not valid
|
|
||||||
extern Charge const feeBadData; // Data we have to verify before rejecting
|
extern Charge const feeBadData; // Data we have to verify before rejecting
|
||||||
|
|
||||||
// RPC loads
|
// RPC loads
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ enum LoadType
|
|||||||
LT_RequestNoReply, // A request that we cannot satisfy
|
LT_RequestNoReply, // A request that we cannot satisfy
|
||||||
LT_InvalidSignature, // An object whose signature we had to check and it failed
|
LT_InvalidSignature, // An object whose signature we had to check and it failed
|
||||||
LT_UnwantedData, // Data we have no use for
|
LT_UnwantedData, // Data we have no use for
|
||||||
LT_BadPoW, // Proof of work not valid
|
|
||||||
LT_BadData, // Data we have to verify before rejecting
|
LT_BadData, // Data we have to verify before rejecting
|
||||||
|
|
||||||
// RPC loads
|
// RPC loads
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ Charge const feeInvalidRequest ( 10, "malformed request" );
|
|||||||
Charge const feeRequestNoReply ( 1, "unsatisfiable request" );
|
Charge const feeRequestNoReply ( 1, "unsatisfiable request" );
|
||||||
Charge const feeInvalidSignature ( 100, "invalid signature" );
|
Charge const feeInvalidSignature ( 100, "invalid signature" );
|
||||||
Charge const feeUnwantedData ( 5, "useless data" );
|
Charge const feeUnwantedData ( 5, "useless data" );
|
||||||
Charge const feeBadProofOfWork ( 250, "incorrect proof of work"); // DAVID: Check the cost
|
|
||||||
Charge const feeBadData ( 20, "invalid data" );
|
Charge const feeBadData ( 20, "invalid data" );
|
||||||
|
|
||||||
Charge const feeInvalidRPC ( 10, "malformed RPC" );
|
Charge const feeInvalidRPC ( 10, "malformed RPC" );
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ Charge legacyFee (LoadType t)
|
|||||||
case LT_RequestNoReply: return feeRequestNoReply;
|
case LT_RequestNoReply: return feeRequestNoReply;
|
||||||
case LT_InvalidSignature: return feeInvalidSignature;
|
case LT_InvalidSignature: return feeInvalidSignature;
|
||||||
case LT_UnwantedData: return feeUnwantedData;
|
case LT_UnwantedData: return feeUnwantedData;
|
||||||
case LT_BadPoW: return feeBadProofOfWork;
|
|
||||||
case LT_BadData: return feeBadData;
|
case LT_BadData: return feeBadData;
|
||||||
|
|
||||||
case LT_RPCInvalid: return feeInvalidRPC;
|
case LT_RPCInvalid: return feeInvalidRPC;
|
||||||
|
|||||||
@@ -53,9 +53,6 @@ Json::Value doPathFind (RPC::Context&);
|
|||||||
Json::Value doPeers (RPC::Context&);
|
Json::Value doPeers (RPC::Context&);
|
||||||
Json::Value doPing (RPC::Context&);
|
Json::Value doPing (RPC::Context&);
|
||||||
Json::Value doPrint (RPC::Context&);
|
Json::Value doPrint (RPC::Context&);
|
||||||
Json::Value doProofCreate (RPC::Context&);
|
|
||||||
Json::Value doProofSolve (RPC::Context&);
|
|
||||||
Json::Value doProofVerify (RPC::Context&);
|
|
||||||
Json::Value doRandom (RPC::Context&);
|
Json::Value doRandom (RPC::Context&);
|
||||||
Json::Value doRipplePathFind (RPC::Context&);
|
Json::Value doRipplePathFind (RPC::Context&);
|
||||||
Json::Value doSMS (RPC::Context&);
|
Json::Value doSMS (RPC::Context&);
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012-2014 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include <ripple/app/misc/ProofOfWorkFactory.h>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
// {
|
|
||||||
// // if either of these parameters is set, a custom generator is used
|
|
||||||
// difficulty: <number> // optional
|
|
||||||
// secret: <secret> // optional
|
|
||||||
// }
|
|
||||||
Json::Value doProofCreate (RPC::Context& context)
|
|
||||||
{
|
|
||||||
// XXX: Add ability to create proof with arbitrary time
|
|
||||||
Json::Value jvResult (Json::objectValue);
|
|
||||||
|
|
||||||
if (context.params.isMember ("difficulty") ||
|
|
||||||
context.params.isMember ("secret"))
|
|
||||||
{
|
|
||||||
// VFALCO TODO why aren't we using the app's factory?
|
|
||||||
auto pgGen = make_ProofOfWorkFactory ();
|
|
||||||
|
|
||||||
if (context.params.isMember ("difficulty"))
|
|
||||||
{
|
|
||||||
if (!context.params["difficulty"].isIntegral ())
|
|
||||||
return RPC::invalid_field_error ("difficulty");
|
|
||||||
|
|
||||||
int const iDifficulty (context.params["difficulty"].asInt ());
|
|
||||||
|
|
||||||
if (iDifficulty < 0 ||
|
|
||||||
iDifficulty > ProofOfWorkFactory::kMaxDifficulty)
|
|
||||||
{
|
|
||||||
return RPC::invalid_field_error ("difficulty");
|
|
||||||
}
|
|
||||||
|
|
||||||
pgGen->setDifficulty (iDifficulty);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.params.isMember ("secret"))
|
|
||||||
{
|
|
||||||
uint256 uSecret (context.params["secret"].asString ());
|
|
||||||
pgGen->setSecret (uSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
jvResult["token"] = pgGen->getProof ().getToken ();
|
|
||||||
jvResult["secret"] = to_string (pgGen->getSecret ());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
jvResult["token"]
|
|
||||||
= getApp().getProofOfWorkFactory ().getProof ().getToken ();
|
|
||||||
}
|
|
||||||
|
|
||||||
return jvResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // ripple
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012-2014 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
// {
|
|
||||||
// token: <token>
|
|
||||||
// }
|
|
||||||
Json::Value doProofSolve (RPC::Context& context)
|
|
||||||
{
|
|
||||||
Json::Value jvResult;
|
|
||||||
|
|
||||||
if (!context.params.isMember ("token"))
|
|
||||||
return RPC::missing_field_error ("token");
|
|
||||||
|
|
||||||
std::string strToken = context.params["token"].asString ();
|
|
||||||
|
|
||||||
if (!ProofOfWork::validateToken (strToken))
|
|
||||||
return RPC::invalid_field_error ("token");
|
|
||||||
|
|
||||||
ProofOfWork powProof (strToken);
|
|
||||||
uint256 uSolution = powProof.solve ();
|
|
||||||
|
|
||||||
jvResult["solution"] = to_string (uSolution);
|
|
||||||
|
|
||||||
return jvResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // ripple
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2012-2014 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
// {
|
|
||||||
// token: <token>
|
|
||||||
// solution: <solution>
|
|
||||||
// // if either of these parameters is set, a custom verifier is used
|
|
||||||
// difficulty: <number> // optional
|
|
||||||
// secret: <secret> // optional
|
|
||||||
// }
|
|
||||||
Json::Value doProofVerify (RPC::Context& context)
|
|
||||||
{
|
|
||||||
// XXX Add ability to check proof against arbitrary time
|
|
||||||
|
|
||||||
Json::Value jvResult;
|
|
||||||
|
|
||||||
if (!context.params.isMember ("token"))
|
|
||||||
return RPC::missing_field_error ("token");
|
|
||||||
|
|
||||||
if (!context.params.isMember ("solution"))
|
|
||||||
return RPC::missing_field_error ("solution");
|
|
||||||
|
|
||||||
std::string strToken = context.params["token"].asString ();
|
|
||||||
uint256 uSolution (context.params["solution"].asString ());
|
|
||||||
|
|
||||||
PowResult prResult;
|
|
||||||
|
|
||||||
if (context.params.isMember ("difficulty") ||
|
|
||||||
context.params.isMember ("secret"))
|
|
||||||
{
|
|
||||||
// VFALCO TODO why aren't we using the app's factory?
|
|
||||||
auto pgGen = make_ProofOfWorkFactory ();
|
|
||||||
|
|
||||||
if (context.params.isMember ("difficulty"))
|
|
||||||
{
|
|
||||||
if (!context.params["difficulty"].isIntegral ())
|
|
||||||
return RPC::invalid_field_error ("difficulty");
|
|
||||||
|
|
||||||
int iDifficulty = context.params["difficulty"].asInt ();
|
|
||||||
|
|
||||||
if (iDifficulty < 0 ||
|
|
||||||
iDifficulty > ProofOfWorkFactory::kMaxDifficulty)
|
|
||||||
{
|
|
||||||
return RPC::invalid_field_error ("difficulty");
|
|
||||||
}
|
|
||||||
|
|
||||||
pgGen->setDifficulty (iDifficulty);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.params.isMember ("secret"))
|
|
||||||
{
|
|
||||||
uint256 uSecret (context.params["secret"].asString ());
|
|
||||||
pgGen->setSecret (uSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
prResult = pgGen->checkProof (strToken, uSolution);
|
|
||||||
jvResult["secret"] = to_string (pgGen->getSecret ());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// XXX Proof should not be marked as used from this
|
|
||||||
prResult = getApp().getProofOfWorkFactory ().checkProof (
|
|
||||||
strToken, uSolution);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string sToken;
|
|
||||||
std::string sHuman;
|
|
||||||
|
|
||||||
ProofOfWork::calcResultInfo (prResult, sToken, sHuman);
|
|
||||||
|
|
||||||
jvResult["proof_result"] = sToken;
|
|
||||||
jvResult["proof_result_code"] = prResult;
|
|
||||||
jvResult["proof_result_message"] = sHuman;
|
|
||||||
|
|
||||||
return jvResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // ripple
|
|
||||||
@@ -117,9 +117,6 @@ HandlerTable HANDLERS({
|
|||||||
{ "ping", byRef (&doPing), Role::USER, NO_CONDITION },
|
{ "ping", byRef (&doPing), Role::USER, NO_CONDITION },
|
||||||
{ "print", byRef (&doPrint), Role::ADMIN, NO_CONDITION },
|
{ "print", byRef (&doPrint), Role::ADMIN, NO_CONDITION },
|
||||||
// { "profile", byRef (&doProfile), Role::USER, NEEDS_CURRENT_LEDGER },
|
// { "profile", byRef (&doProfile), Role::USER, NEEDS_CURRENT_LEDGER },
|
||||||
{ "proof_create", byRef (&doProofCreate), Role::ADMIN, NO_CONDITION },
|
|
||||||
{ "proof_solve", byRef (&doProofSolve), Role::ADMIN, NO_CONDITION },
|
|
||||||
{ "proof_verify", byRef (&doProofVerify), Role::ADMIN, NO_CONDITION },
|
|
||||||
{ "random", byRef (&doRandom), Role::USER, NO_CONDITION },
|
{ "random", byRef (&doRandom), Role::USER, NO_CONDITION },
|
||||||
{ "ripple_path_find", byRef (&doRipplePathFind), Role::USER, NEEDS_CURRENT_LEDGER },
|
{ "ripple_path_find", byRef (&doRipplePathFind), Role::USER, NEEDS_CURRENT_LEDGER },
|
||||||
{ "sign", byRef (&doSign), Role::USER, NO_CONDITION },
|
{ "sign", byRef (&doSign), Role::USER, NO_CONDITION },
|
||||||
@@ -143,6 +140,7 @@ HandlerTable HANDLERS({
|
|||||||
{ "wallet_accounts", byRef (&doWalletAccounts), Role::USER, NEEDS_CURRENT_LEDGER },
|
{ "wallet_accounts", byRef (&doWalletAccounts), Role::USER, NEEDS_CURRENT_LEDGER },
|
||||||
{ "wallet_propose", byRef (&doWalletPropose), Role::ADMIN, NO_CONDITION },
|
{ "wallet_propose", byRef (&doWalletPropose), Role::ADMIN, NO_CONDITION },
|
||||||
{ "wallet_seed", byRef (&doWalletSeed), Role::ADMIN, NO_CONDITION },
|
{ "wallet_seed", byRef (&doWalletSeed), Role::ADMIN, NO_CONDITION },
|
||||||
|
|
||||||
// Evented methods
|
// Evented methods
|
||||||
{ "subscribe", byRef (&doSubscribe), Role::USER, NO_CONDITION },
|
{ "subscribe", byRef (&doSubscribe), Role::USER, NO_CONDITION },
|
||||||
{ "unsubscribe", byRef (&doUnsubscribe), Role::USER, NO_CONDITION },
|
{ "unsubscribe", byRef (&doUnsubscribe), Role::USER, NO_CONDITION },
|
||||||
|
|||||||
@@ -20,9 +20,6 @@
|
|||||||
#include <BeastConfig.h>
|
#include <BeastConfig.h>
|
||||||
|
|
||||||
#include <ripple/app/consensus/LedgerConsensus.cpp>
|
#include <ripple/app/consensus/LedgerConsensus.cpp>
|
||||||
#include <ripple/app/misc/PowResult.h>
|
|
||||||
#include <ripple/app/misc/ProofOfWorkFactory.cpp>
|
|
||||||
#include <ripple/app/misc/ProofOfWork.cpp>
|
|
||||||
#include <ripple/app/peers/PeerSet.cpp>
|
#include <ripple/app/peers/PeerSet.cpp>
|
||||||
#include <ripple/app/shamap/SHAMapSyncFilters.cpp>
|
#include <ripple/app/shamap/SHAMapSyncFilters.cpp>
|
||||||
#include <ripple/app/ledger/LedgerCleaner.cpp>
|
#include <ripple/app/ledger/LedgerCleaner.cpp>
|
||||||
|
|||||||
@@ -73,9 +73,6 @@
|
|||||||
#include <ripple/rpc/handlers/Peers.cpp>
|
#include <ripple/rpc/handlers/Peers.cpp>
|
||||||
#include <ripple/rpc/handlers/Ping.cpp>
|
#include <ripple/rpc/handlers/Ping.cpp>
|
||||||
#include <ripple/rpc/handlers/Print.cpp>
|
#include <ripple/rpc/handlers/Print.cpp>
|
||||||
#include <ripple/rpc/handlers/ProofCreate.cpp>
|
|
||||||
#include <ripple/rpc/handlers/ProofSolve.cpp>
|
|
||||||
#include <ripple/rpc/handlers/ProofVerify.cpp>
|
|
||||||
#include <ripple/rpc/handlers/Random.cpp>
|
#include <ripple/rpc/handlers/Random.cpp>
|
||||||
#include <ripple/rpc/handlers/RipplePathFind.cpp>
|
#include <ripple/rpc/handlers/RipplePathFind.cpp>
|
||||||
#include <ripple/rpc/handlers/SMS.cpp>
|
#include <ripple/rpc/handlers/SMS.cpp>
|
||||||
|
|||||||
Reference in New Issue
Block a user