Skip to main content

Module hash

Module hash 

Source
Expand description

Content addressing for Trident: AST normalization + Poseidon2 hashing.

Every function definition gets a cryptographic identity (Poseidon2 hash) based on its normalized AST. Names are replaced with de Bruijn indices, dependency references are replaced with their hashes, and the result is deterministically serialized before hashing.

Uses Poseidon2 over the Goldilocks field for SNARK-friendly content addressing — content hashes are cheaply provable inside ZK proofs, enabling trustless compilation verification and on-chain registries.

Properties:

  • Two functions with identical computation but different variable names produce the same hash.
  • Changing any dependency changes the hash of all dependents.
  • Renaming a function does not change its hash.
  • Adding/removing comments or formatting does not change the hash.

Structs§

ContentHash
A 256-bit BLAKE3 content hash.
Normalizer
Normalize and serialize a function definition to bytes.

Functions§

hash_file
Hash all functions in a file, returning name → hash map.
hash_file_content
Hash a complete file’s content (all items serialized together). Uses Poseidon2 for SNARK-friendly file-level content addressing.
hash_function
Hash a single function.