Skip to content

Commit

Permalink
3.7.7.0-Leisure
Browse files Browse the repository at this point in the history
Fixed
 - Beacon validation are now done when accepting blocks, not when receiving,
   #899 (@denravonska).
 - Fix crashes due to buffer overflow in encrypt/decrypt, #890 (@denravonska).
 - Rewrite reorganize routine to be more reliable and drop contracts received
   or issued while on a side chain to help reducing forks, #902 (@tomasbrod).
  • Loading branch information
denravonska committed Feb 1, 2018
2 parents 224cc89 + 1b98c03 commit d3c0eb9
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 296 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.7.7.0]
### Fixed
- Beacon validation are now done when accepting blocks, not when receiving,
#899 (@denravonska).
- Fix crashes due to buffer overflow in encrypt/decrypt, #890 (@denravonska).
- Rewrite reorganize routine to be more reliable and drop contracts received
or issued while on a side chain to help reducing forks, #902 (@tomasbrod).

## [3.7.6.0]
Internal test version used to sort out the forks.

## [3.7.5.0] 2018-01-24
### Fixed
- Fix crash when switching to new tally on block 1144120, #868 (@denravonska).
Expand Down
14 changes: 6 additions & 8 deletions src/beacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,20 @@ std::string RetrieveBeaconValueWithMaxAge(const std::string& cpid, int64_t iMaxS
: value;
}

bool VerifyBeaconContractTx(const std::string& txhashBoinc)
bool VerifyBeaconContractTx(const CTransaction& tx)
{
// Mandatory condition handled in CheckBlock

// Check if tx contains beacon advertisement and evaluate for certain conditions
std::string chkMessageType = ExtractXML(txhashBoinc, "<MT>", "</MT>");
std::string chkMessageAction = ExtractXML(txhashBoinc, "<MA>", "</MA>");
std::string chkMessageType = ExtractXML(tx.hashBoinc, "<MT>", "</MT>");
std::string chkMessageAction = ExtractXML(tx.hashBoinc, "<MA>", "</MA>");

if (chkMessageType != "beacon")
return true; // Not beacon contract

if (chkMessageAction != "A")
return true; // Not an add contract for beacon

std::string chkMessageContract = ExtractXML(txhashBoinc, "<MV>", "</MV>");
std::string chkMessageContractCPID = ExtractXML(txhashBoinc, "<MK>", "</MK>");
std::string chkMessageContract = ExtractXML(tx.hashBoinc, "<MV>", "</MV>");
std::string chkMessageContractCPID = ExtractXML(tx.hashBoinc, "<MK>", "</MK>");
// Here we GetBeaconElements for the contract in the tx
std::string tx_out_cpid;
std::string tx_out_address;
Expand All @@ -174,7 +172,7 @@ bool VerifyBeaconContractTx(const std::string& txhashBoinc)
}

int64_t chkiAge = pindexBest != NULL
? pindexBest->nTime - mvApplicationCacheTimestamp[chkKey]
? tx.nLockTime - mvApplicationCacheTimestamp[chkKey]
: 0;
int64_t chkSecondsBase = 60 * 24 * 30 * 60;

Expand Down
3 changes: 2 additions & 1 deletion src/beacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include "fwd.h"
#include <string>

//!
Expand Down Expand Up @@ -63,4 +64,4 @@ std::string GetBeaconPublicKey(const std::string& cpid, bool bAdvertisingBeacon)
int64_t BeaconTimeStamp(const std::string& cpid, bool bZeroOutAfterPOR);
bool HasActiveBeacon(const std::string& cpid);

bool VerifyBeaconContractTx(const std::string& txhashBoinc);
bool VerifyBeaconContractTx(const CTransaction& tx);
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 3
#define CLIENT_VERSION_MINOR 7
#define CLIENT_VERSION_REVISION 5
#define CLIENT_VERSION_REVISION 7
#define CLIENT_VERSION_BUILD 0

// Converts the parameter X to a string after macro replacement on X has been performed.
Expand Down
29 changes: 10 additions & 19 deletions src/crypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,22 @@ bool GridDecryptWithSalt(const std::vector<unsigned char>& vchCiphertext,std::ve
int nLen = vchCiphertext.size();
int nPLen = nLen, nFLen = 0;
bool fOk = true;

// Allocate data for the plaintext string. This is always equal to lower
// than the length of the encrypted string. Stray data is discarded
// after successfully decrypting.
vchPlaintext.resize(nLen);

EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
if(!ctx)
throw std::runtime_error("Error allocating cipher context");

if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKeyGridcoin, chIVGridcoin);
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKeyGridcoin, chIVGridcoin);
if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen);
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen);
EVP_CIPHER_CTX_free(ctx);
if (!fOk) return false;

vchPlaintext.resize(nPLen + nFLen);
return true;
}
Expand Down Expand Up @@ -348,12 +355,10 @@ std::string AdvancedDecryptWithHWID(std::string data)

std::string AdvancedCryptWithSalt(std::string boinchash, std::string salt)
{

try
{
std::vector<unsigned char> vchSecret( boinchash.begin(), boinchash.end() );
std::string d1 = " ";
std::vector<unsigned char> vchCryptedSecret(d1.begin(),d1.end());
std::vector<unsigned char> vchCryptedSecret;
GridEncryptWithSalt(vchSecret, vchCryptedSecret,salt);
std::string encrypted = EncodeBase64(UnsignedVectorToString(vchCryptedSecret));

Expand All @@ -363,21 +368,14 @@ std::string AdvancedCryptWithSalt(std::string boinchash, std::string salt)
printf("Error while encrypting %s",boinchash.c_str());
return "";
}
catch(...)
{
printf("Error while encrypting 2.");
return "";
}

}

std::string AdvancedDecryptWithSalt(std::string boinchash_encrypted, std::string salt)
{
try{
std::string pre_encrypted_boinchash = DecodeBase64(boinchash_encrypted);
std::string d2 = " ";
std::vector<unsigned char> vchCryptedSecret(pre_encrypted_boinchash.begin(),pre_encrypted_boinchash.end());
std::vector<unsigned char> vchPlaintext(d2.begin(),d2.end());
std::vector<unsigned char> vchPlaintext;
GridDecryptWithSalt(vchCryptedSecret,vchPlaintext,salt);
std::string decrypted = UnsignedVectorToString(vchPlaintext);
return decrypted;
Expand All @@ -386,11 +384,4 @@ std::string AdvancedDecryptWithSalt(std::string boinchash_encrypted, std::string
printf("Error while decrypting %s",boinchash_encrypted.c_str());
return "";
}
catch(...)
{
printf("Error while decrypting 2.");
return "";
}
}


1 change: 1 addition & 0 deletions src/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class CBlock;
class CBlockIndex;
class CNetAddr;
class CTransaction;

// Gridcoin
struct MiningCPID;
Expand Down
Loading

0 comments on commit d3c0eb9

Please sign in to comment.