Skip to main content

Smart Contract Scanning

ChainX Scanner provides two powerful scanning methods: standard vulnerability detection and AI-powered analysis. Choose the method that best fits your security needs.

Standard Vulnerability Scan

The standard scan detects 12+ known Smart Contract Weakness Classification (SWC) patterns and provides instant vulnerability detection with security scoring.

Basic Scan

Scan a smart contract file for vulnerabilities:


curl -X POST https://chainx-api-a154bfdeaf7a.herokuapp.com/api/v1/scan \
-H "X-API-Key: prod-chainx-abc123..." \
-F "file=@contracts/MyToken.sol"

Response Structure


{
"success": true,
"message": "File scanned successfully",
"scanId": "cluxyz123scan456",
"file": "/uploads/contract_123.sol",
"vulnerabilitiesCount": 3,
"dataVulnerabilities": [
{ "vulnerabilityId": "SWC-103" },
{ "vulnerabilityId": "SWC-107" },
{ "vulnerabilityId": "SWC-115" }
],
"securityScore": {
"score": 75,
"rating": "Good",
"summary": {
"total": 3,
"critical": 0,
"high": 2,
"medium": 1,
"low": 0
}
},
"bestPractices": {
"checklist": [
{
"category": "Access Control",
"items": [
"Implement proper authorization checks",
"Use OpenZeppelin AccessControl"
]
},
{
"category": "Reentrancy Protection",
"items": [
"Use ReentrancyGuard for external calls",
"Follow checks-effects-interactions pattern"
]
}
],
"recommendations": [
"Use well-audited libraries like OpenZeppelin",
"Implement reentrancy guards for state-changing functions",
"Add comprehensive input validation",
"Consider a professional security audit"
]
}
}

Detected Vulnerabilities

ChainX Scanner detects the following SWC (Smart Contract Weakness Classification) patterns:

SWCNameSeverityDescription
SWC-101Integer Overflow and UnderflowCriticalArithmetic operations without bounds checking
SWC-103Floating PragmaHighUsing unconstrained pragma version
SWC-104Unchecked Call Return ValueHighIgnoring return values from external calls
SWC-105Unprotected Ether WithdrawalCriticalUnrestricted fund withdrawal
SWC-106Unprotected SELFDESTRUCTCriticalUnprotected contract destruction
SWC-107ReentrancyCriticalFunctions vulnerable to reentrancy attacks
SWC-112Delegatecall to Untrusted CalleeCriticalDangerous delegatecall usage
SWC-113DoS with Failed CallHighDenial of service via failed calls
SWC-114Tx.Origin AuthenticationHighUsing tx.origin for authorization
SWC-115Authorization via tx.originHighIncorrect authorization mechanism
SWC-116Block Values as Time ProxiesMediumRelying on block variables for timing
SWC-118Incorrect Constructor NameHighOutdated constructor syntax
SWC-120Weak Sources of RandomnessHighUsing predictable randomness sources
SWC-123Requirement ViolationMediumMissing validation checks
SWC-132Unexpected Gas UsageMediumGas estimation errors

Security Score Calculation

The security score ranges from 0-100 and is calculated as follows:

  • Start with: 100 points
  • Deduct per vulnerability:
    • Critical: -20 points each
    • High: -10 points each
    • Medium: -5 points each
    • Low: -2 points each
    • Info: -1 point each

Score Ratings

Score RangeRatingStatus
90-100ExcellentVery secure
75-89GoodGenerally secure with minor concerns
60-74FairMultiple vulnerabilities to address
40-59PoorSignificant security issues
0-39CriticalHigh-risk, do not deploy

AI-Powered Smart Contract Analysis

Get in-depth analysis of your smart contracts using advanced AI models via OpenRouter.

Prerequisites

  • A valid API key from ChainX Scanner
  • An OpenRouter API key (get one at openrouter.ai)
  • An AI model selection (e.g., 'google/gemini-2.0-pro-exp-02-05:free')

AI Scan Request


curl -X POST https://chainx-api-a154bfdeaf7a.herokuapp.com/api/v1/ai-scan \
-H "X-API-Key: prod-chainx-abc123..." \
-F "file=@contracts/MyToken.sol" \
-F "openrouterApiKey=sk-or-v1-..." \
-F "model=google/gemini-2.0-pro-exp-02-05:free"

AI Scan Response


{
"success": true,
"message": "Analysis completed successfully.",
"timeTaken": "12873.76 milliseconds",
"results": {
"summary": "...",
"vulnerabilities": [],
"recommendations": []
},
"outputFile": "analysis_results_2025-03-04T03-42-57-890Z.md"
}

Practical Examples

Example 1: Token Contract with Overflow Risk


// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract VulnerableToken {
mapping(address => uint) balances;
function transfer(address to, uint amount) public {
// SWC-101: Integer Overflow
balances[msg.sender] -= amount;
balances[to] += amount;
}
}

Example 2: Reentrancy Vulnerability


// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract VulnerableBank {
mapping(address => uint) balances;
function withdraw(uint amount) public {
require(balances[msg.sender] >= amount);
// SWC-107: Reentrancy vulnerability
(bool success, ) = msg.sender.call{value: amount}("");
require(success);
balances[msg.sender] -= amount;
}
}

Best Practices

  1. Always Verify API Keys: Store API keys in environment variables, never hardcode them
  2. Handle Rate Limits: Implement exponential backoff for rate limit errors (429)
  3. Validate File Size: Ensure contracts are within plan limits before uploading
  4. Review All Findings: Security scores are indicators; review all reported issues
  5. Use Multiple Tools: Combine ChainX with formal verification and professional audits
  6. Automate in CI/CD: Integrate scanning into your deployment pipeline
  7. Monitor Quotas: Check your plan regularly to track scan usage

Quota Limits

Different subscription plans have different limits:

PlanScans/DayMax File SizeMax Contract Size
Free5100 KB5 KB
Basic1001 MB50 KB
Pro10005 MB500 KB

See Subscription Plans for more details.