Repository navigation
feat(contracts): add TOKEN — fixed-supply ERC20 with permit and burnable - #635
Merged
Merged
Conversation
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]>
There was a problem hiding this comment.
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]>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_SUPPLYconstant). 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)
TOTAL_SUPPLYis a compile-time constant (1_000_000_000e18), not a constructor argument. The "supply is exactly 1B" guarantee is enforced at compile time.Ownablemint authority, no publicmint()function, no upgrade hook. A test asserts the absence by low-level call.ERC20Votes(see ADR alignment below).Inheritance, per ADR 016 § Contract Inventory (also updated in this PR)
ERC20+ERC20Burnableburn/burnFrom, consumed by the slashing path's 20% burn leg (ADR 026 § Slashing and burn)ERC20PermitStakingRegistry.stakeandVotingEscrow.createLockso users can sign approval + state-changing call as a single user op (ADR 024)ADR alignment: dropping
ERC20VotesADR 026 § Governance is explicit that the governance vote source is
VotingEscrow.balanceOfAt, notTOKEN.getPastVotes:Inheriting
ERC20Voteswas paying ~2× transfer gas and adding ~10 public functions to the audit perimeter for a checkpoint stream thatDecdnGovernornever reads.This PR also updates ADR 016:
ERC20 + ERC20Burnable + ERC20Permit, with explicit pointer to ADR 026's voting decisionERC20Burnableto 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/Checkpointscode.Tests (10 unit + 1 fuzz, all passing under
FOUNDRY_PROFILE=ci)TOTAL_SUPPLYconstant matchestotalSupply()mint(address,uint256)reverts;totalSupplystays constantdelegate,getVotes,getPastVotes,delegates,getPastTotalSupply) all revert — locks the ADR 026 voting decision against accidental future re-addition ofERC20VotestotalSupply; fuzz over[0, balance];burnFromconsumes allowanceOut 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 --checkcleanFOUNDRY_PROFILE=ci forge build --sizesclean (Token = 3,952 bytes runtime)FOUNDRY_PROFILE=ci forge test— 10/10 passingsolidityjob greenci-successaggregator greenRefs: #452