Skip to content
Last updated: March 11, 2025

SCWE-026: Insufficient Hash Verification

Stable Version v0.0.1

This content is in the version-(v0.0.1) and still under active development, so it is subject to change any time (e.g. structure, IDs, content, URLs, etc.).

Send Feedback

Relationships

  • CWE-347: Improper Verification of Cryptographic Signature
    CWE-347 Link

Description

Insufficient hash verification refers to the failure to properly verify hashes, such as message hashes or transaction hashes. This can lead to: - Unauthorized actions by malicious actors. - Loss of funds or data. - Exploitation of the contract's logic.

Remediation

  • Validate hashes: Ensure all hashes are properly verified before processing.
  • Use secure libraries: Leverage well-audited libraries for hash verification.
  • Test thoroughly: Conduct extensive testing to ensure hash verification works as intended.

Examples

  • Insufficient Hash Verification

    pragma solidity ^0.8.0;
    
    contract InsufficientHashVerification {
        function processHash(bytes32 hash) public {
            // Process hash without verification
        }
    }
    

  • Sufficient Hash Verification

    pragma solidity ^0.8.0;
    
    contract SufficientHashVerification {
        function processHash(bytes32 hash, bytes memory data) public {
            require(keccak256(data) == hash, "Invalid hash");
            // Process hash
        }
    }