<!-- markdownlint-disable MD060 -->

# Green Standards Overview (CX337-CX341)

**Green standards** are CarbonX3 **reporting and attestation** contracts: CBAM proofs, sustainability disclosures, supply-chain records, materiality assessments and green claims. Since contract version **3.0-L2** they share one shape: the records live on **L2**, the contract on **L1** keeps what L1 must enforce.

Records live on the tenant's **CX3EvidenceLedger** (L2): each one is issuer-signed, Merkle-batched and anchored to Green Chain through **L2Anchor**. The contract is the template the L2 follows: the L2 asks `canWrite(issuer, kind)` before it seals a record, and its sealer closes epochs with `finalizeEpoch`. L1 state grows by one commitment per epoch plus a few keys per decision, never per record.

| Kept on L1 (contract) | Kept on L2 (CX3EvidenceLedger) |
|-----|--------|
| Rules (`getRules`), roles (`canWrite`), independence checks | Every record: proof, datapoint, hand-off, topic, vote, claim |
| One commitment per epoch: Merkle root, record count, L2 sequence range, totals | Merkle batches, inclusion proofs, epoch datasets |
| Sparse decisions: attestation, revocation, claim verification, challenges | Issuer signatures and sequence numbers |

A record is checked on L1 with the proof the L2 serves (`GET /l2/standard-proof/:id`): the contract recomputes the root with the built-in `merkleVerify` and compares it with the epoch's root. Per-record decisions are keyed by `recordKey(epochId, index)`, the record's position, so a differently written hash cannot dodge them.

All Green templates are **`@target(CX3WASM)`**; the deploy path forces WASM for CX337-CX341. The wizard's editor text and the chain's server-side template (deploy without `sourceCode`) are the same source. A separate, illustrative compiler test suite (`test/green-standards.test.js` in the `cx3script` package) keeps minimal compile-checked variants and is **not the WASM wizard** template.

> **Note:** Green standard tags are **protocol / metadata labels** for reporting and attestation workflows. They are **not** ISO, CBAM, ESRS or other authority-issued records, legal guarantees, accredited verification, legal opinion or authority approval by themselves.

---

## Standard Map

| Tag | L2 domain | Epoch totals | Decisions on L1 | Example doc |
|-----|-----------|--------------|-----------------|-------------|
| **@CX337** | `cx337` | Scope 1 / Scope 2 kg CO2e | verifier attestation, revoked proofs | **Example: CX337 (excerpt)** |
| **@CX338** | `cx338` | - | published disclosure, assurance, ESG scores | **Example: CX338 sustainability (deploy)** |
| **@CX339** | `cx339` | Scope 3 kg CO2e, suppliers | attestation with coverage, revoked records | **Example: CX339 supply chain (deploy)** |
| **@CX340** | `cx340` | topics, votes | result hash, governance&nbsp;approval | **Example: CX340 materiality (deploy)** |
| **@CX341** | `cx341` | - | verified / rejected / revoked claims, challenges | **Example: CX341 green claims (deploy)** |

---

## Shared L2 Core (from the CX337 template)

```cxs
    // What the L2 needs to close the next epoch
    @view
    getL2Binding() -> (string, string, uint256, uint256, uint256, uint256) {
        return (l2Domain, l2ChainId, lastEpoch, lastSequence, lastEpochClosedAt, minEpochInterval)
    }

    // Is recordHash leaf number index of the epoch? The L2 serves the proof
    // (GET /l2/standard-proof/:evidenceId); siblings are comma-separated hashes.
    @view
    verifyRecord(epochId: uint256, recordHash: string, siblings: string, index: uint256) -> bool {
        if epochClosedAt[epochId] == 0 { return false }
        if index >= epochRecords[epochId] { return false }
        return merkleVerify(recordHash, siblings, index, epochRecords[epochId], epochRoot[epochId])
    }

    // Position of a record: the key of per-record decisions (a hex string is not canonical)
    @view
    recordKey(epochId: uint256, index: uint256) -> uint256 {
        return epochId * 4294967296 + index
    }

    // The L2 sealer closes an epoch: the records of this domain sealed in the
    // L2 sequence range, already inside an L2 batch anchored on L2Anchor.
    @onlyNotary
    @audit
    finalizeEpoch(epochId: uint256, root: string, records: uint256, fromSeq: uint256, toSeq: uint256, l2Batch: uint256, dataUri: string, directTotal: uint256, indirectTotal: uint256) {
        require !paused, "CONTRACT_PAUSED"
        require epochId == lastEpoch + 1, "INVALID_EPOCH"
        require records > 0, "EMPTY_EPOCH"
        require lastEpoch == 0 || fromSeq == lastSequence + 1, "SEQUENCE_GAP"
        require toSeq >= fromSeq, "INVALID_RANGE"
        require records <= toSeq - fromSeq + 1, "TOO_MANY_RECORDS"
        require isHash(root), "INVALID_ROOT"
        require lastEpochClosedAt == 0 || block.timestamp >= lastEpochClosedAt + minEpochInterval, "EPOCH_TOO_EARLY"
        // CBAM scope rule on the epoch totals (the L2 applies it to every record)
        if emissionScope == "DIRECT_ONLY" {
            require indirectTotal == 0, "INDIRECT_NOT_ALLOWED_FOR_SECTOR"
        }
        epochRoot[epochId] = root
        epochRecords[epochId] = records
        epochFromSeq[epochId] = fromSeq
        epochToSeq[epochId] = toSeq
        epochL2Batch[epochId] = l2Batch
        epochDataUri[epochId] = dataUri
        epochClosedAt[epochId] = block.timestamp
        epochDirectEmissions[epochId] = directTotal
        totalDirectEmissions += directTotal
        epochIndirectEmissions[epochId] = indirectTotal
        totalIndirectEmissions += indirectTotal

        lastEpoch = epochId
        lastSequence = toSeq
        lastEpochClosedAt = block.timestamp
        totalRecords += records

        emit EpochFinalized(epochId, root, records, fromSeq, toSeq)
    }
```

---

## Related

- **Deploy-Time CX3Script** - wizard overview and `examples/` catalogue.
- **Compile Targets** - **CX3WASM** for Green builds.
- CX3EvidenceLedger `docs/README.md` - binding a contract to an L2 (`standards` in the tenant profile) and the `/l2/standard-*` endpoints.
