From 258ca9474f0b1287475327bcf53cc43e691d4671 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Wed, 15 Apr 2026 18:46:00 +0200 Subject: [PATCH] shorten transaction --- include/block/transaction.h | 1 - src/block/block.c | 4 +++- src/block/transaction.c | 11 ++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/block/transaction.h b/include/block/transaction.h index 4704bcc..db6c381 100644 --- a/include/block/transaction.h +++ b/include/block/transaction.h @@ -44,7 +44,6 @@ typedef struct { #pragma pack(pop) typedef struct { - uint8_t txHash[32]; uint8_t signature[64]; // Signature of the hash } transaction_sig_t; diff --git a/src/block/block.c b/src/block/block.c index f270c61..f1561cf 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -199,7 +199,9 @@ void Block_RemoveTransaction(block_t* block, uint8_t* txHash) { for (size_t i = 0; i < DynArr_size(block->transactions); i++) { signed_transaction_t* currentTx = (signed_transaction_t*)DynArr_at(block->transactions, i); - if (memcmp(currentTx->signature.txHash, txHash, 32) == 0) { + uint8_t currentTxHash[32]; + Transaction_CalculateHash(currentTx, currentTxHash); + if (memcmp(currentTxHash, txHash, 32) == 0) { DynArr_remove(block->transactions, i); return; } diff --git a/src/block/transaction.c b/src/block/transaction.c index 4c5eba0..929b3c6 100644 --- a/src/block/transaction.c +++ b/src/block/transaction.c @@ -26,9 +26,10 @@ void Transaction_Sign(signed_transaction_t* tx, const uint8_t* privateKey) { return; } - Transaction_CalculateHash(tx, tx->signature.txHash); + uint8_t txHash[32]; + Transaction_CalculateHash(tx, txHash); Crypto_SignData( - (const uint8_t*)&tx->transaction, + txHash, sizeof(transaction_t), privateKey, tx->signature.signature @@ -81,13 +82,9 @@ bool Transaction_Verify(const signed_transaction_t* tx) { uint8_t txHash[32]; Transaction_CalculateHash(tx, txHash); - if (memcmp(txHash, tx->signature.txHash, 32) != 0) { - return false; // Hash does not match signature hash - } - // If all checks pass, verify the signature return Crypto_VerifySignature( - (const uint8_t*)&tx->transaction, + txHash, sizeof(transaction_t), tx->signature.signature, tx->transaction.compressedPublicKey