The Bridge
Decoupling STARK hash functions from the proving logic.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Bridge
ARCANUM SCHOOL: Conjuration // Connection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CAIRO PATTERN //
trait IHashAlgo<T> { fn hash(self: @T, data: felt252) -> felt252; }
#[derive(Copy, Drop)]
struct PoseidonHash {}
impl PoseidonImpl of IHashAlgo<PoseidonHash> {
fn hash(self: @PoseidonHash, data: felt252) -> felt252 { data + 1 }
}
#[derive(Copy, Drop)]
struct Prover<T> { hasher: T }
trait IProver<T> { fn prove(self: @Prover<T>, data: felt252) -> felt252; }
impl ProverImpl<T, +IHashAlgo<T>> of IProver<T> {
fn prove(self: @Prover<T>, data: felt252) -> felt252 {
self.hasher.hash(data)
}
}
Separates the mystical hash algorithm from the prover’s structure, allowing both to evolve independently.
Runic Tags:
#cairo
#design-pattern
#bridge