Process finished with exit code -1073741819 (0xC0000005) in my crypto

0

Me and a friend is trying to make a crypto from scratch but we have ran in to an error. We have tracked down the problems to our block class

class Block {
    string previousHash;
    ist <Transaction> transactions;
    int difficulty;
    string currentHash = getHash();
    time_t timeFound;
    list <int> triedFillers;
    list <string> fillerHashes;
    int filler = 0;
    bool found = false;
    string hash;

public:
    Block () {
    }

    bool foundHash() {
        return found;
    }

    int getFiller() {
        return filler;
    }

    vector <string> getFillerHashResults() {
        vector <string > vecOfStr(fillerHashes.begin(), fillerHashes.end());
        return vecOfStr;
    }

    vector <int> triedFillerHashes() {
        vector <int> vecOfStr(triedFillers.begin(), triedFillers.end());
        return vecOfStr;
    }

    int getDifficulty() {
        return difficulty;
    };
    void setDifficulty(int difficulty) {
        found = false;
        this->difficulty = difficulty;
    };

    void setPreviousHash(string previousHash) {
        found = false;
        this->previousHash = previousHash;
    }
    string getPreviousHash() {
        return previousHash;
    }

    void addTransaction(Transaction transaction) {
        found = false;
        this->transactions.push_back(transaction);
    }
    void removeTransaction(int position) {
        cout << "Not implemented yet \n";
    }

    vector<Transaction> getTransactions() {
        vector <Transaction > vecOfStr(transactions.begin(), transactions.end());
        return vecOfStr;
    }

    string getHash() {
        if (!found) {
            triedFillers.clear();
            fillerHashes.clear();

            Transaction *transactionsHashes = new Transaction[this->transactions.size()];
            int l = 0;
            for (Transaction const &i: this->transactions) {
                transactionsHashes[l++] = i;
            }

            string all = previousHash;
            for (unsigned int i = 0; i < this->transactions.size(); i++) {
                all += "\n" + transactionsHashes[i].getHash();
            }

            stringstream ss;
            ss << hex << difficulty;
            string diff = ss.str();
            while (sha256(all + to_string(filler)) < diff) {
                triedFillers.push_back(filler);
                fillerHashes.push_back(sha256(all + to_string(filler)));
                filler++;
            }

            timeFound = time(NULL);
            hash = sha256(all);

            return sha256(all);

        } else {
            return hash;
        }
    }
    string forceFindNewHash() {
        found = false;
        return getHash();
    }
};

When trying to either debug in VS code or compile we get get the following error:

Error

We know that it is a memory read/write problem but we dont know where

If anyone got any solutions to this error i would be happy to read them and if you got any further questions i will gladly answer them

exception
cryptocurrency
memory-access
asked on Stack Overflow Apr 8, 2021 by TechyGuy

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0