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
decimals — decimals() 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
- Detect which ERC standard a contract implements via interface detection (function signature heuristic)
- Once standard is detected, apply the corresponding compliance rule set
- 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
References
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)
transfer/transferFrom— ERC-20 spec requires aboolreturn; some tokens omit it, breaking integratorsTransferandApprovalevents — integrators and indexers rely on thesedecimals—decimals()should returnuint8, notuint256approverace condition — flagging directapprovewithout aincreaseAllowance/decreaseAllowancepatternERC-721 Compliance (CP-ERC721)
safeTransferFromreentrancy guard — ERC-721 callsonERC721Receivedon the recipient which creates a reentrancy vectorsupportsInterfaceimplementation — required by ERC-165_mintcallable without access controlERC-1155 Compliance (CP-ERC1155)
TransferSingle/TransferBatcheventsonERC1155Receivedreentrancy considerationDetection Strategy
Acceptance Criteria
examples/contracts/erc/CP-ERC20-*,CP-ERC721-*,CP-ERC1155-*References