· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·

Blake3 Hashing

Blake3 Merkle Tree
Architecture / Hashing

Blake3 Deep Dive

Astral uses Blake3 as its cryptographic hash function. This document explores why we chose Blake3 and how it's integrated into Astral's architecture.


Why Blake3?

14 GB/s

Hashing speed on modern hardware (AVX2), compared to ~2 GB/s for SHA-256.

256-bit

Security level. Provides the same security margin as SHA-256.

Key Properties

  1. Speed: Blake3 is designed from the ground up for performance on modern CPUs
  2. Parallelism: The Merkle tree structure enables multi-core hashing
  3. Security: Based on the well-analyzed Blake2 and ChaCha primitives
  4. Versatility: Can be used as a hash, MAC, KDF, and PRF

The Merkle Tree Structure

Unlike traditional hash functions that process data sequentially, Blake3 uses a Merkle tree internally:

Blake3 Merkle Tree
Root Hash
H1
H2
H1a
H1b
H2a
H2b
1KB
1KB
1KB
1KB
1KB
1KB
1KB
1KB

Each chunk (1 KB) can be hashed independently

Benefits for Astral

  • Parallel hashing: Large files can be hashed across multiple cores
  • Incremental updates: Only changed chunks need rehashing
  • Streaming: No need to buffer the entire file in memory
  • Verified streaming: Can verify chunks as they arrive

Benchmarks

Performance comparison on AMD Ryzen 9 (16 cores):

File: 1 GB random data
Blake3 (16 threads)14.0 GB/s
Blake3 (4 threads)7.8 GB/s
Blake3 (1 thread)4.2 GB/s
SHA-2562.0 GB/s

Implementation

Astral uses the official Blake3 Go implementation:

import "github.com/zeebo/blake3"

func HashObject(content []byte) [32]byte {
    return blake3.Sum256(content)
}

// For large files, use streaming:
func HashFile(path string) ([32]byte, error) {
    f, err := os.Open(path)
    if err != nil {
        return [32]byte{}, err
    }
    defer f.Close()
    
    h := blake3.New()
    if _, err := io.Copy(h, f); err != nil {
        return [32]byte{}, err
    }
    
    var hash [32]byte
    h.Sum(hash[:0])
    return hash, nil
}

SIMD Optimization

The implementation automatically uses:

  • AVX-512 on supported Intel/AMD processors
  • AVX2 on most modern x86-64 CPUs
  • NEON on ARM64 (Apple Silicon, AWS Graviton)
  • Pure Go fallback for other architectures

Security Considerations

Blake3's security properties:

| Property | Status | | :--- | :--- | | Collision Resistance | 128-bit (birthday bound) | | Preimage Resistance | 256-bit | | Second Preimage Resistance | 256-bit | | Length Extension | Immune (due to tree construction) |

Note on Cryptographic Proofs

While Blake3 is newer than SHA-256, its core compression function is derived from Blake2 (analyzed since 2012) and ChaCha (analyzed since 2008), both with extensive cryptographic review.


Next Steps

└─── End of Document ───┘