midnight-compact

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Midnight Compact Language

Midnight Compact 语言

Complete guide to writing privacy-preserving smart contracts with Compact.
使用Compact编写隐私保护型智能合约的完整指南。

What is Compact?

什么是Compact?

Compact is a purpose-built programming language for zero-knowledge smart contracts. Unlike adapting existing languages, Compact was designed from scratch to make privacy-preserving programming natural and secure.
Key Design Goals:
  • Compile directly to efficient ZK circuits
  • Type-safe cryptographic operations
  • Familiar syntax for developers
  • Automatic proof generation
Compact是专为零知识智能合约打造的编程语言。与改造现有语言不同,Compact是从头设计的,旨在让隐私保护编程自然且安全。
核心设计目标:
  • 直接编译为高效的ZK电路
  • 类型安全的加密操作
  • 开发者熟悉的语法
  • 自动生成证明

Quick Start

快速入门

Basic Contract Structure

基础合约结构

compact
circuit myContract(private secretInput, public publicInput) {
  // Private data hidden in proof
  // Public data visible to all
  // Proof shows execution was correct
}
compact
circuit myContract(private secretInput, public publicInput) {
  // Private data hidden in proof
  // Public data visible to all
  // Proof shows execution was correct
}

Project Scaffolding

项目脚手架

Use
scripts/init-compact-project.py
to create new projects with proper structure.
使用
scripts/init-compact-project.py
创建结构规范的新项目。

Contract Generation

合约生成

Use
scripts/generate-contract.py
to generate boilerplate from templates.
使用
scripts/generate-contract.py
从模板生成合约样板代码。

Compilation

编译

Use
scripts/compile-compact.py
for compilation with error handling.
使用
scripts/compile-compact.py
进行编译并处理错误。

Language Reference

语言参考

Basics

基础内容

See language-basics.md for:
  • Syntax and structure
  • Types and variables
  • Functions and control flow
  • Modules and imports
可参考language-basics.md了解:
  • 语法与结构
  • 类型与变量
  • 函数与控制流
  • 模块与导入

ZK Patterns

ZK电路模式

See zk-patterns.md for:
  • Common zero-knowledge proof patterns
  • Circuit optimization techniques
  • Performance best practices
  • Privacy-preserving algorithms
可参考zk-patterns.md了解:
  • 常见零知识证明模式
  • 电路优化技巧
  • 性能最佳实践
  • 隐私保护算法

Standard Library

标准库

See standard-library.md for:
  • Built-in cryptographic functions
  • Hashing and commitments
  • Elliptic curve operations
  • Blockchain interaction primitives
可参考standard-library.md了解:
  • 内置加密函数
  • 哈希与承诺
  • 椭圆曲线操作
  • 区块链交互原语

Contract Examples

合约示例

See contract-examples.md for annotated examples:
  • Private token contracts (Zswap integration)
  • Voting contracts (secret ballot)
  • DeFi contracts (confidential trading)
  • Identity contracts (credential verification)
可参考contract-examples.md中的带注释示例:
  • 私有代币合约(集成Zswap)
  • 投票合约(秘密投票)
  • DeFi合约(保密交易)
  • 身份合约(凭证验证)

Best Practices

最佳实践

See best-practices.md for:
  • Security guidelines
  • Performance optimization
  • Testing strategies
  • Formal verification approaches
可参考best-practices.md了解:
  • 安全指南
  • 性能优化
  • 测试策略
  • 形式化验证方法

Contract Templates

合约模板

Ready-to-use templates in
assets/templates/
:
  • basic-contract/: Minimal working contract
  • private-token/: Zswap token implementation
  • voting-contract/: Private voting system
  • defi-contract/: Confidential DeFi protocol
assets/templates/
目录下有可直接使用的模板:
  • basic-contract/: 最简可用合约
  • private-token/: Zswap代币实现
  • voting-contract/: 私有投票系统
  • defi-contract/: 保密DeFi协议

Development Workflow

开发流程

  1. Initialize:
    python scripts/init-compact-project.py <project-name>
  2. Generate:
    python scripts/generate-contract.py <template-name>
  3. Develop: Write contract logic in Compact
  4. Compile:
    python scripts/compile-compact.py <contract-file>
  5. Test: Run tests with Compact test framework
  6. Deploy: Deploy to Midnight network
  1. 初始化
    python scripts/init-compact-project.py <project-name>
  2. 生成
    python scripts/generate-contract.py <template-name>
  3. 开发:使用Compact编写合约逻辑
  4. 编译
    python scripts/compile-compact.py <contract-file>
  5. 测试:使用Compact测试框架运行测试
  6. 部署:部署至Midnight Network

Resources

相关资源