JayDDee / cpuminer-opt

Optimized multi algo CPU miner
Other
777 stars 549 forks source link

algo request - dualpow algo/logic support #425

Closed mraksoll4 closed 4 months ago

mraksoll4 commented 4 months ago

Logic


static bool CheckBlockHeader(const CBlockHeader& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true)
{
    // Check proof of work's matches claimed amount (dual pow logic)
    bool powResult1 = fCheckPOW ? CheckProofOfWork(block.GetYespowerPoWHash(), block.nBits, consensusParams) : true;
    bool powResult2 = fCheckPOW ? CheckProofOfWork(block.GetArgon2idPoWHash(), block.nBits, consensusParams) : true;

    // Checking if both POW's are valid
    if (!powResult1 || !powResult2) {
        return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "high-hash", "proof of work's failed");
    }

    return true;
}

/* Yespower */
uint256 CBlockHeader::GetYespowerPoWHash() const
{
    static const yespower_params_t yespower_1_0_dpowcoin = {
        .version = YESPOWER_1_0,
        .N = 2048,
        .r = 8,
        .pers = (const uint8_t *)"One POW? Why not two? 17/04/2024",
        .perslen = 32
    };
    uint256 hash;
    CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
    ss << *this;
    if (yespower_tls((const uint8_t *)&ss[0], ss.size(), &yespower_1_0_dpowcoin, (yespower_binary_t *)&hash)) {
        tfm::format(std::cerr, "Error: CBlockHeader::GetYespowerPoWHash(): failed to compute PoW hash (out of memory?)\n");
        exit(1);
    }
    return hash;
}

// CBlockHeader::GetArgon2idPoWHash() instance
// -> Serialize Block Header using CDataStream
// -> Compute SHA-512 hash of serialized data (Two Rounds)
// -> Use the computed hash as the salt for argon2id_hash_raw function for the first round
// -> Call argon2id_hash_raw function for the first round using the serialized data as password and SHA-512 hash as salt
// -> Use the hash obtained from the first round as the salt for the second round
// -> Call argon2id_hash_raw function for the second round using the serialized data as password and the hash from the first round as salt
// -> Return the hash computed in the second round (hash2)

uint256 CBlockHeader::GetArgon2idPoWHash() const
{
    uint256 hash;
    uint256 hash2;
    CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
    ss << *this;

    // Hashing the data using SHA-512 (two rounds)
    std::vector<unsigned char> salt_sha512(CSHA512::OUTPUT_SIZE);
    CSHA512 sha512;
    sha512.Write((unsigned char*)&ss[0], ss.size()).Finalize(salt_sha512.data());
    sha512.Reset().Write(salt_sha512.data(), salt_sha512.size()).Finalize(salt_sha512.data());

    // Preparing data for hashing
    const void* pwd = &ss[0];
    size_t pwdlen = ss.size();
    const void* salt = salt_sha512.data();
    size_t saltlen = salt_sha512.size();

    // Calling the argon2id_hash_raw function for the first round
    int rc = argon2id_hash_raw(2, 4096, 2, pwd, pwdlen, salt, saltlen, &hash, 32);
    if (rc != ARGON2_OK) {
        printf("Error: Failed to compute Argon2id hash for the first round\n");
        exit(1);
    }

    // Using the hash from the first round as the salt for the second round
    salt = &hash;
    saltlen = 32;

    // Calling the argon2id_hash_raw function for the second round
    rc = argon2id_hash_raw(2, 32768, 2, pwd, pwdlen, salt, saltlen, &hash2, 32);
    if (rc != ARGON2_OK) {
        printf("Error: Failed to compute Argon2id hash for the second round\n");
        exit(1);
    }

    // Return the result of the second round of Argon2id
    return hash2;
}

https://bitcointalk.org/index.php?topic=5493459.0

https://github.com/dpowcore-project/dpowcoin/tree/master/src/crypto

JayDDee commented 4 months ago

Rplant already supports it, I'm not going to duplicate their work.

mraksoll4 commented 4 months ago

Rplant already supports it, I'm not going to duplicate their work.

yes he support , but people ask original miner with working solo mining with open source code. Rplant miner closed source.

JayDDee commented 4 months ago

Precisely! I would have to do the work all over again. That's not going to happen.

mraksoll4 commented 4 months ago

this is sad, but as a coin core developer I don’t care, since these are not my concerns, people asked me, I created a request, no then no :)

mraksoll4 commented 3 months ago

in principle, full adaptation is not necessary, I would do everything myself, but I need to at least know where the logic of checking the pow is in order to add a double algorithm there and if I do it, then like with yescrypts/yespower , etc., with parameters where we specify algorithms

aka 1 first pow , 2 pow - algos. or even more depeding at setting if future project repeat idea...

The main problem is that for me as a person who hasn’t dug into the miner code, I have to trace everything, what goes where, and there are no normal comments in the miner code or they are not clear to me.

that is, I need to simply need know where in the code the functions for checking the pow , and where it call algo for them, everything essentially comes down to calling 2 algorithms in turn and calculating the hash rate by 2.

It's actually a shame that any trash with a premine is supported by 99% of people, but when a project is created for the community, everyone doesn't give a damn about its decentralization, the problem of centralization in 1 pool is very relevant and it needs to be solved too.