🌱 Carbon & Compliance — 6.4
Developer HubModule 6: Carbon & Compliance6.4
Reading15 min

Hash-Chained Attestation (SHA-256)

🌱 Module 6: Carbon & Compliance

Hash-Chained Attestation (SHA-256)

Hash-chained attestation creates a tamper-evident record of carbon accounting data. Each record is cryptographically linked to the previous one, forming an immutable chain similar to blockchain but without the distributed consensus overhead.

Why Hash Chains?

Carbon accounting data is used for:

  • Regulatory compliance (DEWA, EU ETS, SEC climate disclosure)
  • Financial transactions (carbon credits, RECs, VPPAs)
  • Reputation (ESG ratings, sustainability reports)

If this data can be silently altered after the fact (changing an emission factor, modifying a meter reading), the entire carbon accounting system loses credibility. Hash chains make any modification detectable.

SHA-256 Fundamentals

SHA-256 (Secure Hash Algorithm, 256-bit) produces a fixed 256-bit (32-byte) hash from any input:

SHA-256("Hello, World!") = dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f

Key properties:

  • Deterministic: Same input always produces the same hash
  • One-way: Cannot reconstruct the input from the hash
  • Avalanche effect: A single-bit change in input completely changes the hash
  • Collision resistant: Computationally infeasible to find two different inputs with the same hash

Building the Chain

Each carbon record includes a hash of the previous record, creating a chain:

Record 1:
  data: { facility: "DC-1", period: "2026-02-01T00:00Z", emissions_kg: 4200, ... }
  prev_hash: "0000...0000"  (genesis record)
  hash: SHA-256(data + prev_hash) = "a1b2c3..."

Record 2:
  data: { facility: "DC-1", period: "2026-02-01T01:00Z", emissions_kg: 4150, ... }
  prev_hash: "a1b2c3..."  (hash of Record 1)
  hash: SHA-256(data + prev_hash) = "d4e5f6..."

Record 3:
  data: { facility: "DC-1", period: "2026-02-01T02:00Z", emissions_kg: 3900, ... }
  prev_hash: "d4e5f6..."  (hash of Record 2)
  hash: SHA-256(data + prev_hash) = "g7h8i9..."

Tamper Detection

If someone modifies Record 2's data (e.g., changing emissions from 4150 to 3000):

  1. Record 2's hash changes (because the data changed)
  2. Record 3's prev_hash no longer matches Record 2's new hash
  3. The chain is broken -- the modification is immediately detectable

To hide the modification, the attacker would need to recalculate the hashes of Record 2, Record 3, and every subsequent record. If the latest hash is published to an external witness (a timestamp authority, a public ledger, or multiple independent parties), even this is detectable.

Implementation

import { createHash } from 'crypto';

interface CarbonRecord {
  facilityId: string;
  periodStart: string;
  periodEnd: string;
  energyKwh: number;
  emissionsKg: number;
  emissionFactor: number;
  source: string;
  prevHash: string;
  hash: string;
}

function computeHash(record: Omit<CarbonRecord, 'hash'>): string {
  const payload = JSON.stringify({
    facilityId: record.facilityId,
    periodStart: record.periodStart,
    periodEnd: record.periodEnd,
    energyKwh: record.energyKwh,
    emissionsKg: record.emissionsKg,
    emissionFactor: record.emissionFactor,
    source: record.source,
    prevHash: record.prevHash,
  });
  return createHash('sha256').update(payload).digest('hex');
}

function verifyChain(records: CarbonRecord[]): boolean {
  for (let i = 0; i < records.length; i++) {
    const expected = computeHash(records[i]);
    if (expected !== records[i].hash) return false;
    if (i > 0 && records[i].prevHash !== records[i - 1].hash) return false;
  }
  return true;
}

Anchoring to External Witnesses

For maximum tamper-evidence, periodically publish the latest chain hash to external systems:

  • Timestamping authorities (RFC 3161): A trusted third party signs your hash with a timestamp
  • Public blockchains: Write the hash to Ethereum or Bitcoin (costs a few dollars per transaction)
  • Multiple independent databases: Store hashes at two or more independent organizations

If the latest hash is anchored externally, an attacker cannot rewrite history without detection, even if they have full control of the internal database.

Compliance Applications

  • EU ETS MRV (Monitoring, Reporting, Verification): Hash chains provide an auditable trail from meter reading to reported emissions
  • SEC Climate Disclosure: Tamper-evident records support the assurance requirements
  • Voluntary carbon markets: Hash chains can link carbon credits to specific generation records, preventing double-counting

Log in to track your progress and earn certifications.