From 96bc9641235d4e75458a572a33347c606da4fd2b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 16:16:28 +0500 Subject: [PATCH] corr add funding tx validation added amount check --- src/cc/prices.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index f04496eba..c6df1ccb5 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -238,8 +238,11 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac int16_t leverage; CPubKey pk, pricespk; std::vector vec; + + // check payment cc config: if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) GetKomodoEarlytxidScriptPub(); + if (bettx.vout.size() < 5 || bettx.vout.size() > 6) return eval->Invalid("incorrect vout number for bet tx"); @@ -260,7 +263,7 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac return eval->Invalid("the fee was paid to wrong address."); int64_t betamount = bettx.vout[2].nValue; - if (betamount != (positionsize * 199) / 200) { + if (betamount != PRICES_SUBREVSHAREFEE(positionsize)) { return eval->Invalid("invalid position size in the opreturn"); } @@ -289,7 +292,11 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C CPubKey pk, pricespk; vscript_t vintxOpret; - if (addfundingtx.vout.size() < 3 || addfundingtx.vout.size() > 4) + // check payment cc config: + if (ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0) + GetKomodoEarlytxidScriptPub(); + + if (addfundingtx.vout.size() < 4 || addfundingtx.vout.size() > 5) return eval->Invalid("incorrect vout number for add funding tx"); vscript_t opret; @@ -311,6 +318,11 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C if (MakeCC1vout(cp->evalcode, addfundingtx.vout[1].nValue, pricespk) != addfundingtx.vout[1]) return eval->Invalid("cannot validate vout1 in add funding tx with global pk"); + int64_t betamount = addfundingtx.vout[2].nValue; + if (betamount != PRICES_SUBREVSHAREFEE(amount)) { + return eval->Invalid("invalid position size in the opreturn"); + } + return true; }