88 lines
2.1 KiB
Markdown
88 lines
2.1 KiB
Markdown
# NAC虚拟机(NVM)
|
||
|
||
NAC原生虚拟机,用于执行Charter智能合约。NVM是专为RWA(Real World Assets)设计的虚拟机,内置宪法验证、合规检查和资产操作指令。
|
||
|
||
## 特性
|
||
|
||
### 核心功能
|
||
|
||
- **完整的指令集**: 栈操作、算术运算、逻辑运算、内存操作、控制流、RWA专用指令、宪法验证指令、合规检查指令
|
||
- **高级内存管理**: 页式内存分配、标记-清除垃圾回收、内存安全检查、性能优化
|
||
- **JIT编译器**: 热点代码检测、多级优化、内联优化、常量折叠、死代码消除、编译缓存
|
||
- **沙箱安全系统**: 权限策略、资源限制、安全监控、审计日志、安全报告生成
|
||
|
||
### NAC专用指令
|
||
|
||
#### RWA资产操作
|
||
- AssetCreate: 创建RWA资产
|
||
- AssetTransfer: 转移资产所有权
|
||
- AssetQuery: 查询资产信息
|
||
- AssetBurn: 销毁资产
|
||
|
||
#### 宪法验证
|
||
- ConstitutionCheck: 检查宪法合规性
|
||
- ClauseVerify: 验证特定条款
|
||
- RightsQuery: 查询权利信息
|
||
|
||
#### 合规检查
|
||
- KycVerify: KYC身份验证
|
||
- AmlCheck: 反洗钱检查
|
||
- ComplianceReport: 生成合规报告
|
||
|
||
## 使用方法
|
||
|
||
### 基础执行
|
||
|
||
\`\`\`rust
|
||
use nac_nvm::{Executor, Opcode, Bytecode};
|
||
|
||
let mut executor = Executor::new();
|
||
let bytecode = Bytecode::new(vec![Opcode::Push, Opcode::Push, Opcode::Add]);
|
||
let result = executor.execute(&bytecode)?;
|
||
\`\`\`
|
||
|
||
### 使用JIT编译
|
||
|
||
\`\`\`rust
|
||
use nac_nvm::{JitCompiler, OptimizationLevel};
|
||
|
||
let mut jit = JitCompiler::new();
|
||
jit.set_optimization_level(OptimizationLevel::O2);
|
||
let compiled = jit.compile(&bytecode)?;
|
||
let result = compiled.execute()?;
|
||
\`\`\`
|
||
|
||
### 使用沙箱
|
||
|
||
\`\`\`rust
|
||
use nac_nvm::{Sandbox, SecurityPolicy, ResourceLimits};
|
||
|
||
let mut sandbox = Sandbox::with_limits(policy, limits);
|
||
sandbox.initialize()?;
|
||
sandbox.pre_execution_check(Opcode::Push)?;
|
||
let report = sandbox.generate_security_report();
|
||
\`\`\`
|
||
|
||
## 测试
|
||
|
||
\`\`\`bash
|
||
cargo test
|
||
\`\`\`
|
||
|
||
33个测试全部通过!
|
||
|
||
## 更新日志
|
||
|
||
### v1.0.0 (2026-02-18)
|
||
|
||
- ✅ 完整的指令集实现
|
||
- ✅ NAC专用RWA指令
|
||
- ✅ 高级内存管理
|
||
- ✅ JIT编译器
|
||
- ✅ 沙箱安全系统
|
||
- ✅ 33个测试全部通过
|
||
|
||
## 许可证
|
||
|
||
MIT License
|