No validation for network configuration JSON (contract addresses, duplicate active versions, schema)

Đang mở
#48 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@DarkLord017 đang làm issue này rồi.

Từ ngày 26/11/2025.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
tooling

Hướng nghiên cứu

Xác định JSON cấu hình mạng và điểm vào tải nó; issue không nêu tên các tệp hoặc kiểm thử cụ thể. Đọc cấu trúc cấu hình hiện có trước khi đánh giá phương pháp xác thực được đề xuất bằng Zod và viem. Được xem là hoàn thành khi schema bắt buộc, các kiểm tra địa chỉ và URL, các quy tắc phiên bản và các ràng buộc riêng của từng mạng được áp dụng mà không dựa vào lỗi khi chạy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

The network configuration JSON (containing calibration/mainnet networks with contract deployments) has no validation layer, which could lead to runtime errors or deployment issues.

Missing Validations

1. Contract Address Format Validation

No checks that contract addresses are:

  • Properly formatted (valid hex, correct length)
  • Properly checksummed (EIP-55 format)
  • Actually valid Ethereum/Filecoin addresses

Example from current config:

"implementation": "0x88449EcAd119B6c05fa5eFB18C80d86d5781fc10"

There's no validation that these addresses are valid before the app tries to use them.

2. Multiple Active Versions

No validation to prevent multiple versions with "status": "active" within the same network. This could cause ambiguity about which contract version should be used.

Example risk:

"versions": [
  {
    "version": "v0.1.0",
    "status": "active",  // ❌ First active version
    ...
  },
  {
    "version": "v1.0.0",
    "status": "active",  // ❌ Second active version - which one is used?
    ...
  }
]
3. Schema Validation

No validation for:

  • Required fields (chainId, rpcUrl, contracts, etc.)
  • Valid status values (should be enum: "active" | "inactive" | "testing")
  • Nested contract structure completeness
  • Type correctness at runtime
4. Business Logic Validation

No checks for:

  • At least one active version per network
  • Valid version format (semantic versioning)
  • Valid URLs (rpcUrl, explorerUrl, linkToRelease)
  • chainId matches network name expectations (314 for mainnet, 314159 for calibration)

Current Risks

Risk 1: Invalid address format

"proxy": "0xINVALID"  // No validation, app crashes at runtime

Risk 2: Two active versions

"calibration": {
  "versions": [
    { "status": "active", ... },
    { "status": "active", ... }  // Which contracts does the app use?
  ]
}

Risk 3: Missing required fields

{
  "version": "v1.0.0",
  // Missing "status" field - no validation
  "contracts": { ... }
}

Suggested Solution: Zod Schema

import { z } from 'zod'
import { isAddress } from 'viem'

const ContractSchema = z.object({
  implementation: z.string().refine(isAddress, 'Invalid address'),
  proxy: z.string().refine(isAddress, 'Invalid address'),
  stateView: z.string().refine(isAddress, 'Invalid address').optional(),
  // ...
})

const VersionSchema = z.object({
  version: z.string().regex(/^v\d+\.\d+\.\d+$/),
  status: z.enum(['active', 'inactive', 'testing']),
  isNew: z.boolean(),
  linkToRelease: z.string().url().or(z.literal('')),
  contracts: z.object({
    warmStorage: ContractSchema,
    serviceProviderRegistry: ContractSchema,
  })
})

const NetworkSchema = z.object({
  name: z.string(),
  rpcUrl: z.string().url(),
  chainId: z.number(),
  explorerUrl: z.string().url(),
  versions: z.array(VersionSchema)
    .refine(
      (versions) => versions.filter(v => v.status === 'active').length <= 1,
      'Only one version can be active'
    )
})
Ngôn ngữ chính
TypeScript
Star
4
Fork
10
Merge trung bình
4 giờ 10 phút
Pull request đã merge (30 ngày)
13

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của FilOzone/filecoin-cloud

Tất cả issue của FilOzone/filecoin-cloud

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.