qubic/core

[QA] Can I use random number as `solution nonce`?

qiji2023 opened this issue · 4 comments

const m256i& solution_nonce = *(m256i*)((unsigned char*)transaction + sizeof(Transaction));

here, Can I use random number as solution nonce?

and here

const m256i & solution_nonce = *(m256i*)((unsigned char*)transaction + sizeof(Transaction));

@philippwerner Can you help me?

I assume you want to develop a miner? This is the reference code: https://github.com/qubic/Qiner/tree/2024-march
It is not just a random number that is sent. Please read this code. It sends the solution with a Message.
This code

core/src/qubic.cpp

Lines 2423 to 2477 in 1d3dacd

int solutionIndexToPublish = -1;
unsigned int j;
for (j = 0; j < system.numberOfSolutions; j++)
{
if (solutionPublicationTicks[j] > 0
&& system.solutions[j].computorPublicKey == computorPublicKeys[i])
{
if (solutionPublicationTicks[j] <= (int)system.tick)
{
solutionIndexToPublish = j;
}
break;
}
}
if (j == system.numberOfSolutions)
{
for (j = 0; j < system.numberOfSolutions; j++)
{
if (!solutionPublicationTicks[j]
&& system.solutions[j].computorPublicKey == computorPublicKeys[i])
{
solutionIndexToPublish = j;
break;
}
}
}
if (solutionIndexToPublish >= 0)
{
struct
{
Transaction transaction;
m256i nonce;
unsigned char signature[SIGNATURE_SIZE];
} payload;
static_assert(sizeof(payload) == sizeof(Transaction) + 32 + SIGNATURE_SIZE, "Unexpected struct size!");
payload.transaction.sourcePublicKey = computorPublicKeys[i];
payload.transaction.destinationPublicKey = arbitratorPublicKey;
payload.transaction.amount = 0;
unsigned int random;
_rdrand32_step(&random);
solutionPublicationTicks[solutionIndexToPublish] = payload.transaction.tick = system.tick + MIN_MINING_SOLUTIONS_PUBLICATION_OFFSET + random % MIN_MINING_SOLUTIONS_PUBLICATION_OFFSET;
payload.transaction.inputType = 0;
payload.transaction.inputSize = sizeof(payload.nonce);
payload.nonce = system.solutions[solutionIndexToPublish].nonce;
unsigned char digest[32];
KangarooTwelve(&payload.transaction, sizeof(payload.transaction) + sizeof(payload.nonce), digest, sizeof(digest));
sign(computorSubseeds[i].m256i_u8, computorPublicKeys[i].m256i_u8, digest, payload.signature);
enqueueResponse(NULL, sizeof(payload), BROADCAST_TRANSACTION, 0, &payload);
}
creates a Transaction containing the solution.

Issue seems to be resolved. i will close it for now.