This commit is contained in:
jl777
2018-08-18 03:07:53 -11:00
parent b626aafeb0
commit b4795ed684
10 changed files with 15 additions and 31 deletions

View File

@@ -260,7 +260,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> param
//txid = ctx.GetHash(); //txid = ctx.GetHash();
//if ( txid == cp->prevtxid ) //if ( txid == cp->prevtxid )
// return(true); // return(true);
fprintf(stderr,"process CC %02x\n",cp->evalcode); //fprintf(stderr,"process CC %02x\n",cp->evalcode);
if ( paramsNull.size() != 0 ) // Don't expect params if ( paramsNull.size() != 0 ) // Don't expect params
return eval->Invalid("Cannot have params"); return eval->Invalid("Cannot have params");
else if ( ctx.vout.size() == 0 ) else if ( ctx.vout.size() == 0 )

View File

@@ -38,7 +38,7 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn)
pthread_mutex_lock(&KOMODO_CC_mutex); pthread_mutex_lock(&KOMODO_CC_mutex);
bool out = eval->Dispatch(cond, tx, nIn); bool out = eval->Dispatch(cond, tx, nIn);
pthread_mutex_unlock(&KOMODO_CC_mutex); pthread_mutex_unlock(&KOMODO_CC_mutex);
fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); //fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid());
assert(eval->state.IsValid() == out); assert(eval->state.IsValid() == out);
if (eval->state.IsValid()) return true; if (eval->state.IsValid()) return true;

View File

@@ -116,20 +116,14 @@ uint32_t fromAsnSubtypes(const ConditionTypes_t types) {
size_t cc_conditionBinary(const CC *cond, unsigned char *buf) { size_t cc_conditionBinary(const CC *cond, unsigned char *buf) {
fprintf(stderr,"inside cc_conditionBinary\n");
Condition_t *asn = calloc(1, sizeof(Condition_t)); Condition_t *asn = calloc(1, sizeof(Condition_t));
fprintf(stderr,"asn.%p\n",asn);
asnCondition(cond, asn); asnCondition(cond, asn);
fprintf(stderr,"call derencode\n");
asn_enc_rval_t rc = der_encode_to_buffer(&asn_DEF_Condition, asn, buf, 1000); asn_enc_rval_t rc = der_encode_to_buffer(&asn_DEF_Condition, asn, buf, 1000);
fprintf(stderr,"back from derencode\n");
if (rc.encoded == -1) { if (rc.encoded == -1) {
fprintf(stderr, "CONDITION NOT ENCODED\n"); fprintf(stderr, "CONDITION NOT ENCODED\n");
return 0; return 0;
} }
fprintf(stderr,"call ASN_STRUCT_FREE\n");
ASN_STRUCT_FREE(asn_DEF_Condition, asn); ASN_STRUCT_FREE(asn_DEF_Condition, asn);
fprintf(stderr,"return rc.encoded %d\n",(int32_t)rc.encoded);
return rc.encoded; return rc.encoded;
} }
@@ -152,15 +146,11 @@ void asnCondition(const CC *cond, Condition_t *asn) {
// This may look a little weird - we dont have a reference here to the correct // This may look a little weird - we dont have a reference here to the correct
// union choice for the condition type, so we just assign everything to the threshold // union choice for the condition type, so we just assign everything to the threshold
// type. This works out nicely since the union choices have the same binary interface. // type. This works out nicely since the union choices have the same binary interface.
fprintf(stderr,"asnCondition type.%p\n",cond->type);
CompoundSha256Condition_t *choice = &asn->choice.thresholdSha256; CompoundSha256Condition_t *choice = &asn->choice.thresholdSha256;
choice->cost = cc_getCost(cond); choice->cost = cc_getCost(cond);
fprintf(stderr,"after cost\n");
choice->fingerprint.buf = cond->type->fingerprint(cond); choice->fingerprint.buf = cond->type->fingerprint(cond);
choice->fingerprint.size = 32; choice->fingerprint.size = 32;
fprintf(stderr,"after fingerprint\n");
choice->subtypes = asnSubtypes(cond->type->getSubtypes(cond)); choice->subtypes = asnSubtypes(cond->type->getSubtypes(cond));
fprintf(stderr,"after asnSubtypes\n");
} }
@@ -240,35 +230,30 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength,
const unsigned char *condBin, size_t condBinLength, const unsigned char *condBin, size_t condBinLength,
VerifyEval verifyEval, void *evalContext) { VerifyEval verifyEval, void *evalContext) {
unsigned char targetBinary[1000]; unsigned char targetBinary[1000];
fprintf(stderr,"in cc_verify cond.%p msg.%p[%d] dohash.%d condbin.%p[%d]\n",cond,msg,(int32_t)msgLength,doHashMsg,condBin,(int32_t)condBinLength); //fprintf(stderr,"in cc_verify cond.%p msg.%p[%d] dohash.%d condbin.%p[%d]\n",cond,msg,(int32_t)msgLength,doHashMsg,condBin,(int32_t)condBinLength);
const size_t binLength = cc_conditionBinary(cond, targetBinary); const size_t binLength = cc_conditionBinary(cond, targetBinary);
if (0 != memcmp(condBin, targetBinary, binLength)) { if (0 != memcmp(condBin, targetBinary, binLength)) {
fprintf(stderr,"cc_verify error A\n"); fprintf(stderr,"cc_verify error A\n");
return 0; return 0;
} }
fprintf(stderr,"after memcmp\n");
if (!cc_ed25519VerifyTree(cond, msg, msgLength)) { if (!cc_ed25519VerifyTree(cond, msg, msgLength)) {
fprintf(stderr,"cc_verify error B\n"); fprintf(stderr,"cc_verify error B\n");
return 0; return 0;
} }
fprintf(stderr,"after cc_ed25519VerifyTree\n");
unsigned char msgHash[32]; unsigned char msgHash[32];
if (doHashMsg) sha256(msg, msgLength, msgHash); if (doHashMsg) sha256(msg, msgLength, msgHash);
else memcpy(msgHash, msg, 32); else memcpy(msgHash, msg, 32);
fprintf(stderr,"after memcpy/sha256\n");
if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) { if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) {
fprintf(stderr,"cc_verify error C\n"); fprintf(stderr,"cc_verify error C\n");
return 0; return 0;
} }
fprintf(stderr,"after cc_secp256k1VerifyTreeMsg32\n");
if (!cc_verifyEval(cond, verifyEval, evalContext)) { if (!cc_verifyEval(cond, verifyEval, evalContext)) {
fprintf(stderr,"cc_verify error D\n"); fprintf(stderr,"cc_verify error D\n");
return 0; return 0;
} }
fprintf(stderr,"return 1\n");
return 1; return 1;
} }

View File

@@ -27,7 +27,7 @@ struct CCType CC_Ed25519Type;
static unsigned char *ed25519Fingerprint(const CC *cond) { static unsigned char *ed25519Fingerprint(const CC *cond) {
Ed25519FingerprintContents_t *fp = calloc(1, sizeof(Ed25519FingerprintContents_t)); Ed25519FingerprintContents_t *fp = calloc(1, sizeof(Ed25519FingerprintContents_t));
fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey); //fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey);
OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, 32); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, 32);
return hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp); return hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp);
} }

View File

@@ -27,7 +27,7 @@ struct CCType CC_EvalType;
static unsigned char *evalFingerprint(const CC *cond) { static unsigned char *evalFingerprint(const CC *cond) {
unsigned char *hash = calloc(1, 32); unsigned char *hash = calloc(1, 32);
fprintf(stderr,"evalfingerprint %p %p\n",hash,cond->code); //fprintf(stderr,"evalfingerprint %p %p\n",hash,cond->code);
sha256(cond->code, cond->codeLength, hash); sha256(cond->code, cond->codeLength, hash);
return hash; return hash;
} }

View File

@@ -39,7 +39,7 @@ static int prefixVisitChildren(CC *cond, CCVisitor visitor) {
static unsigned char *prefixFingerprint(const CC *cond) { static unsigned char *prefixFingerprint(const CC *cond) {
PrefixFingerprintContents_t *fp = calloc(1, sizeof(PrefixFingerprintContents_t)); PrefixFingerprintContents_t *fp = calloc(1, sizeof(PrefixFingerprintContents_t));
fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix); //fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix);
asnCondition(cond->subcondition, &fp->subcondition); // TODO: check asnCondition for safety asnCondition(cond->subcondition, &fp->subcondition); // TODO: check asnCondition for safety
fp->maxMessageLength = cond->maxMessageLength; fp->maxMessageLength = cond->maxMessageLength;
OCTET_STRING_fromBuf(&fp->prefix, cond->prefix, cond->prefixLength); OCTET_STRING_fromBuf(&fp->prefix, cond->prefix, cond->prefixLength);

View File

@@ -46,7 +46,7 @@ static unsigned long preimageCost(const CC *cond) {
static unsigned char *preimageFingerprint(const CC *cond) { static unsigned char *preimageFingerprint(const CC *cond) {
unsigned char *hash = calloc(1, 32); unsigned char *hash = calloc(1, 32);
fprintf(stderr,"preimage %p %p\n",hash,cond->preimage); //fprintf(stderr,"preimage %p %p\n",hash,cond->preimage);
sha256(cond->preimage, cond->preimageLength, hash); sha256(cond->preimage, cond->preimageLength, hash);
return hash; return hash;
} }

View File

@@ -73,9 +73,8 @@ void initVerify() {
static unsigned char *secp256k1Fingerprint(const CC *cond) { static unsigned char *secp256k1Fingerprint(const CC *cond) {
Secp256k1FingerprintContents_t *fp = calloc(1, sizeof(Secp256k1FingerprintContents_t)); Secp256k1FingerprintContents_t *fp = calloc(1, sizeof(Secp256k1FingerprintContents_t));
fprintf(stderr,"secpfinger %p %p size %d vs %d\n",fp,cond->publicKey,(int32_t)sizeof(Secp256k1FingerprintContents_t),(int32_t)SECP256K1_PK_SIZE); //fprintf(stderr,"secpfinger %p %p size %d vs %d\n",fp,cond->publicKey,(int32_t)sizeof(Secp256k1FingerprintContents_t),(int32_t)SECP256K1_PK_SIZE);
OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, SECP256K1_PK_SIZE); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, SECP256K1_PK_SIZE);
fprintf(stderr,"got octet\n");
return hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp); return hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp);
} }

View File

@@ -86,7 +86,7 @@ static int cmpConditionBin(const void *a, const void *b) {
static unsigned char *thresholdFingerprint(const CC *cond) { static unsigned char *thresholdFingerprint(const CC *cond) {
/* Create fingerprint */ /* Create fingerprint */
ThresholdFingerprintContents_t *fp = calloc(1, sizeof(ThresholdFingerprintContents_t)); ThresholdFingerprintContents_t *fp = calloc(1, sizeof(ThresholdFingerprintContents_t));
fprintf(stderr,"thresholdfinger %p\n",fp); //fprintf(stderr,"thresholdfinger %p\n",fp);
fp->threshold = cond->threshold; fp->threshold = cond->threshold;
for (int i=0; i<cond->size; i++) { for (int i=0; i<cond->size; i++) {
Condition_t *asnCond = asnConditionNew(cond->subconditions[i]); Condition_t *asnCond = asnConditionNew(cond->subconditions[i]);

View File

@@ -952,7 +952,7 @@ bool EvalScript(
if (stack.size() < 2) if (stack.size() < 2)
return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);
fprintf(stderr,"check cryptocondition\n"); //fprintf(stderr,"check cryptocondition\n");
int fResult = checker.CheckCryptoCondition(stacktop(-1), stacktop(-2), script, consensusBranchId); int fResult = checker.CheckCryptoCondition(stacktop(-1), stacktop(-2), script, consensusBranchId);
if (fResult == -1) { if (fResult == -1) {
return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT); return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT);
@@ -1313,7 +1313,7 @@ int TransactionSignatureChecker::CheckCryptoCondition(
} catch (logic_error ex) { } catch (logic_error ex) {
return 0; return 0;
} }
int32_t z; uint8_t *ptr; /*int32_t z; uint8_t *ptr;
ptr = (uint8_t *)scriptCode.data(); ptr = (uint8_t *)scriptCode.data();
for (z=0; z<scriptCode.size(); z++) for (z=0; z<scriptCode.size(); z++)
fprintf(stderr,"%02x",ptr[z]); fprintf(stderr,"%02x",ptr[z]);
@@ -1321,15 +1321,15 @@ int TransactionSignatureChecker::CheckCryptoCondition(
for (z=0; z<32; z++) for (z=0; z<32; z++)
fprintf(stderr,"%02x",((uint8_t *)&sighash)[z]); fprintf(stderr,"%02x",((uint8_t *)&sighash)[z]);
fprintf(stderr," sighash nIn.%d nHashType.%d %.8f id.%d\n",(int32_t)nIn,(int32_t)nHashType,(double)amount/COIN,(int32_t)consensusBranchId); fprintf(stderr," sighash nIn.%d nHashType.%d %.8f id.%d\n",(int32_t)nIn,(int32_t)nHashType,(double)amount/COIN,(int32_t)consensusBranchId);
*/
VerifyEval eval = [] (CC *cond, void *checker) { VerifyEval eval = [] (CC *cond, void *checker) {
fprintf(stderr,"checker.%p\n",(TransactionSignatureChecker*)checker); //fprintf(stderr,"checker.%p\n",(TransactionSignatureChecker*)checker);
return ((TransactionSignatureChecker*)checker)->CheckEvalCondition(cond); return ((TransactionSignatureChecker*)checker)->CheckEvalCondition(cond);
}; };
fprintf(stderr,"non-checker path\n"); //fprintf(stderr,"non-checker path\n");
int out = cc_verify(cond, (const unsigned char*)&sighash, 32, 0, int out = cc_verify(cond, (const unsigned char*)&sighash, 32, 0,
condBin.data(), condBin.size(), eval, (void*)this); condBin.data(), condBin.size(), eval, (void*)this);
fprintf(stderr,"out.%d from cc_verify\n",(int32_t)out); //fprintf(stderr,"out.%d from cc_verify\n",(int32_t)out);
cc_free(cond); cc_free(cond);
return out; return out;
} }