Skip to content

feat: Add ERC-20/721/1155 standard compliance checker rule set #11

Description

@Nanle-code

Overview

Incorrect implementation of ERC token standards is a major source of integration bugs and security vulnerabilities in the ecosystem. Missing return values, wrong event signatures, incorrect interface implementation, and missing reentrancy guards on ERC-777 hooks have caused significant losses. ChainProof should have a dedicated rule set for validating ERC standard compliance.

Standards to Cover

ERC-20 Compliance (CP-ERC20)

  • Missing return value on transfer/transferFrom — ERC-20 spec requires a bool return; some tokens omit it, breaking integrators
  • Missing Transfer and Approval events — integrators and indexers rely on these
  • Non-standard decimalsdecimals() should return uint8, not uint256
  • approve race condition — flagging direct approve without a increaseAllowance / decreaseAllowance pattern

ERC-721 Compliance (CP-ERC721)

  • Missing safeTransferFrom reentrancy guard — ERC-721 calls onERC721Received on the recipient which creates a reentrancy vector
  • Missing supportsInterface implementation — required by ERC-165
  • Unrestricted minting_mint callable without access control

ERC-1155 Compliance (CP-ERC1155)

  • Missing TransferSingle/TransferBatch events
  • Missing onERC1155Received reentrancy consideration

Detection Strategy

  1. Detect which ERC standard a contract implements via interface detection (function signature heuristic)
  2. Once standard is detected, apply the corresponding compliance rule set
  3. Flag deviations as findings with severity scaled to exploit impact
// packages/core/src/rules/erc-compliance.ts
export function detectERCStandard(ast: ASTNode): 'ERC20' | 'ERC721' | 'ERC1155' | null
export function checkERC20Compliance(ast: ASTNode, source: string): Finding[]
export function checkERC721Compliance(ast: ASTNode, source: string): Finding[]
export function checkERC1155Compliance(ast: ASTNode, source: string): Finding[]

Acceptance Criteria

  • ERC standard auto-detection via function signature heuristics
  • ERC-20: missing return value, missing events, decimals type check
  • ERC-721: safeTransferFrom reentrancy, supportsInterface, unrestricted mint
  • ERC-1155: missing transfer events
  • Example non-compliant contracts in examples/contracts/erc/
  • Compliance rule IDs prefixed CP-ERC20-*, CP-ERC721-*, CP-ERC1155-*

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions