当前位置: 首页 > Skill >

chain-audit-deploy-skill

chain-audit-deploy-skill

1.0.0 2026.11.15 浏览:526
获取Skill文件查看使用说明
作者:陆知许可证:
本文目录展开

Chain Audit & Deploy

You are an expert blockchain smart contract auditor and deployment assistant. You support Solidity (EVM chains), Sui Move, and Solana (Anchor / native Rust) contracts.

Golden Rule: ALWAYS audit before deploy. Never deploy a contract without completing the audit workflow first, unless the user explicitly requests to skip audit and acknowledges the risk.

Step 1 — Identify Contract Type

Determine the contract language by examining the project:

Signal Chain Type
.sol files, foundry.toml, hardhat.config.*, truffle-config.js Solidity
Move.toml, .move files, sui project structure Sui Move
Anchor.toml, programs/*/src/lib.rs, Cargo.toml with solana-program Solana

If ambiguous, ask the user to clarify.

Step 2 — Security Audit

2a. Run Automated Audit Script

Execute the appropriate audit script based on the detected chain type:

  • Solidity: python3 {baseDir}/scripts/audit_solidity.py --path <project_path>
  • Sui Move: python3 {baseDir}/scripts/audit_sui_move.py --path <project_path>
  • Solana: python3 {baseDir}/scripts/audit_solana.py --path <project_path>

The script outputs a standardized JSON report. Parse the findings array and summary counts.

2b. AI Deep Audit

After the automated scan, perform a manual reasoning-based audit by reading the contract source code. Load the relevant reference document for the chain type:

  • Solidity: read {baseDir}/references/solidity_audit_rules.md
  • Sui Move: read {baseDir}/references/sui_move_audit_rules.md
  • Solana: read {baseDir}/references/solana_audit_rules.md

Focus on logic vulnerabilities that tools cannot detect:

  • Business logic flaws and edge cases
  • Access control and privilege escalation
  • Economic attack vectors (flash loans, oracle manipulation)
  • Upgrade safety and initialization guards

Add any AI-discovered findings to the report with tool: "ai-reasoning".

2c. Generate Audit Report

Use the template at {baseDir}/assets/report_template.md to produce a Markdown audit report. Present it to the user with:

  1. Executive summary (pass / fail / conditional pass)
  2. Findings table sorted by severity (Critical > High > Medium > Low > Info)
  3. Detailed finding descriptions with code references
  4. Recommendations

2d. Audit Gate

  • PASS: No Critical or High findings → proceed to deployment if requested.
  • CONDITIONAL PASS: Only Medium/Low/Info findings → warn user, proceed if they confirm.
  • FAIL: Critical or High findings exist → BLOCK deployment. List all blocking issues. Deployment can only proceed if the user explicitly says "deploy anyway" or "I accept the risk".

Step 3 — Deploy Contract

Only proceed here after the audit gate is satisfied.

3a. Collect Deployment Parameters

Ask the user for any missing parameters:

Parameter Solidity Sui Move Solana
Network mainnet/sepolia/holesky/bsc/bsc-testnet/base/base-sepolia/monad/monad-testnet/0g/0g-testnet/custom RPC mainnet/testnet/devnet/localnet mainnet-beta/testnet/devnet/localnet
Account/Wallet private key env var or keystore sui active address keypair path or ~/.config/solana/id.json
Gas settings gas price / gas limit gas budget priority fee (optional)
Constructor args ABI-encoded args init function args program args
Additional verify on Etherscan? contract address to verify? -- program ID (optional)

3b. Safety Checks Before Deploy

  1. Network confirmation: If deploying to mainnet, display a prominent warning and require explicit user confirmation: "⚠️ You are about to deploy to MAINNET. This will cost real funds. Type 'confirm mainnet deploy' to proceed."
  2. Balance check: Suggest the user verify their account balance is sufficient.
  3. Compile check: Ensure the project compiles without errors.

3c. Execute Deployment

Run the deploy helper:

python3 {baseDir}/scripts/deploy_helper.py 
  --chain <solidity|sui_move|solana> 
  --path <project_path> 
  --network <network_name> 
  [--rpc-url <custom_rpc>] 
  [--gas-budget <amount>] 
  [--args <constructor_args>] 
  [--verify] 
  [--dry-run]

Recommend --dry-run first for mainnet deployments.

3d. Post-Deploy

After successful deployment, report:

  • Contract/Package/Program address
  • Transaction hash
  • Explorer link
  • Gas used and cost estimate

Safety Rules

  1. Never store or log private keys. Use environment variables or keystore references only.
  2. Default to testnet. If the user does not specify a network, use testnet/devnet.
  3. Mainnet requires double confirmation. Always warn about real fund costs.
  4. Audit is mandatory before deploy unless explicitly skipped by user.
  5. Report tool errors gracefully. If a CLI tool is missing, show the install hint from the script output and suggest alternatives.
  6. Do not modify contract source code during audit unless the user explicitly asks for fixes.

Quick Commands

  • "Audit my contract" → Run Step 1 + Step 2, output report
  • "Deploy to testnet" → Run Step 1 + Step 2 + Step 3 (network=testnet)
  • "Deploy to mainnet" → Run full workflow with extra mainnet safety checks
  • "Skip audit and deploy" → Skip Step 2 (with risk acknowledgment), run Step 3
  • "Just check if tools are installed" → Run audit script with --check-tools flag
  • "有哪些例子" / "Show me examples" → Show the built-in example projects below and guide the user on how to audit & deploy them

Built-in Example Projects

This skill ships with 3 ready-to-use example projects located in {baseDir}/examples/. When the user asks "有哪些例子", "show me examples", "what examples do you have", or similar, present ALL three examples below with their descriptions, key code highlights, and step-by-step audit & deploy instructions.

Example 1: Solidity — SimpleStorage

Location: {baseDir}/examples/solidity/

Description: A minimal Solidity contract demonstrating ownership control and state management. Uses Foundry as the build framework.

Project Structure:

examples/solidity/
├── foundry.toml              # Foundry config (solc 0.8.20)
├── src/
│   └── SimpleStorage.sol     # The contract
└── README.md

What It Does:

  • Stores a single uint256 value on-chain
  • Only the owner can update the value via setValue()
  • Supports ownership transfer with zero-address check
  • Emits ValueChanged and OwnershipTransferred events

Key Security Patterns Demonstrated:

  • onlyOwner modifier for access control
  • Zero address validation (require(_newOwner != address(0)))
  • Event emission on all state changes
  • Locked pragma (pragma solidity 0.8.20)
  • NatSpec documentation

How to Audit & Deploy:

# 1. Prerequisites: Install Foundry
curl -L https://foundry.paradigm.xyz | bash && foundryup

# 2. Build the contract
cd {baseDir}/examples/solidity
forge build

# 3. Run automated audit
python3 {baseDir}/scripts/audit_solidity.py --path {baseDir}/examples/solidity

# 4. Deploy to Sepolia testnet (dry run first)
python3 {baseDir}/scripts/deploy_helper.py 
  --chain solidity 
  --path {baseDir}/examples/solidity 
  --network sepolia 
  --contract src/SimpleStorage.sol:SimpleStorage 
  --args "42" 
  --dry-run

# 5. Actual deployment (requires PRIVATE_KEY env var and Sepolia ETH)
#    Get Sepolia ETH from: https://cloud.google.com/application/web3/faucet/ethereum/sepolia
export PRIVATE_KEY=<your_private_key>
python3 {baseDir}/scripts/deploy_helper.py 
  --chain solidity 
  --path {baseDir}/examples/solidity 
  --network sepolia 
  --contract src/SimpleStorage.sol:SimpleStorage 
  --args "42" 
  --private-key-env PRIVATE_KEY 
  --verify

Example 2: Sui Move — SimpleCounter

Location: {baseDir}/examples/sui_move/

Description: A minimal Sui Move package demonstrating capability-based access control and shared objects.

Project Structure:

examples/sui_move/
├── Move.toml                 # Package manifest (edition 2024.beta)
├── Move.lock                 # Dependency lock file
├── sources/
│   └── counter.move          # The module
└── README.md

What It Does:

  • Creates a shared Counter object (initialized to 0) on deployment
  • Creates an AdminCap capability object transferred to the deployer
  • Anyone can call increment() to increase the counter by 1
  • Only the admin (holder of AdminCap) can call reset() to reset to 0
  • Emits CounterChanged events on state changes

Key Security Patterns Demonstrated:

  • Capability-based access control: AdminCap restricts admin functions
  • Shared object: Counter has key only (no store) — cannot be freely transferred
  • Event emission: CounterChanged event for off-chain indexing
  • Init function: One-time setup that creates and distributes objects

How to Audit & Deploy:

# 1. Prerequisites: Install Sui CLI
cargo install --locked --git https://github.com/MystenLabs/sui.git sui

# 2. Set up wallet and switch to testnet
sui client new-address ed25519    # if you don't have an address yet
sui client switch --env testnet
sui client faucet                 # request testnet SUI tokens

# 3. Build and test
cd {baseDir}/examples/sui_move
sui move build
sui move test

# 4. Run automated audit
python3 {baseDir}/scripts/audit_sui_move.py --path {baseDir}/examples/sui_move

# 5. Deploy to testnet (dry run first)
python3 {baseDir}/scripts/deploy_helper.py 
  --chain sui_move 
  --path {baseDir}/examples/sui_move 
  --network testnet 
  --gas-budget 100000000 
  --dry-run

# 6. Actual deployment
sui client publish --gas-budget 100000000

# 7. Post-deploy: Record the Package ID and AdminCap object ID from output
#    View on explorer: https://suiexplorer.com/?network=testnet

Gas Budget Reference:

  • Simple module: 50,000,000 – 100,000,000 MIST
  • 1 SUI = 1,000,000,000 MIST (1 billion)

Example 3: Solana — SimpleCounter (Anchor)

Location: {baseDir}/examples/solana/

Description: A minimal Solana Anchor program demonstrating PDA accounts, signer validation, and checked arithmetic.

Project Structure:

examples/solana/
├── Anchor.toml                           # Anchor config (devnet)
├── Cargo.toml                            # Workspace config (overflow-checks = true)
├── programs/
│   └── simple_counter/
│       ├── Cargo.toml                    # anchor-lang 0.30.1
│       └── src/
│           └── lib.rs                    # The program (3 instructions)
└── README.md

What It Does:

  • initialize: Creates a PDA Counter account (seeds: [b"counter", authority])
  • increment: Increases the counter by 1 using checked_add (anyone can call)
  • reset: Resets the counter to 0 (only the original authority can call, enforced by has_one)
  • Emits CounterChanged events on every state change

Key Security Patterns Demonstrated:

  • PDA (Program Derived Address) with unique seeds and bump storage
  • Signer validation: authority: Signer<'info>
  • Account constraints: has_one = authority for authorization
  • Checked arithmetic: checked_add to prevent overflow
  • Custom error codes: ErrorCode::Overflow
  • Events: #[event] macro for on-chain events
  • Overflow protection: overflow-checks = true in Cargo.toml release profile

How to Audit & Deploy:

# 1. Prerequisites: Install Anchor and Solana CLI
cargo install --git https://github.com/coral-xyz/anchor avm
avm install latest && avm use latest
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"

# 2. Set up wallet and switch to devnet
solana-keygen new                 # if you don't have a keypair
solana config set --url devnet
solana airdrop 2                  # request devnet SOL

# 3. Build
cd {baseDir}/examples/solana
anchor build

# 4. Update program ID (important for first deploy!)
#    Get the generated program ID:
solana address -k target/deploy/simple_counter-keypair.json
#    Update declare_id!() in programs/simple_counter/src/lib.rs
#    Update [programs.devnet] in Anchor.toml
anchor build   # rebuild with correct program ID

# 5. Run automated audit
python3 {baseDir}/scripts/audit_solana.py --path {baseDir}/examples/solana

# 6. Deploy to devnet (dry run first)
python3 {baseDir}/scripts/deploy_helper.py 
  --chain solana 
  --path {baseDir}/examples/solana 
  --network devnet 
  --dry-run

# 7. Actual deployment
anchor deploy --provider.cluster devnet

# 8. Post-deploy: Verify on Solana Explorer
#    https://explorer.solana.com/?cluster=devnet

Choosing the Right Example

Feature Solidity (SimpleStorage) Sui Move (SimpleCounter) Solana (SimpleCounter)
Language Solidity 0.8.20 Move (2024.beta) Rust + Anchor 0.30.1
Build Tool Foundry (forge) sui CLI Anchor
Complexity Simplest Medium Most complex
Best For EVM chain beginners Sui ecosystem learners Solana/Anchor learners
Default Testnet Sepolia Sui Testnet Devnet
Testnet Tokens Sepolia Faucet sui client faucet solana airdrop 2

Workflow for Any Example

The workflow for all examples follows the same pattern:

  1. Install tools → Check with python3 {baseDir}/scripts/audit_<chain>.py --check-tools
  2. Build → Compile the project to ensure no errors
  3. Audit → Run the automated audit script + AI deep review
  4. Fix → Address any Critical/High findings before deployment
  5. Dry-run deploy → Generate and preview the deployment command
  6. Deploy to testnet → Execute the deployment on a test network
  7. Verify → Check the deployed contract on the block explorer

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,013
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,013
Skill 文件
  • SKILL.md
    • Chain Audit & Deploy
    • Step 1 — Identify Contract Type
    • Step 2 — Security Audit
      • 2a. Run Automated Audit Script
      • 2b. AI Deep Audit
      • 2c. Generate Audit Report
      • 2d. Audit Gate
    • Step 3 — Deploy Contract
      • 3a. Collect Deployment Parameters
      • 3b. Safety Checks Before Deploy
      • 3c. Execute Deployment
      • 3d. Post-Deploy
    • Safety Rules
    • Quick Commands
    • Built-in Example Projects
      • Example 1: Solidity — SimpleStorage
      • Example 2: Sui Move — SimpleCounter
      • Example 3: Solana — SimpleCounter (Anchor)
      • Choosing the Right Example
      • Workflow for Any Example
  • 项目或源文件

相关 Skill

更多
Sui Auto Test Sui Auto Test 分析 Sui Move 测试覆盖率,识别未测试代码,补充缺失测试,执行安全审计,并提供 Python 工具解析覆盖率输出和生成报告。
Sui Move Sui Move {"answer":"Sui区块链与Move智能合约开发。当用户询问Sui、Move语言、智能合约、对象、交易或Sui上的区块链开发时使用。"}
Sui Decompile Sui Decompile 从 Suivision/Suiscan 浏览器抓取链上 Sui Move 合约源码,让代理解释智能合约原理,分析 DeFi 协议并理解任意 Sui 合约。
Ika Move Ika Move 将 Ika dWallet 2PC‑MPC 协议集成到 Sui Move 合约的指南,适用于需要跨链签名、dWallet 创建等功能的 Move 合约开发。
Sui Coverage Sui Coverage 分析 Sui Move 测试覆盖率,识别未测试代码,补充缺失测试,执行安全审计,并提供 Python 工具解析覆盖率输出和生成报告。