Skip to content

feat(contracts): add TOKEN — fixed-supply ERC20 with permit and burnable - #635

Merged
alpergundogdu merged 2 commits into
mainfrom
feat/contracts-token
May 21, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
feat/contracts-token

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

First contract from the 14-contract surface tracked in #452. TOKEN is pure OZ v5 composition — the entirety of the deCDN-specific custom Solidity is 5 lines (a constructor + a zero-holder revert + a TOTAL_SUPPLY constant). No multi-inheritance overrides; no business logic.

This follows the principle from #237: inherit from audited OpenZeppelin v5 bases, limit custom Solidity to deCDN-specific business logic. TOKEN has no business logic — it's a fixed-supply token — so the custom surface is essentially the constructor.

Audit surface (intentionally tiny)

  1. TOTAL_SUPPLY is a compile-time constant (1_000_000_000e18), not a constructor argument. The "supply is exactly 1B" guarantee is enforced at compile time.
  2. No mint path post-genesis. No Ownable mint authority, no public mint() function, no upgrade hook. A test asserts the absence by low-level call.
  3. No ERC20Votes (see ADR alignment below).

Inheritance, per ADR 016 § Contract Inventory (also updated in this PR)

Base Purpose
ERC20 + ERC20Burnable base + burn / burnFrom, consumed by the slashing path's 20% burn leg (ADR 026 § Slashing and burn)
ERC20Permit EIP-2612 gasless approvals. Used by StakingRegistry.stake and VotingEscrow.createLock so users can sign approval + state-changing call as a single user op (ADR 024)

ADR alignment: dropping ERC20Votes

ADR 026 § Governance is explicit that the governance vote source is VotingEscrow.balanceOfAt, not TOKEN.getPastVotes:

Voting source: VotingEscrow.balanceOfAt (was TOKEN.getPastVotes)

Inheriting ERC20Votes was paying ~2× transfer gas and adding ~10 public functions to the audit perimeter for a checkpoint stream that DecdnGovernor never reads.

This PR also updates ADR 016:

  • TOKEN inventory row corrected to ERC20 + ERC20Burnable + ERC20Permit, with explicit pointer to ADR 026's voting decision
  • Adds ERC20Burnable to both ADR 016 mentions of TOKEN (was missing despite ADR 026 line 31 requiring it)

Net effect: runtime size 7,661 → 3,952 bytes (~48% smaller); transfer gas roughly halved; audit surface shrinks by the ~150 LoC of OZ Votes / Checkpoints code.

Tests (10 unit + 1 fuzz, all passing under FOUNDRY_PROFILE=ci)

  • Constructor: mints full supply; reverts on zero holder; metadata sane
  • Supply invariant: TOTAL_SUPPLY constant matches totalSupply()
  • No mint path: low-level call to mint(address,uint256) reverts; totalSupply stays constant
  • No votes surface: 5 selector probes (delegate, getVotes, getPastVotes, delegates, getPastTotalSupply) all revert — locks the ADR 026 voting decision against accidental future re-addition of ERC20Votes
  • Burn: reduces totalSupply; fuzz over [0, balance]; burnFrom consumes allowance
  • Permit: EIP-2612 signed approval sets allowance, increments nonce

Out of scope

This PR is TOKEN only. StakingRegistry is the next PR — the ed25519 + EIP-712 signature work, the slash redirect via SafetyReserve.recordSlashInflow, and the auto-ejection path are review-heavy and don't belong in the same diff as the trivial composition above.

Test plan

  • forge fmt --check clean
  • FOUNDRY_PROFILE=ci forge build --sizes clean (Token = 3,952 bytes runtime)
  • FOUNDRY_PROFILE=ci forge test — 10/10 passing
  • CI solidity job green
  • CI ci-success aggregator green

Refs: #452

First contract from the 14-contract surface tracked in #452. TOKEN is
pure OZ v5 composition — the only custom Solidity is the constructor
and two multi-inheritance override stubs. Audit surface for this
contract is intentionally minimal:

  1. TOTAL_SUPPLY is a compile-time constant (1_000_000_000e18) — not
     a constructor argument — so the "supply is exactly 1B" guarantee
     is enforced at compile time, not at deploy time.
  2. The constructor mints the full supply to `initialHolder` and
     reverts on `address(0)`. No `Ownable` mint authority, no public
     `mint()` function, no upgrade hook.
  3. The two override stubs (`_update`, `nonces`) forward to `super`
     and add no logic — they exist solely to resolve the C3
     linearization across ERC20 + ERC20Votes + Nonces.

Inheritance per ADR 016 § Contract Inventory:
  - ERC20 + ERC20Burnable: base + burn/burnFrom, consumed by the
    slashing path's 20% burn leg (ADR 026 § Slashing and burn)
  - ERC20Permit: EIP-2612 gasless approvals; AA/ERC-4337 path
    (ADR 024)
  - ERC20Votes: per-address vote checkpoints. Governor reads weight
    from VotingEscrow.balanceOfAt, not from this contract; retained
    because ADR 016's inventory lists it and storage cost is bounded.

Tests (12 unit + 1 fuzz, all passing under FOUNDRY_PROFILE=ci):
  - Constructor: mints full supply; reverts on zero holder; metadata
  - Supply: TOTAL_SUPPLY constant matches totalSupply()
  - No mint path: low-level call to mint(address,uint256) reverts and
    totalSupply stays constant (locks the audit guarantee against
    accidental future addition of a mint function)
  - Burn: reduces totalSupply; fuzz over [0, balance]; burnFrom
    consumes allowance
  - Permit: EIP-2612 signed approval sets allowance, increments nonce
  - Votes: zero before delegation; self-delegate sets weight;
    transfer reallocates checkpoints

Drops Sanity.t.sol — that smoke test was scaffold-only, planned to
go away when the first real contract landed.

Refs: #452

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the Token contract, a fixed-supply ERC20 implementation for the deCDN governance and staking token. It leverages OpenZeppelin's standard extensions for burning, EIP-2612 permits, and voting checkpoints. The entire supply of 1 billion tokens is minted to a specified holder upon deployment, with no further minting possible. Comprehensive tests are included to verify construction, metadata, burn mechanics, permit logic, and voting behavior. I have no feedback to provide as there were no review comments to evaluate.

… ADR 026

ADR 026 § Governance is the canonical voting-source decision:

    Voting source: VotingEscrow.balanceOfAt (was TOKEN.getPastVotes)

So `DecdnGovernor` never calls `TOKEN.getPastVotes`. Inheriting
`ERC20Votes` was paying ~2× gas on every transfer and adding ~10
public functions to the audit perimeter for a checkpoint stream
that no contract reads.

Changes:
- Token.sol: drop ERC20Votes + the Nonces multi-inheritance override.
  Both override stubs (_update, nonces) collapse — ERC20Permit's
  Nonces is now the only Nonces user, so no diamond to resolve.
- Token.t.sol: drop the three vote tests; replace with a single
  selector probe that locks the absence of `delegate` / `getVotes` /
  `getPastVotes` / `delegates` / `getPastTotalSupply` against
  accidental future re-addition.
- ADR 016 § Contract Inventory (line 22): TOKEN row corrected.
  - Add ERC20Burnable (was missing despite ADR 026 line 31 requiring
    it for the slashing-path burn leg).
  - Drop ERC20Votes with explicit pointer to ADR 026 § Voting weight =
    ve-balance for the rationale.
- ADR 016 § OZ base contracts table (line 787): same correction.

Net effect on Token: runtime size 7,661 → 3,952 bytes (~48%
smaller); transfer gas roughly halved; audit surface shrinks by
the ERC20Votes contract (~150 LoC of OZ Votes/Checkpoints code).

Refs: #452

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu alpergundogdu changed the title feat(contracts): TOKEN — fixed-supply ERC20 with permit, votes, burnable feat(contracts): add TOKEN — fixed-supply ERC20 with permit and burnable May 21, 2026
@alpergundogdu
alpergundogdu merged commit 878e395 into main May 21, 2026
13 of 14 checks passed
@alpergundogdu
alpergundogdu deleted the feat/contracts-token branch May 21, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant