Blockchain-C-Plus-Plus-Example icon indicating copy to clipboard operation
Blockchain-C-Plus-Plus-Example copied to clipboard

I cracked the chain

Open kenhero opened this issue 7 years ago • 1 comments

I cracked the chain and it says it's still valid

// Someone's getting sneaky Block *hackBlock = awesomeCoin.getLatestBlock(); cout << "Hash = " << hackBlock->getHash() << endl << "Previous Hash is " << hackBlock->getPreviousHash() << endl << "Is valid Hash? " << hackBlock->isHashValid() << endl; //creo transactiondata fake con modificato solo ammontare e destinatario e stesso timestamp TransactionData d(10000, hackBlock->data.senderKey, "Jon", hackBlock->data.timestamp); Block b(hackBlock->getIndex(), d, hackBlock->getPreviousHash());

//stampa dell ultimo block della chain prima di provare a crakkare,dovrebbe essere tutto ok
//cout << "Hash = " << hackBlock->getHash() << endl << "Previous Hash is " << hackBlock->getPreviousHash() << endl << "Is valid Hash? " << hackBlock->isHashValid() << endl;
*hackBlock = b;
//test dopo modifica
//cout << "Hash = " << hackBlock->getHash() << endl << "Previous Hash is " << hackBlock->getPreviousHash() << endl << "Is valid Hash? " << hackBlock->isHashValid() << endl;


/*hackBlock->data.amount = 10000; // Oh yeah!
hackBlock->data.receiverKey = "Jon"; // mwahahahaha!
//cout << "Hash = " << hackBlock->getHash() << endl << "Previous Hash is " << hackBlock->getPreviousHash() << endl << "Is valid Hash? " << hackBlock->isHashValid() << endl;
*/
// Let's look at data
awesomeCoin.printChain();

// Awww! Why is it not valid?
printf("\nIs chain still valid? %d\n", awesomeCoin.isChainValid());

kenhero avatar Jan 08 '19 11:01 kenhero

A solo chain can always be cracked. If there are two chains, your cracked version and my un-cracked version will fight like 2 gladiators. Only one of us will survive. If there are three chains, then your cracked version and the other two un-cracked version will fight. The other two uncracked chains will be the same chain, and your cracked chain is the different one. These chains will vary in their lengths. But the pure chain will eventually be longer, and the longer chain is chosen winner. The pure chain gets longer first, because it is distributed nodes and parallel computing involved and their similarity checks faster in the network. Indeed, you are correct that you can crack your own copy of the chain there is no stopping there from doing it. More theory called "Byzantine General's Problem".

typelogic avatar Apr 20 '19 09:04 typelogic