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/sign.cpp \
|
||||
script/standard.cpp \
|
||||
komodo_cryptoconditions.cpp \
|
||||
$(BITCOIN_CORE_H) \
|
||||
$(LIBZCASH_H)
|
||||
|
||||
@@ -505,6 +506,7 @@ libzcashconsensus_la_SOURCES = \
|
||||
script/zcashconsensus.cpp \
|
||||
script/interpreter.cpp \
|
||||
script/script.cpp \
|
||||
komodo_cryptoconditions.cpp \
|
||||
uint256.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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
|
||||
@@ -949,18 +949,15 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
|
||||
valtype& vchFulfillment = stacktop(-2);
|
||||
valtype& vchCondition = stacktop(-1);
|
||||
|
||||
char *fulfillmentBin = (char*) vchFulfillment.data();
|
||||
CC *cond = cc_readFulfillmentBinary(fulfillmentBin, vchFulfillment.size());
|
||||
CC *cond = cc_readFulfillmentBinary((unsigned char*)vchFulfillment.data(),
|
||||
vchFulfillment.size());
|
||||
if (!cond) {
|
||||
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 = checker.CheckCryptoCondition(cond, vchCondition, script);
|
||||
|
||||
bool fSuccess = cc_verify(cond, msg, 32, condBin, vchCondition.size(), komodoCCAux, NULL);
|
||||
cc_free(cond);
|
||||
|
||||
popstack(stack);
|
||||
popstack(stack);
|
||||
@@ -1155,6 +1152,22 @@ bool TransactionSignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn
|
||||
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
|
||||
{
|
||||
// There are two times of nLockTime: lock-by-blockheight
|
||||
@@ -1191,11 +1204,6 @@ 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)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "script_error.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "komodo_cryptoconditions.h"
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
@@ -102,10 +103,9 @@ public:
|
||||
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 blob;
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual ~BaseSignatureChecker() {}
|
||||
@@ -124,7 +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;
|
||||
bool CheckCryptoCondition(const CC *cond, const std::vector<unsigned char>& condBin, const CScript& scriptCode) const;
|
||||
};
|
||||
|
||||
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 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
|
||||
|
||||
Reference in New Issue
Block a user