basic integration of cryptoconditions
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
#include "pubkey.h"
|
||||
#include "script/script.h"
|
||||
#include "uint256.h"
|
||||
#include "cryptoconditions/include/cryptoconditions.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -934,6 +936,51 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_CHECKCRYPTOCONDITION:
|
||||
case OP_CHECKCRYPTOCONDITIONVERIFY:
|
||||
{
|
||||
// (fulfillment condition -- bool)
|
||||
|
||||
if (stack.size() < 2)
|
||||
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
|
||||
|
||||
valtype& vchFulfillment = stacktop(-2);
|
||||
valtype& vchCondition = stacktop(-1);
|
||||
|
||||
// Hard limit fulfillment size
|
||||
if (vchFulfillment.size() > 1024 * 10) {
|
||||
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT);
|
||||
}
|
||||
|
||||
CC *cond = (CC*) calloc(1, sizeof(CC));
|
||||
char *fulfillmentBin = (char*) vchFulfillment.data();
|
||||
int rc = cc_readFulfillmentBinary(cond, fulfillmentBin, vchFulfillment.size());
|
||||
if (rc != 0) {
|
||||
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT);
|
||||
}
|
||||
|
||||
char *condBin = (char*) &vchCondition[0];
|
||||
// TODO: Should nHashType be hardcoded?
|
||||
// Other types use the last byte of the signature
|
||||
char *msg = (char*) checker.GetMessage(script, SIGHASH_ALL).begin();
|
||||
;
|
||||
bool fSuccess = cc_verify(cond, msg, 32, condBin, vchCondition.size());
|
||||
|
||||
popstack(stack);
|
||||
popstack(stack);
|
||||
|
||||
stack.push_back(fSuccess ? vchTrue : vchFalse);
|
||||
|
||||
if (opcode == OP_CHECKCRYPTOCONDITIONVERIFY)
|
||||
{
|
||||
if (fSuccess)
|
||||
popstack(stack);
|
||||
else
|
||||
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_VERIFY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return set_error(serror, SCRIPT_ERR_BAD_OPCODE);
|
||||
}
|
||||
@@ -1147,6 +1194,11 @@ bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) con
|
||||
return true;
|
||||
}
|
||||
|
||||
uint256 TransactionSignatureChecker::GetMessage(const CScript& scriptCode, int nHashType) const
|
||||
{
|
||||
return SignatureHash(scriptCode, *txTo, nIn, nHashType);
|
||||
}
|
||||
|
||||
|
||||
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
|
||||
{
|
||||
|
||||
@@ -102,6 +102,12 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual uint256 GetMessage(const CScript& scriptCode, int nHashType) const
|
||||
{
|
||||
uint256 blob;
|
||||
return blob;
|
||||
}
|
||||
|
||||
virtual ~BaseSignatureChecker() {}
|
||||
};
|
||||
|
||||
@@ -118,6 +124,7 @@ public:
|
||||
TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn) : txTo(txToIn), nIn(nInIn) {}
|
||||
bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const;
|
||||
bool CheckLockTime(const CScriptNum& nLockTime) const;
|
||||
uint256 GetMessage(const CScript& scriptCode, int nHashType) const;
|
||||
};
|
||||
|
||||
class MutableTransactionSignatureChecker : public TransactionSignatureChecker
|
||||
|
||||
@@ -138,6 +138,9 @@ const char* GetOpName(opcodetype opcode)
|
||||
case OP_CHECKSIGVERIFY : return "OP_CHECKSIGVERIFY";
|
||||
case OP_CHECKMULTISIG : return "OP_CHECKMULTISIG";
|
||||
case OP_CHECKMULTISIGVERIFY : return "OP_CHECKMULTISIGVERIFY";
|
||||
case OP_CHECKCRYPTOCONDITION : return "OP_CHECKCRYPTOCONDITION";
|
||||
case OP_CHECKCRYPTOCONDITIONVERIFY
|
||||
: return "OP_CHECKCRYPTOCONDITIONVERIFY";
|
||||
|
||||
// expanson
|
||||
case OP_NOP1 : return "OP_NOP1";
|
||||
|
||||
@@ -154,6 +154,8 @@ enum opcodetype
|
||||
OP_CHECKSIGVERIFY = 0xad,
|
||||
OP_CHECKMULTISIG = 0xae,
|
||||
OP_CHECKMULTISIGVERIFY = 0xaf,
|
||||
OP_CHECKCRYPTOCONDITION = 0xcc,
|
||||
OP_CHECKCRYPTOCONDITIONVERIFY = 0xcd,
|
||||
|
||||
// expansion
|
||||
OP_NOP1 = 0xb0,
|
||||
@@ -168,7 +170,6 @@ enum opcodetype
|
||||
OP_NOP9 = 0xb8,
|
||||
OP_NOP10 = 0xb9,
|
||||
|
||||
|
||||
// template matching params
|
||||
OP_SMALLDATA = 0xf9,
|
||||
OP_SMALLINTEGER = 0xfa,
|
||||
|
||||
@@ -52,7 +52,10 @@ typedef enum ScriptError_t
|
||||
/* softfork safeness */
|
||||
SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS,
|
||||
|
||||
SCRIPT_ERR_ERROR_COUNT
|
||||
SCRIPT_ERR_ERROR_COUNT,
|
||||
|
||||
SCRIPT_ERR_CRYPTOCONDITION_VERIFY,
|
||||
SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT
|
||||
} ScriptError;
|
||||
|
||||
#define SCRIPT_ERR_LAST SCRIPT_ERR_ERROR_COUNT
|
||||
|
||||
Reference in New Issue
Block a user