* make interface for getting tx safer in Eval

* restrict lengths in cryptoconditions to avoid ridiculous situations
This commit is contained in:
Scott Sadler
2018-04-06 14:35:46 -03:00
parent 56cf273faf
commit 4729632250
7 changed files with 47 additions and 35 deletions

View File

@@ -33,29 +33,27 @@ bool Eval::DisputePayout(AppVM &vm, const CC *cond, const CTransaction &disputeT
// load dispute header
DisputeHeader disputeHeader;
std::vector<unsigned char> headerData(cond->paramsBin,
cond->paramsBin+cond->paramsBinLength);
std::vector<unsigned char> headerData(
cond->paramsBin, cond->paramsBin+cond->paramsBinLength);
if (!CheckDeserialize(headerData, disputeHeader))
return Invalid("invalid-dispute-header");
// ensure that enough time has passed
CTransaction sessionTx;
uint256 sessionBlockHash;
CBlockIndex sessionBlock;
if (!GetTx(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlockHash, false))
return Error("couldnt-get-parent");
// TODO: This may not be an error, if both txs are to go into the same block...
// Probably change it to Invalid
if (!GetBlock(sessionBlockHash, sessionBlock))
return Error("couldnt-get-block");
{
CTransaction sessionTx;
CBlockIndex sessionBlock;
// if unconformed its too soon
if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock))
return Error("couldnt-get-parent");
if (GetCurrentHeight() < sessionBlock.nHeight + disputeHeader.waitBlocks)
return Invalid("dispute-too-soon"); // Not yet
if (GetCurrentHeight() < sessionBlock.nHeight + disputeHeader.waitBlocks)
return Invalid("dispute-too-soon"); // Not yet
}
// get spends
std::vector<CTransaction> spends;
if (!GetSpends(disputeTx.vin[0].prevout.hash, spends))
if (!GetSpendsConfirmed(disputeTx.vin[0].prevout.hash, spends))
return Error("couldnt-get-spends");
// verify result from VM