Komodo CC aux callback has access to transaction via checker
This commit is contained in:
@@ -336,6 +336,7 @@ libbitcoin_common_a_SOURCES = \
|
|||||||
script/script_error.cpp \
|
script/script_error.cpp \
|
||||||
script/sign.cpp \
|
script/sign.cpp \
|
||||||
script/standard.cpp \
|
script/standard.cpp \
|
||||||
|
komodo_cryptoconditions.cpp \
|
||||||
$(BITCOIN_CORE_H) \
|
$(BITCOIN_CORE_H) \
|
||||||
$(LIBZCASH_H)
|
$(LIBZCASH_H)
|
||||||
|
|
||||||
@@ -505,6 +506,7 @@ libzcashconsensus_la_SOURCES = \
|
|||||||
script/zcashconsensus.cpp \
|
script/zcashconsensus.cpp \
|
||||||
script/interpreter.cpp \
|
script/interpreter.cpp \
|
||||||
script/script.cpp \
|
script/script.cpp \
|
||||||
|
komodo_cryptoconditions.cpp \
|
||||||
uint256.cpp \
|
uint256.cpp \
|
||||||
utilstrencodings.cpp
|
utilstrencodings.cpp
|
||||||
|
|
||||||
|
|||||||
Submodule src/cryptoconditions updated: 6b859e63a2...e33203ae34
8
src/komodo_cryptoconditions.cpp
Normal file
8
src/komodo_cryptoconditions.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
#include "cryptoconditions/include/cryptoconditions.h"
|
||||||
|
#include "script/interpreter.h"
|
||||||
|
|
||||||
|
|
||||||
|
int CryptoConditionChecker::CheckAuxCondition(const CC *cond) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -9,11 +9,4 @@ static bool IsCryptoConditionsEnabled() {
|
|||||||
return 0 != ASSETCHAINS_CC;
|
return 0 != ASSETCHAINS_CC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Method stub for aux conditions. Unimplemented, thus fails if an aux condition is encountered.
|
|
||||||
*/
|
|
||||||
static int komodoCCAux(CC *cond, void *context) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* KOMODO_CRYPTOCONDITIONS_H */
|
#endif /* KOMODO_CRYPTOCONDITIONS_H */
|
||||||
|
|||||||
@@ -949,18 +949,15 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
|
|||||||
valtype& vchFulfillment = stacktop(-2);
|
valtype& vchFulfillment = stacktop(-2);
|
||||||
valtype& vchCondition = stacktop(-1);
|
valtype& vchCondition = stacktop(-1);
|
||||||
|
|
||||||
char *fulfillmentBin = (char*) vchFulfillment.data();
|
CC *cond = cc_readFulfillmentBinary((unsigned char*)vchFulfillment.data(),
|
||||||
CC *cond = cc_readFulfillmentBinary(fulfillmentBin, vchFulfillment.size());
|
vchFulfillment.size());
|
||||||
if (!cond) {
|
if (!cond) {
|
||||||
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT);
|
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *condBin = (char*) &vchCondition[0];
|
bool fSuccess = checker.CheckCryptoCondition(cond, vchCondition, script);
|
||||||
// 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(), komodoCCAux, NULL);
|
cc_free(cond);
|
||||||
|
|
||||||
popstack(stack);
|
popstack(stack);
|
||||||
popstack(stack);
|
popstack(stack);
|
||||||
@@ -1155,6 +1152,22 @@ bool TransactionSignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
static int komodoCCAux(CC *cond, void *transactionSignatureChecker);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int komodoCCAux(CC *cond, void *checker) {
|
||||||
|
return ((CryptoConditionChecker*)checker)->CheckAuxCondition(cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TransactionSignatureChecker::CheckCryptoCondition(const CC *cond, const std::vector<unsigned char>& condBin, const CScript& scriptCode) const
|
||||||
|
{
|
||||||
|
uint256 message = SignatureHash(scriptCode, *txTo, nIn, SIGHASH_ALL);
|
||||||
|
return cc_verify(cond, (const unsigned char*)&message, 32,
|
||||||
|
condBin.data(), condBin.size(), komodoCCAux, (void*)this);
|
||||||
|
}
|
||||||
|
|
||||||
bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) const
|
bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) const
|
||||||
{
|
{
|
||||||
// There are two times of nLockTime: lock-by-blockheight
|
// There are two times of nLockTime: lock-by-blockheight
|
||||||
@@ -1191,11 +1204,6 @@ bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) con
|
|||||||
return true;
|
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)
|
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "script_error.h"
|
#include "script_error.h"
|
||||||
#include "primitives/transaction.h"
|
#include "primitives/transaction.h"
|
||||||
|
#include "komodo_cryptoconditions.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -102,10 +103,9 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint256 GetMessage(const CScript& scriptCode, int nHashType) const
|
virtual bool CheckCryptoCondition(const CC *cond, const std::vector<unsigned char>& condBin, const CScript& scriptCode) const
|
||||||
{
|
{
|
||||||
uint256 blob;
|
return false;
|
||||||
return blob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~BaseSignatureChecker() {}
|
virtual ~BaseSignatureChecker() {}
|
||||||
@@ -124,7 +124,7 @@ public:
|
|||||||
TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn) : txTo(txToIn), nIn(nInIn) {}
|
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 CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const;
|
||||||
bool CheckLockTime(const CScriptNum& nLockTime) const;
|
bool CheckLockTime(const CScriptNum& nLockTime) const;
|
||||||
uint256 GetMessage(const CScript& scriptCode, int nHashType) const;
|
bool CheckCryptoCondition(const CC *cond, const std::vector<unsigned char>& condBin, const CScript& scriptCode) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MutableTransactionSignatureChecker : public TransactionSignatureChecker
|
class MutableTransactionSignatureChecker : public TransactionSignatureChecker
|
||||||
@@ -139,4 +139,10 @@ public:
|
|||||||
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
|
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
|
||||||
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
|
bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
|
||||||
|
|
||||||
|
class CryptoConditionChecker : public TransactionSignatureChecker
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int CheckAuxCondition(const CC *cond) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_SCRIPT_INTERPRETER_H
|
#endif // BITCOIN_SCRIPT_INTERPRETER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user