Transaction and Block Validation
The validation module provides comprehensive validation rules for transactions and blocks according to consensus rules. It performs format checks, state checks, and structural validation.Transaction Validation
TransactionValidator
Validator for transaction format, signature, and state checks.Methods
validate_transaction(tx: &Transaction) -> Result<()>
Basic transaction validation (format and gas checks).
Note: This does NOT verify the signature since Ed25519 requires the public key which must be obtained from the blockchain state. Use validate_with_signature for full validation including signature.
Validation checks:
- Gas price must be non-zero
- Gas limit must meet minimum requirements:
- Transfer: 21,000 minimum
- Contract call: 21,000 + (calldata length × 68)
- Contract deployment: 21,000 minimum
- Contract deployments must have non-empty bytecode
validate_with_signature(tx: &Transaction, public_key: &PublicKey) -> Result<()>
Validates transaction with signature verification.
The transaction to validate
The sender’s public key for signature verification
validate_against_state(tx: &Transaction, sender_nonce: u64, sender_balance: u64) -> Result<()>
Validates transaction against account state.
The transaction to validate
The sender’s current nonce from state
The sender’s current balance from state
- Transaction nonce must match sender’s current nonce
- Sender balance must cover
value + (gas_limit × gas_price)
validate_full(tx: &Transaction, public_key: &PublicKey, sender_nonce: u64, sender_balance: u64) -> Result<()>
Full transaction validation (signature + format + state checks).
Block Validation
BlockValidator
Validator for block structure, parent linkage, and transaction contents.Methods
validate_block_structure(block: &Block) -> Result<()>
Validates block structure and contents.
Validation checks:
- Merkle root matches transaction hashes
- No duplicate transactions in the block
- Block format is correct
validate_block_extends_parent(block: &Block, parent_hash: Hash, parent_height: u64) -> Result<()>
Validates that a block correctly extends its parent.
The block to validate
The parent block’s hash
The parent block’s height
- Block height is parent height + 1
- Block’s
prev_hashmatches parent hash
validate_block_transactions(block: &Block) -> Result<()>
Validates all transactions in the block (format only, not signatures).
Note: This does NOT verify transaction signatures since that requires public keys from the blockchain state. Signature verification should be done during transaction execution.
validate_full(block: &Block, parent_hash: Hash, parent_height: u64) -> Result<()>
Full block validation (structure + parent + transactions).
Errors
ValidationError
Errors that can occur during validation.Transaction signature verification failed.
Transaction nonce doesn’t match sender’s current nonce.
Sender has insufficient balance to cover transaction cost.
Transaction gas limit is below the required minimum.
Transaction has zero gas price (not allowed).
Contract deployment transaction has no bytecode.
Block height doesn’t correctly extend parent.
Block’s prev_hash doesn’t match parent hash.
Block merkle root verification failed.
Block contains duplicate transactions.
Transaction hash doesn’t match computed hash.
Block contains no transactions and is not genesis.
Gas Calculation
Minimum Gas Requirements
Transactions must meet minimum gas limits based on their type:Maximum Transaction Cost
The maximum cost of a transaction includes both the value transfer and gas fees:max_cost balance to send the transaction.
Complete Example
Transaction Validation
Block Validation
Validation Pipeline
Transaction Processing
- Format Validation: Check gas price, gas limit, deployment data
- Signature Validation: Verify cryptographic signature
- State Validation: Check nonce and balance
- Execution: Execute transaction and update state
Block Processing
- Structure Validation: Merkle root, duplicates
- Parent Validation: Height, prev_hash
- Transaction Validation: Format of all transactions
- Consensus Validation: Authority, signature, timestamp (from PoA module)
- State Execution: Execute all transactions