@btc-vision/btc-runtime 1.10.10 → 1.10.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +258 -137
- package/SECURITY.md +226 -0
- package/docs/README.md +614 -0
- package/docs/advanced/bitcoin-scripts.md +939 -0
- package/docs/advanced/cross-contract-calls.md +579 -0
- package/docs/advanced/plugins.md +1006 -0
- package/docs/advanced/quantum-resistance.md +660 -0
- package/docs/advanced/signature-verification.md +715 -0
- package/docs/api-reference/blockchain.md +729 -0
- package/docs/api-reference/events.md +642 -0
- package/docs/api-reference/op20.md +902 -0
- package/docs/api-reference/op721.md +819 -0
- package/docs/api-reference/safe-math.md +510 -0
- package/docs/api-reference/storage.md +840 -0
- package/docs/contracts/op-net-base.md +786 -0
- package/docs/contracts/op20-token.md +687 -0
- package/docs/contracts/op20s-signatures.md +614 -0
- package/docs/contracts/op721-nft.md +785 -0
- package/docs/contracts/reentrancy-guard.md +787 -0
- package/docs/core-concepts/blockchain-environment.md +724 -0
- package/docs/core-concepts/decorators.md +466 -0
- package/docs/core-concepts/events.md +652 -0
- package/docs/core-concepts/pointers.md +391 -0
- package/docs/core-concepts/security.md +473 -0
- package/docs/core-concepts/storage-system.md +969 -0
- package/docs/examples/basic-token.md +745 -0
- package/docs/examples/nft-with-reservations.md +1440 -0
- package/docs/examples/oracle-integration.md +1212 -0
- package/docs/examples/stablecoin.md +1180 -0
- package/docs/getting-started/first-contract.md +575 -0
- package/docs/getting-started/installation.md +384 -0
- package/docs/getting-started/project-structure.md +630 -0
- package/docs/storage/memory-maps.md +764 -0
- package/docs/storage/stored-arrays.md +778 -0
- package/docs/storage/stored-maps.md +758 -0
- package/docs/storage/stored-primitives.md +655 -0
- package/docs/types/address.md +773 -0
- package/docs/types/bytes-writer-reader.md +938 -0
- package/docs/types/calldata.md +744 -0
- package/docs/types/safe-math.md +446 -0
- package/package.json +51 -26
- package/runtime/memory/MapOfMap.ts +1 -0
- package/LICENSE.md +0 -21
package/SECURITY.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://verichains.io">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/btc-vision/contract-logo/refs/heads/main/public-assets/verichains.png" alt="Verichains" width="300"/>
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://verichains.io">
|
|
11
|
+
<img src="https://img.shields.io/badge/Security%20Audit-Verichains-4C35E0?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTIgMkw0IDV2Ni41YzAgNS4yNSAzLjQgMTAuMiA4IDExLjUgNC42LTEuMyA4LTYuMjUgOC0xMS41VjVsLTgtM3ptMCAxMC45OVYxOS41Yy0zLjQ1LTEuMTctNS45My00LjgtNi02LjVWNi4zTDEyIDRsMCA4Ljk5eiIgZmlsbD0id2hpdGUiLz48L3N2Zz4=" alt="Audited by Verichains"/>
|
|
12
|
+
</a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<strong>Professionally Audited by <a href="https://verichains.io">Verichains</a></strong>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
## Audit Status
|
|
20
|
+
|
|
21
|
+
| Aspect | Status |
|
|
22
|
+
|---------------------------|-------------------------------------|
|
|
23
|
+
| **Auditor** | [Verichains](https://verichains.io) |
|
|
24
|
+
| **Audit Date** | 2025 |
|
|
25
|
+
| **Report Status** | Pending Publication |
|
|
26
|
+
| **Severity Issues Found** | All resolved |
|
|
27
|
+
|
|
28
|
+
## About the Audit
|
|
29
|
+
|
|
30
|
+
The OPNet Smart Contract Runtime has undergone a comprehensive security audit by [Verichains](https://verichains.io), a
|
|
31
|
+
leading blockchain security firm with extensive experience in:
|
|
32
|
+
|
|
33
|
+
- Smart contract security audits
|
|
34
|
+
- Blockchain protocol assessments
|
|
35
|
+
- Cryptographic implementation reviews
|
|
36
|
+
- WebAssembly security analysis
|
|
37
|
+
|
|
38
|
+
## Audit Scope
|
|
39
|
+
|
|
40
|
+
The security audit covered all core components of the btc-runtime:
|
|
41
|
+
|
|
42
|
+
### Contract Standards
|
|
43
|
+
|
|
44
|
+
- [x] **OP_NET Base Contract** - Abstract contract class, lifecycle hooks, method dispatching
|
|
45
|
+
- [x] **OP20 Token Standard** - Fungible token implementation, transfers, approvals, minting/burning
|
|
46
|
+
- [x] **OP20S Signatures** - Gasless approvals, EIP-712 typed signatures, nonce management
|
|
47
|
+
- [x] **OP721 NFT Standard** - Non-fungible tokens, ownership, enumeration, metadata
|
|
48
|
+
- [x] **ReentrancyGuard** - Reentrancy protection mechanisms (STANDARD and CALLBACK modes)
|
|
49
|
+
|
|
50
|
+
### Storage System
|
|
51
|
+
|
|
52
|
+
- [x] **Pointer Architecture** - u16 primary pointers, u256 sub-pointers, SHA256 key hashing
|
|
53
|
+
- [x] **Persistent Storage** - StoredU256, StoredString, StoredAddress, StoredBoolean
|
|
54
|
+
- [x] **Array Storage** - StoredU256Array through StoredU8Array, bounds checking
|
|
55
|
+
- [x] **Map Storage** - StoredMapU256, AddressMemoryMap, MapOfMap nested structures
|
|
56
|
+
|
|
57
|
+
### Cryptographic Operations
|
|
58
|
+
|
|
59
|
+
- [x] **Signature Verification** - Schnorr signatures, ML-DSA quantum-resistant signatures
|
|
60
|
+
- [x] **Hash Functions** - SHA256, double SHA256 (hash256)
|
|
61
|
+
- [x] **EIP-712 Domain Separator** - Typed data signing, replay protection
|
|
62
|
+
- [x] **Address Derivation** - P2TR, P2WSH, P2WPKH address generation
|
|
63
|
+
|
|
64
|
+
### Security Mechanisms
|
|
65
|
+
|
|
66
|
+
- [x] **SafeMath Operations** - Overflow/underflow protection for u256, u128, u64
|
|
67
|
+
- [x] **Access Control** - onlyDeployer patterns, role-based authorization
|
|
68
|
+
- [x] **Input Validation** - Calldata parsing, bounds checking, type verification
|
|
69
|
+
- [x] **Event System** - 352-byte limit enforcement, proper encoding
|
|
70
|
+
|
|
71
|
+
### Bitcoin Integration
|
|
72
|
+
|
|
73
|
+
- [x] **Transaction Parsing** - Input/output decoding, script parsing
|
|
74
|
+
- [x] **Address Validation** - Bitcoin address format verification
|
|
75
|
+
- [x] **Script Building** - Opcodes, CSV timelocks, witness structures
|
|
76
|
+
- [x] **Network Configuration** - Mainnet/testnet handling
|
|
77
|
+
|
|
78
|
+
## Supported Versions
|
|
79
|
+
|
|
80
|
+
| Version | Supported |
|
|
81
|
+
|---------|------------------------|
|
|
82
|
+
| 1.10.x | ✅ Current |
|
|
83
|
+
| 1.9.x | ⚠️ Upgrade recommended |
|
|
84
|
+
| < 1.9.0 | ❌ Not supported |
|
|
85
|
+
|
|
86
|
+
## Security Best Practices
|
|
87
|
+
|
|
88
|
+
When developing contracts with btc-runtime, follow these guidelines:
|
|
89
|
+
|
|
90
|
+
### Use SafeMath for All Arithmetic
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { SafeMath } from '@btc-vision/btc-runtime/runtime';
|
|
94
|
+
|
|
95
|
+
// CORRECT: Use SafeMath
|
|
96
|
+
const total = SafeMath.add(balance, amount);
|
|
97
|
+
const remaining = SafeMath.sub(balance, amount);
|
|
98
|
+
|
|
99
|
+
// WRONG: Direct arithmetic can overflow silently
|
|
100
|
+
// const total = balance + amount; // DON'T DO THIS
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Always Validate Inputs
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
class Test extends OP_NET {
|
|
107
|
+
public transfer(calldata: Calldata): BytesWriter {
|
|
108
|
+
const to = calldata.readAddress();
|
|
109
|
+
const amount = calldata.readU256();
|
|
110
|
+
|
|
111
|
+
// Validate recipient is not zero address
|
|
112
|
+
if (to.equals(Address.zero())) {
|
|
113
|
+
throw new Revert('Cannot transfer to zero address');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Validate amount is positive
|
|
117
|
+
if (amount.isZero()) {
|
|
118
|
+
throw new Revert('Amount must be greater than zero');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ... proceed with transfer
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Use Reentrancy Guards
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { ReentrancyGuard, ReentrancyGuardMode } from '@btc-vision/btc-runtime/runtime';
|
|
130
|
+
|
|
131
|
+
@final
|
|
132
|
+
export class MyContract extends ReentrancyGuard {
|
|
133
|
+
constructor() {
|
|
134
|
+
// Use CALLBACK mode for contracts with safe transfer callbacks
|
|
135
|
+
super(ReentrancyGuardMode.CALLBACK);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Implement Access Control
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// Check deployer authorization
|
|
144
|
+
this.onlyDeployer(Blockchain.tx.sender);
|
|
145
|
+
|
|
146
|
+
// Custom role checks
|
|
147
|
+
class Test {
|
|
148
|
+
private onlyAdmin(): void {
|
|
149
|
+
if (!this.isAdmin(Blockchain.tx.sender)) {
|
|
150
|
+
throw new Revert('Caller is not admin');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Handle Cross-Contract Calls Safely
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const result = Blockchain.call(targetContract, calldata, true);
|
|
160
|
+
|
|
161
|
+
if (!result.success) {
|
|
162
|
+
throw new Revert('External call failed');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Parse and validate response
|
|
166
|
+
const response = result.data;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Never Use Floating-Point Arithmetic
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// WRONG: Floating-point is non-deterministic
|
|
173
|
+
// const price = 1.5; // DON'T USE FLOATS
|
|
174
|
+
|
|
175
|
+
// CORRECT: Use fixed-point with integers
|
|
176
|
+
const PRECISION = u256.fromU64(1_000_000); // 6 decimals
|
|
177
|
+
const price = SafeMath.mul(amount, PRECISION);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Reporting a Vulnerability
|
|
181
|
+
|
|
182
|
+
We take security vulnerabilities seriously. If you discover a security issue, please report it responsibly.
|
|
183
|
+
|
|
184
|
+
### How to Report
|
|
185
|
+
|
|
186
|
+
1. **DO NOT** open a public GitHub issue for security vulnerabilities
|
|
187
|
+
2. Report via [GitHub Security Advisories](https://github.com/btc-vision/btc-runtime/security/advisories)
|
|
188
|
+
3. Include detailed steps to reproduce the vulnerability
|
|
189
|
+
4. Allow reasonable time for a fix before public disclosure
|
|
190
|
+
|
|
191
|
+
### What to Include
|
|
192
|
+
|
|
193
|
+
- Description of the vulnerability
|
|
194
|
+
- Affected component(s) and version(s)
|
|
195
|
+
- Steps to reproduce
|
|
196
|
+
- Potential impact assessment
|
|
197
|
+
- Suggested fix (if any)
|
|
198
|
+
- Proof of concept (if applicable)
|
|
199
|
+
|
|
200
|
+
### Response Timeline
|
|
201
|
+
|
|
202
|
+
| Action | Timeframe |
|
|
203
|
+
|----------------------------|---------------------|
|
|
204
|
+
| Initial response | 48 hours |
|
|
205
|
+
| Vulnerability confirmation | 7 days |
|
|
206
|
+
| Patch development | 14-30 days |
|
|
207
|
+
| Public disclosure | After patch release |
|
|
208
|
+
|
|
209
|
+
## Audit Report
|
|
210
|
+
|
|
211
|
+
The full audit report from Verichains will be published here upon completion of the disclosure process.
|
|
212
|
+
|
|
213
|
+
📄 **[Audit Report - Coming Soon]**
|
|
214
|
+
|
|
215
|
+
## Contact
|
|
216
|
+
|
|
217
|
+
- **Security Issues**: [GitHub Security Advisories](https://github.com/btc-vision/btc-runtime/security/advisories)
|
|
218
|
+
- **General Questions**: [GitHub Issues](https://github.com/btc-vision/btc-runtime/issues)
|
|
219
|
+
- **Website**: [OPNet](https://opnet.org)
|
|
220
|
+
- **Auditor**: [Verichains](https://verichains.io)
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
<p align="center">
|
|
225
|
+
<sub>Security is a continuous process. This document will be updated as new audits are completed.</sub>
|
|
226
|
+
</p>
|