code cleanup

Signed-off-by: RubenCGomes <rlcg@ua.pt>
This commit is contained in:
RubenCGomes 2025-11-28 23:30:36 +00:00
parent c712f2a431
commit cc3fb6db0b
No known key found for this signature in database
GPG Key ID: 0D213021197E3EE0
1 changed files with 5 additions and 23 deletions

View File

@ -17,15 +17,8 @@ void mine_deti_coins_kernel(u32_t *coins_storage_area, u64_t base_nonce, u32_t a
u32_t hash[5]; u32_t hash[5];
// 1. Initialize Fixed Prefix: "DETI coin 2 " (12 bytes) // 1. Initialize Fixed Prefix: "DETI coin 2 " (12 bytes)
// We construct this directly into the u32 array.
// Note: We assume the system is Little Endian, but SHA1 input via macro usually handles bytes.
// Ideally, we pack bytes: 'D','E','T','I' -> 0x44455449
// Word 0: "DETI"
coin[0] = (u32_t)'D' << 24 | (u32_t)'E' << 16 | (u32_t)'T' << 8 | (u32_t)'I'; coin[0] = (u32_t)'D' << 24 | (u32_t)'E' << 16 | (u32_t)'T' << 8 | (u32_t)'I';
// Word 1: " coi"
coin[1] = (u32_t)' ' << 24 | (u32_t)'c' << 16 | (u32_t)'o' << 8 | (u32_t)'i'; coin[1] = (u32_t)' ' << 24 | (u32_t)'c' << 16 | (u32_t)'o' << 8 | (u32_t)'i';
// Word 2: "n 2 "
coin[2] = (u32_t)'n' << 24 | (u32_t)' ' << 16 | (u32_t)'2' << 8 | (u32_t)' '; coin[2] = (u32_t)'n' << 24 | (u32_t)' ' << 16 | (u32_t)'2' << 8 | (u32_t)' ';
// 2. Initialize Variable Part (Bytes 12 to 53) // 2. Initialize Variable Part (Bytes 12 to 53)
@ -45,18 +38,15 @@ void mine_deti_coins_kernel(u32_t *coins_storage_area, u64_t base_nonce, u32_t a
coin[15] = 440; coin[15] = 440;
// 4. Thread Unique Initialization // 4. Thread Unique Initialization
// We use the thread ID to set the initial state of the variable bytes // Uses thread ID to set the initial state of the variable bytes
// to ensure every thread starts at a different point. // to ensure every thread starts at a different point.
u64_t thread_id = (u64_t)blockIdx.x * blockDim.x + threadIdx.x; u64_t thread_id = (u64_t)blockIdx.x * blockDim.x + threadIdx.x;
u64_t nonce_offset = base_nonce + thread_id * attempts_per_thread; u64_t nonce_offset = base_nonce + thread_id * attempts_per_thread;
// "Seeding" the message with the nonce (Fast update of specific bytes) // Seeding the message with the nonce (Fast update of specific bytes)
// We modify the bytes in words 3 through 12.
// Accessing as byte pointer for easier manipulation
u08_t *byte_ptr = (u08_t*)coin; u08_t *byte_ptr = (u08_t*)coin;
// Apply the nonce offset to the message structure (Odometer setup) // Apply the nonce offset to the message structure
// Start modifying from byte 12
u64_t temp_nonce = nonce_offset; u64_t temp_nonce = nonce_offset;
for (int k = 12; k < 54 && temp_nonce > 0; k++) { for (int k = 12; k < 54 && temp_nonce > 0; k++) {
u32_t val = byte_ptr[k ^ 3] + (temp_nonce % 95); // mod 95 to stay in printable ASCII u32_t val = byte_ptr[k ^ 3] + (temp_nonce % 95); // mod 95 to stay in printable ASCII
@ -108,9 +98,7 @@ void mine_deti_coins_kernel(u32_t *coins_storage_area, u64_t base_nonce, u32_t a
// --- UPDATE MESSAGE (ODOMETER) --- // --- UPDATE MESSAGE (ODOMETER) ---
// Increment the message string for the next attempt // Increment the message string for the next attempt
// We only touch the variable bytes.
// Start at byte 53 (just before the \n) and work backwards if carry needed. // Start at byte 53 (just before the \n) and work backwards if carry needed.
// Note: byte_ptr access needs XOR 3 for Endianness correction on arrays treated as words
int pos = 53; int pos = 53;
while (pos >= 12) { while (pos >= 12) {
@ -136,17 +124,13 @@ void mine_visual_row_kernel(u32_t *coins_storage_area, u32_t *row_template, u64_
u32_t coin[16]; // SHA1 working buffer u32_t coin[16]; // SHA1 working buffer
u32_t hash[5]; u32_t hash[5];
// 1. Load the template (Fixed Visual Part) // 1. Load the template
// The host has already prepared "DETI coin 2 " + "The DNA Pattern"
// We copy the first 12 words (48 bytes) exactly as they are.
#pragma unroll #pragma unroll
for(int i = 0; i < 12; i++) { for(int i = 0; i < 12; i++) {
coin[i] = row_template[i]; coin[i] = row_template[i];
} }
// 2. Setup the "Mining Area" (Bytes 48-53) // 2. Setup the "Mining Area" (Bytes 48-53)
// We use word 12 and part of word 13 for the nonce.
// Word 13 also contains the \n and 0x80 padding.
// Template provided by host: [ ... visual ... ] [ mining_space ] \n 0x80 // Template provided by host: [ ... visual ... ] [ mining_space ] \n 0x80
coin[12] = 0x41414141; // Initialize mining space with 'AAAA' coin[12] = 0x41414141; // Initialize mining space with 'AAAA'
@ -161,11 +145,9 @@ void mine_visual_row_kernel(u32_t *coins_storage_area, u32_t *row_template, u64_
u64_t nonce = base_nonce + thread_id; // Simple linear nonce u64_t nonce = base_nonce + thread_id; // Simple linear nonce
// 4. Map nonce to the "Mining Area" (Bytes 48-53) // 4. Map nonce to the "Mining Area" (Bytes 48-53)
// We manipulate bytes 48, 49, 50, 51 (Word 12) and 52, 53 (Low half of Word 13) // Change bytes from 48 to 53
u08_t *bytes = (u08_t*)coin; u08_t *bytes = (u08_t*)coin;
// We use an Odometer approach on the specific bytes allowed for mining
// so we don't disturb the beautiful visual pattern on the left.
u64_t temp_nonce = nonce; u64_t temp_nonce = nonce;
for(int k = 48; k <= 53; k++) for(int k = 48; k <= 53; k++)
{ {