transaction.rs - Transactions

The transaction module defines the fundamental value transfer mechanism in Bunkercoin, implementing Ed25519 digital signatures with deterministic nonce generation and Blake3 hashing for radio-optimized financial operations.

Transaction Structure

// src/transaction.rs (lines 4-13)
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Transaction {
    pub sender: Vec<u8>,        // Ed25519 public key
    pub recipient: Vec<u8>,     // Ed25519 public key  
    pub amount: u64,            // Amount in base units
    pub nonce: u64,             // Deterministic nonce
    pub signature: Vec<u8>,     // Ed25519 signature
}

Ed25519 Cryptographic Implementation

Digital Signature Verification

// src/transaction.rs (lines 15-23)
impl Transaction {
    pub fn verify(&self) -> bool {
        let pk = PublicKey::from_bytes(&self.sender).unwrap();
        let data = self.data_to_sign();
        let sig_bytes: [u8; 64] = self.signature.clone().try_into().expect("sig length");
        let sig = Signature::from_bytes(&sig_bytes).unwrap();
        pk.verify(&data, &sig).is_ok()
    }
}

Signing Data Generation

Ed25519 Advantages: Ed25519 provides 128-bit security equivalent with fast verification and small signature sizes (64 bytes), making it ideal for bandwidth-constrained radio transmissions while maintaining cryptographic strength.

Blake3 Transaction Hashing

The Blake3 hash function provides:

  • Deterministic hashing: Same transaction always produces same hash

  • Collision resistance: Cryptographically secure transaction identification

  • Fast computation: Optimized for low-power radio bridge environments

Deterministic Nonce System

Unlike Bitcoin's UTXO model, Bunkercoin uses a simplified account-based system with deterministic nonces:

Nonce Generation Strategy

Anti-Replay Protection

  • Sequential nonces: Each transaction must have the next expected nonce

  • State validation: Prevents double-spending through nonce verification

  • Deterministic ordering: Ensures consistent transaction processing across nodes

Transaction Lifecycle

1. Creation and Signing

2. Network Propagation

  • HTTP broadcast: POST /tx endpoint accepts individual transactions

  • Mempool injection: Transactions stored pending block inclusion

  • Peer synchronization: GET /mempool shares pending transactions

3. Block Inclusion

  • Deterministic ordering: Transactions sorted by hash for consistent blocks

  • Merkle root calculation: Blake3 hash of all transactions

  • Finalization: Transactions become immutable once included in blocks

Radio-Optimized Features

Compact Binary Format

JS8Call Compatibility

  • Single frame transmission: Most transactions fit in one 256-byte JS8Call frame

  • Error detection: Built-in checksums enable corruption detection

  • Human readable: JSON format allows manual verification during radio operations

Validation and Security

Cryptographic Validation Chain

Security Properties

Property
Implementation
Purpose

Authentication

Ed25519 signature verification

Proves transaction authorization

Integrity

Blake3 hash validation

Detects transmission corruption

Non-repudiation

Immutable blockchain storage

Prevents transaction denial

Replay protection

Sequential nonce system

Prevents transaction reuse

Error Handling and Recovery

Malformed Transaction Handling

Radio Transmission Errors

  • Checksum validation: JSON deserialization detects corruption

  • Signature verification: Cryptographic proof of integrity

  • Graceful degradation: Invalid transactions discarded without affecting system

  • Retransmission: Failed transactions can be rebroadcast by sender

Future Enhancements

Planned Transaction Features

  • Multi-signature support: m-of-n signature schemes for enhanced security

  • Smart contract integration: Programmable transaction conditions

  • Privacy enhancements: Zero-knowledge proofs for transaction privacy

  • UTXO migration: Transition to unspent transaction output model

Backward Compatibility

Transaction format extensions will maintain compatibility through:

  • Version fields: Enable protocol upgrades

  • Optional fields: New features added as optional extensions

  • Legacy support: Older transaction formats remain valid

Last updated