@btc-vision/btc-runtime 1.11.0-rc.9 → 1.11.0
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/README.md +7 -7
- package/docs/README.md +39 -39
- package/docs/advanced/bitcoin-scripts.md +17 -17
- package/docs/advanced/{contract-upgrades.md → contract-updates.md} +90 -98
- package/docs/advanced/cross-contract-calls.md +4 -4
- package/docs/advanced/plugins.md +21 -21
- package/docs/advanced/quantum-resistance.md +32 -32
- package/docs/advanced/signature-verification.md +22 -22
- package/docs/api-reference/blockchain.md +14 -14
- package/docs/api-reference/events.md +2 -2
- package/docs/api-reference/op20.md +7 -7
- package/docs/api-reference/op721.md +7 -7
- package/docs/api-reference/storage.md +2 -2
- package/docs/contracts/op-net-base.md +15 -15
- package/docs/contracts/op20-token.md +3 -3
- package/docs/contracts/op20s-signatures.md +2 -2
- package/docs/contracts/op721-nft.md +3 -3
- package/docs/contracts/reentrancy-guard.md +5 -7
- package/docs/contracts/updatable.md +384 -0
- package/docs/core-concepts/blockchain-environment.md +10 -10
- package/docs/core-concepts/decorators.md +5 -5
- package/docs/core-concepts/events.md +6 -6
- package/docs/core-concepts/pointers.md +5 -5
- package/docs/core-concepts/security.md +5 -5
- package/docs/core-concepts/storage-system.md +24 -24
- package/docs/examples/basic-token.md +8 -8
- package/docs/examples/nft-with-reservations.md +9 -9
- package/docs/examples/oracle-integration.md +13 -13
- package/docs/examples/stablecoin.md +10 -10
- package/docs/getting-started/first-contract.md +8 -8
- package/docs/getting-started/installation.md +2 -2
- package/docs/getting-started/project-structure.md +6 -6
- package/docs/storage/memory-maps.md +8 -8
- package/docs/storage/stored-arrays.md +6 -6
- package/docs/storage/stored-maps.md +8 -8
- package/docs/storage/stored-primitives.md +6 -6
- package/docs/types/address.md +13 -13
- package/docs/types/bytes-writer-reader.md +18 -18
- package/docs/types/calldata.md +12 -12
- package/package.json +10 -10
- package/runtime/constants/Exports.ts +0 -30
- package/runtime/contracts/OP20.ts +7 -7
- package/runtime/contracts/OP721.ts +60 -74
- package/runtime/contracts/OP_NET.ts +2 -2
- package/runtime/contracts/ReentrancyGuard.ts +1 -5
- package/runtime/contracts/Updatable.ts +241 -0
- package/runtime/contracts/interfaces/OP721InitParameters.ts +8 -8
- package/runtime/env/BlockchainEnvironment.ts +5 -5
- package/runtime/env/global.ts +7 -6
- package/runtime/events/predefined/{ApprovedEvent.ts → OP20ApprovedEvent.ts} +1 -1
- package/runtime/events/predefined/{BurnedEvent.ts → OP20BurnedEvent.ts} +1 -1
- package/runtime/events/predefined/{MintedEvent.ts → OP20MintedEvent.ts} +1 -1
- package/runtime/events/predefined/{TransferredEvent.ts → OP20TransferredEvent.ts} +1 -1
- package/runtime/events/predefined/OP721ApprovedEvent.ts +17 -0
- package/runtime/events/predefined/{ApprovedForAll.ts → OP721ApprovedForAllEvent.ts} +1 -1
- package/runtime/events/predefined/OP721BurnedEvent.ts +16 -0
- package/runtime/events/predefined/OP721MintedEvent.ts +16 -0
- package/runtime/events/predefined/OP721TransferredEvent.ts +18 -0
- package/runtime/events/predefined/index.ts +5 -5
- package/runtime/events/{upgradeable/UpgradeableEvents.ts → updatable/UpdatableEvents.ts} +9 -9
- package/runtime/hashing/keccak256.ts +1 -1
- package/runtime/index.ts +3 -5
- package/runtime/plugins/UpdatablePlugin.ts +276 -0
- package/runtime/script/Networks.ts +1 -1
- package/runtime/storage/StoredBoolean.ts +23 -12
- package/runtime/types/Address.ts +1 -1
- package/runtime/types/ExtendedAddress.ts +1 -1
- package/docs/contracts/upgradeable.md +0 -396
- package/runtime/contracts/Upgradeable.ts +0 -242
- package/runtime/contracts/interfaces/IOP1155.ts +0 -33
- package/runtime/contracts/interfaces/OP1155InitParameters.ts +0 -11
- package/runtime/plugins/UpgradeablePlugin.ts +0 -279
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Quantum Resistance
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OP_NET includes built-in quantum-resistant cryptography through ML-DSA (Module-Lattice Digital Signature Algorithm). The `Address` class provides automatic access to ML-DSA public keys without requiring any custom storage.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
7
|
Quantum computers pose a threat to traditional cryptographic schemes:
|
|
8
8
|
|
|
9
|
-
| Algorithm | Quantum Threat |
|
|
9
|
+
| Algorithm | Quantum Threat | OP_NET Status |
|
|
10
10
|
|-----------|---------------|--------------|
|
|
11
11
|
| ECDSA | Vulnerable (Shor's algorithm) | Supported (deprecated), transition to ML-DSA |
|
|
12
12
|
| Schnorr | Vulnerable (Shor's algorithm) | Supported, with transition plan |
|
|
@@ -40,7 +40,7 @@ const isValid = Blockchain.verifySignature(
|
|
|
40
40
|
- Existing signatures remain safe (retroactive attack impossible)
|
|
41
41
|
- Future transactions from exposed addresses are at risk
|
|
42
42
|
|
|
43
|
-
###
|
|
43
|
+
### OP_NET's Approach
|
|
44
44
|
|
|
45
45
|
1. **Dual signature support** - Both Schnorr and ML-DSA signatures
|
|
46
46
|
2. **Extended addresses** - Store both Schnorr (taproot) and ML-DSA key references
|
|
@@ -49,7 +49,7 @@ const isValid = Blockchain.verifySignature(
|
|
|
49
49
|
|
|
50
50
|
## ML-DSA Security Levels
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
OP_NET supports three ML-DSA security levels, from classical Schnorr to quantum-resistant ML-DSA:
|
|
53
53
|
|
|
54
54
|
```mermaid
|
|
55
55
|
---
|
|
@@ -57,7 +57,7 @@ config:
|
|
|
57
57
|
theme: dark
|
|
58
58
|
---
|
|
59
59
|
flowchart LR
|
|
60
|
-
subgraph
|
|
60
|
+
subgraph OP_NET["OP_NET Security Architecture"]
|
|
61
61
|
subgraph Classical["Classical Security"]
|
|
62
62
|
C1["Schnorr<br/>256-bit<br/>Classical: Strong<br/>Quantum: Broken"]
|
|
63
63
|
end
|
|
@@ -83,7 +83,7 @@ flowchart LR
|
|
|
83
83
|
| Level3 | ML-DSA-65 | 1,952 bytes | 3,309 bytes | 4,032 bytes | Category 3 (~AES-192) |
|
|
84
84
|
| Level5 | ML-DSA-87 | 2,592 bytes | 4,627 bytes | 4,896 bytes | Category 5 (~AES-256) |
|
|
85
85
|
|
|
86
|
-
**
|
|
86
|
+
**OP_NET uses ML-DSA-44 (Level2) by default**, balancing security and performance.
|
|
87
87
|
|
|
88
88
|
### Level Constants
|
|
89
89
|
|
|
@@ -109,7 +109,7 @@ config:
|
|
|
109
109
|
theme: dark
|
|
110
110
|
---
|
|
111
111
|
flowchart LR
|
|
112
|
-
subgraph
|
|
112
|
+
subgraph OP_NET["OP_NET Quantum-Resistant Signatures"]
|
|
113
113
|
subgraph MLDSA["ML-DSA-44 - Level2 - Default"]
|
|
114
114
|
PK["Public Key<br/>1,312 bytes"]
|
|
115
115
|
SIG["Signature<br/>2,420 bytes"]
|
|
@@ -133,7 +133,7 @@ flowchart LR
|
|
|
133
133
|
|
|
134
134
|
### Automatic ML-DSA Key Access
|
|
135
135
|
|
|
136
|
-
Every `Address` in
|
|
136
|
+
Every `Address` in OP_NET stores the SHA256 hash of an ML-DSA public key. The full public key is automatically loaded on demand:
|
|
137
137
|
|
|
138
138
|
```typescript
|
|
139
139
|
import { Address, Blockchain } from '@btc-vision/btc-runtime/runtime';
|
|
@@ -214,7 +214,7 @@ config:
|
|
|
214
214
|
sequenceDiagram
|
|
215
215
|
participant User as 👤 User
|
|
216
216
|
participant Wallet as Wallet
|
|
217
|
-
participant Blockchain as
|
|
217
|
+
participant Blockchain as OP_NET Runtime
|
|
218
218
|
participant Contract as Contract
|
|
219
219
|
|
|
220
220
|
Note over User,Blockchain: Key Generation (Off-chain)
|
|
@@ -310,7 +310,7 @@ const isValid = Blockchain.verifyMLDSASignature(
|
|
|
310
310
|
|
|
311
311
|
## Migration Path: Schnorr to ML-DSA
|
|
312
312
|
|
|
313
|
-
|
|
313
|
+
OP_NET manages a phased transition from classical to quantum-resistant signatures:
|
|
314
314
|
|
|
315
315
|
```mermaid
|
|
316
316
|
---
|
|
@@ -319,7 +319,7 @@ config:
|
|
|
319
319
|
---
|
|
320
320
|
sequenceDiagram
|
|
321
321
|
participant User as User/Wallet
|
|
322
|
-
participant Network as
|
|
322
|
+
participant Network as OP_NET Network
|
|
323
323
|
participant Consensus as Consensus Rules
|
|
324
324
|
|
|
325
325
|
Note over User,Consensus: Phase 1: Transition Period (Current)
|
|
@@ -431,13 +431,13 @@ class QuantumSecureContract extends OP_NET {
|
|
|
431
431
|
}
|
|
432
432
|
```
|
|
433
433
|
|
|
434
|
-
## Solidity vs
|
|
434
|
+
## Solidity vs OP_NET: Quantum Resistance Comparison
|
|
435
435
|
|
|
436
|
-
|
|
436
|
+
OP_NET is the first smart contract platform with built-in quantum-resistant cryptography. Solidity and the EVM have no quantum resistance capabilities.
|
|
437
437
|
|
|
438
438
|
### Feature Comparison Table
|
|
439
439
|
|
|
440
|
-
| Feature | Solidity/EVM |
|
|
440
|
+
| Feature | Solidity/EVM | OP_NET | OP_NET Advantage |
|
|
441
441
|
|---------|--------------|-------|-----------------|
|
|
442
442
|
| **Quantum-Safe Signatures** | Not supported | ML-DSA (FIPS 204) | Future-proof security |
|
|
443
443
|
| **Post-Quantum Algorithm** | None | ML-DSA-44/65/87 | NIST standardized |
|
|
@@ -449,16 +449,16 @@ OPNet is the first smart contract platform with built-in quantum-resistant crypt
|
|
|
449
449
|
|
|
450
450
|
### Quantum Threat Analysis
|
|
451
451
|
|
|
452
|
-
| Algorithm | Shor's Algorithm Impact | Grover's Algorithm Impact | Status in
|
|
452
|
+
| Algorithm | Shor's Algorithm Impact | Grover's Algorithm Impact | Status in OP_NET |
|
|
453
453
|
|-----------|------------------------|---------------------------|-----------------|
|
|
454
454
|
| ECDSA (Solidity) | **Broken** (polynomial time) | Weakened | N/A |
|
|
455
|
-
| ECDSA (
|
|
456
|
-
| Schnorr (
|
|
457
|
-
| ML-DSA (
|
|
455
|
+
| ECDSA (OP_NET) | **Broken** (polynomial time) | Weakened | Deprecated |
|
|
456
|
+
| Schnorr (OP_NET) | **Broken** (polynomial time) | Weakened | Transition only |
|
|
457
|
+
| ML-DSA (OP_NET) | **Secure** | Minimal impact | **Recommended** |
|
|
458
458
|
|
|
459
459
|
### Security Level Comparison
|
|
460
460
|
|
|
461
|
-
| Security Level | Solidity |
|
|
461
|
+
| Security Level | Solidity | OP_NET ML-DSA | NIST Category | Quantum Security |
|
|
462
462
|
|----------------|----------|--------------|---------------|------------------|
|
|
463
463
|
| ~AES-128 equivalent | ECDSA (broken by quantum) | ML-DSA-44 (Level2) | Category 2 | **Secure** |
|
|
464
464
|
| ~AES-192 equivalent | Not available | ML-DSA-65 (Level3) | Category 3 | **Secure** |
|
|
@@ -466,7 +466,7 @@ OPNet is the first smart contract platform with built-in quantum-resistant crypt
|
|
|
466
466
|
|
|
467
467
|
### Key and Signature Size Comparison
|
|
468
468
|
|
|
469
|
-
| Metric | Solidity (ECDSA) |
|
|
469
|
+
| Metric | Solidity (ECDSA) | OP_NET (Schnorr) | OP_NET (ML-DSA-44) | OP_NET (ML-DSA-87) |
|
|
470
470
|
|--------|------------------|-----------------|-------------------|-------------------|
|
|
471
471
|
| Public Key Size | 33/65 bytes | 32 bytes | 1,312 bytes | 2,592 bytes |
|
|
472
472
|
| Signature Size | 65 bytes | 64 bytes | 2,420 bytes | 4,627 bytes |
|
|
@@ -475,7 +475,7 @@ OPNet is the first smart contract platform with built-in quantum-resistant crypt
|
|
|
475
475
|
|
|
476
476
|
### Capability Matrix
|
|
477
477
|
|
|
478
|
-
| Capability | Solidity |
|
|
478
|
+
| Capability | Solidity | OP_NET |
|
|
479
479
|
|------------|:--------:|:-----:|
|
|
480
480
|
| ECDSA verification (Ethereum) | Yes | Yes (deprecated) |
|
|
481
481
|
| ECDSA verification (Bitcoin) | No | Yes (deprecated) |
|
|
@@ -491,7 +491,7 @@ OPNet is the first smart contract platform with built-in quantum-resistant crypt
|
|
|
491
491
|
|
|
492
492
|
### Timeline: Quantum Threat vs Platform Readiness
|
|
493
493
|
|
|
494
|
-
| Timeframe | Quantum Computer Status | Solidity Status |
|
|
494
|
+
| Timeframe | Quantum Computer Status | Solidity Status | OP_NET Status |
|
|
495
495
|
|-----------|------------------------|-----------------|--------------|
|
|
496
496
|
| **2024-2025** | Early NISQ era (~1000 qubits) | Vulnerable (no plan) | ML-DSA ready |
|
|
497
497
|
| **2026-2030** | Scaling (~4000+ qubits possible) | **Critical risk** | Dual-key transition |
|
|
@@ -511,7 +511,7 @@ flowchart LR
|
|
|
511
511
|
S3 --> S4["Funds at risk"]
|
|
512
512
|
end
|
|
513
513
|
|
|
514
|
-
subgraph
|
|
514
|
+
subgraph OP_NET["OP_NET - Built-in Migration"]
|
|
515
515
|
O1["Schnorr (current)"] --> O2["Dual-key period"]
|
|
516
516
|
O2 --> O3["ML-DSA only"]
|
|
517
517
|
O3 --> O4["Quantum secure"]
|
|
@@ -531,7 +531,7 @@ function verify(bytes32 hash, uint8 v, bytes32 r, bytes32 s) external view retur
|
|
|
531
531
|
|
|
532
532
|
// CRITICAL VULNERABILITIES:
|
|
533
533
|
// - ECDSA is broken by Shor's algorithm
|
|
534
|
-
// - No
|
|
534
|
+
// - No update path to quantum-safe algorithms
|
|
535
535
|
// - All funds signed with exposed public keys at risk
|
|
536
536
|
// - No way to add ML-DSA or other PQC algorithms
|
|
537
537
|
}
|
|
@@ -540,10 +540,10 @@ function verify(bytes32 hash, uint8 v, bytes32 r, bytes32 s) external view retur
|
|
|
540
540
|
// EIP proposals for PQC have not been implemented
|
|
541
541
|
```
|
|
542
542
|
|
|
543
|
-
####
|
|
543
|
+
#### OP_NET: Built-in Quantum Resistance
|
|
544
544
|
|
|
545
545
|
```typescript
|
|
546
|
-
//
|
|
546
|
+
// OP_NET - Quantum-resistant
|
|
547
547
|
@method(
|
|
548
548
|
{ name: 'hash', type: ABIDataTypes.BYTES32 },
|
|
549
549
|
{ name: 'signature', type: ABIDataTypes.BYTES },
|
|
@@ -596,7 +596,7 @@ contract SolidityContract {
|
|
|
596
596
|
```
|
|
597
597
|
|
|
598
598
|
```typescript
|
|
599
|
-
//
|
|
599
|
+
// OP_NET - Automatic key access
|
|
600
600
|
@final
|
|
601
601
|
class OPNetContract extends OP_NET {
|
|
602
602
|
|
|
@@ -615,12 +615,12 @@ class OPNetContract extends OP_NET {
|
|
|
615
615
|
}
|
|
616
616
|
```
|
|
617
617
|
|
|
618
|
-
### Why
|
|
618
|
+
### Why OP_NET for Quantum Security?
|
|
619
619
|
|
|
620
|
-
| Solidity Limitation |
|
|
620
|
+
| Solidity Limitation | OP_NET Solution |
|
|
621
621
|
|---------------------|----------------|
|
|
622
622
|
| ECDSA only (quantum vulnerable) | ML-DSA (quantum resistant) |
|
|
623
|
-
| No
|
|
623
|
+
| No update path | Built-in consensus migration |
|
|
624
624
|
| Must store large keys manually | Automatic key loading |
|
|
625
625
|
| No NIST PQC algorithms | FIPS 204 ML-DSA |
|
|
626
626
|
| Single key per address | Dual-key architecture |
|
|
@@ -630,9 +630,9 @@ class OPNetContract extends OP_NET {
|
|
|
630
630
|
|
|
631
631
|
### Cost Comparison
|
|
632
632
|
|
|
633
|
-
| Operation | Solidity |
|
|
633
|
+
| Operation | Solidity | OP_NET Cost | Notes |
|
|
634
634
|
|-----------|----------|------------|-------|
|
|
635
|
-
| Store ML-DSA public key | Not practical (1,312 bytes) | 0 |
|
|
635
|
+
| Store ML-DSA public key | Not practical (1,312 bytes) | 0 | OP_NET loads automatically |
|
|
636
636
|
| Store ML-DSA signature | Not practical (2,420 bytes) | N/A | Not stored, verified |
|
|
637
637
|
| Quantum-safe verification | Not possible | Standard | No additional cost |
|
|
638
638
|
| Key migration | Contract redeploy | Consensus-managed | No user action needed |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Signature Verification
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OP_NET supports multiple signature schemes for authentication and authorization. This guide covers Schnorr signatures, ECDSA (secp256k1), quantum-resistant ML-DSA, and common verification patterns.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
@@ -41,7 +41,7 @@ const isValidBTC: bool = Blockchain.verifyBitcoinECDSASignature(
|
|
|
41
41
|
|
|
42
42
|
## Signature Scheme Comparison
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
OP_NET supports Schnorr, ECDSA (secp256k1), and quantum-resistant ML-DSA signatures:
|
|
45
45
|
|
|
46
46
|
```mermaid
|
|
47
47
|
---
|
|
@@ -49,7 +49,7 @@ config:
|
|
|
49
49
|
theme: dark
|
|
50
50
|
---
|
|
51
51
|
flowchart LR
|
|
52
|
-
subgraph
|
|
52
|
+
subgraph OP_NET["OP_NET Signature Verification"]
|
|
53
53
|
subgraph ECDSA["ECDSA - Legacy (Deprecated)"]
|
|
54
54
|
E1["Public Key: 33/64/65 bytes"]
|
|
55
55
|
E2["Signature: 64 or 65 bytes"]
|
|
@@ -118,7 +118,7 @@ config:
|
|
|
118
118
|
---
|
|
119
119
|
sequenceDiagram
|
|
120
120
|
participant Contract as Contract
|
|
121
|
-
participant Blockchain as
|
|
121
|
+
participant Blockchain as OP_NET Runtime
|
|
122
122
|
participant SchnorrVerifier as Schnorr Verifier
|
|
123
123
|
participant ExtendedAddress as ExtendedAddress
|
|
124
124
|
|
|
@@ -161,7 +161,7 @@ config:
|
|
|
161
161
|
---
|
|
162
162
|
sequenceDiagram
|
|
163
163
|
participant Contract as Contract
|
|
164
|
-
participant Blockchain as
|
|
164
|
+
participant Blockchain as OP_NET Runtime
|
|
165
165
|
participant MLDSAVerifier as ML-DSA Verifier
|
|
166
166
|
participant Address as Address
|
|
167
167
|
|
|
@@ -205,11 +205,11 @@ const isValid = Blockchain.verifyMLDSASignature(
|
|
|
205
205
|
| Level3 | ML-DSA-65 | 1,952 bytes | 3,309 bytes | Category 3 (~AES-192) |
|
|
206
206
|
| Level5 | ML-DSA-87 | 2,592 bytes | 4,627 bytes | Category 5 (~AES-256) |
|
|
207
207
|
|
|
208
|
-
**
|
|
208
|
+
**OP_NET uses ML-DSA-44 (Level2) by default.**
|
|
209
209
|
|
|
210
210
|
## ECDSA Verification (Deprecated)
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
OP_NET now supports ECDSA (secp256k1) signatures for backward compatibility with Ethereum and Bitcoin ecosystems. These methods are **deprecated** and only available when `UNSAFE_QUANTUM_SIGNATURES_ALLOWED` consensus flag is set.
|
|
213
213
|
|
|
214
214
|
### Ethereum ECDSA (ecrecover model)
|
|
215
215
|
|
|
@@ -257,7 +257,7 @@ Both ECDSA methods emit a runtime `WARNING` and are gated behind the `UNSAFE_QUA
|
|
|
257
257
|
|
|
258
258
|
## Keccak-256 Hashing
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
OP_NET includes a built-in Keccak-256 implementation (Ethereum-compatible, pre-NIST). This is useful for ECDSA-related workflows, Ethereum-style function selectors, and EIP-712 typed data hashing.
|
|
261
261
|
|
|
262
262
|
```typescript
|
|
263
263
|
import { keccak256, keccak256Concat, functionSelector, ethAddressFromPubKey } from '@btc-vision/btc-runtime/runtime';
|
|
@@ -375,7 +375,7 @@ class SignatureContract extends OP_NET {
|
|
|
375
375
|
|
|
376
376
|
// Create the message to verify
|
|
377
377
|
const message = new BytesWriter(32);
|
|
378
|
-
message.writeString('Hello,
|
|
378
|
+
message.writeString('Hello, OP_NET!');
|
|
379
379
|
const messageHash = sha256(message.getBuffer());
|
|
380
380
|
|
|
381
381
|
// Verify using consensus-aware method
|
|
@@ -420,13 +420,13 @@ class SignatureContract extends OP_NET {
|
|
|
420
420
|
}
|
|
421
421
|
```
|
|
422
422
|
|
|
423
|
-
## Solidity vs
|
|
423
|
+
## Solidity vs OP_NET: Signature Verification Comparison
|
|
424
424
|
|
|
425
|
-
|
|
425
|
+
OP_NET provides significant advantages over Solidity for signature verification, including quantum-resistant signatures, native Schnorr support, and simplified APIs.
|
|
426
426
|
|
|
427
427
|
### Feature Comparison Table
|
|
428
428
|
|
|
429
|
-
| Feature | Solidity/EVM |
|
|
429
|
+
| Feature | Solidity/EVM | OP_NET | OP_NET Advantage |
|
|
430
430
|
|---------|--------------|-------|-----------------|
|
|
431
431
|
| **Primary Signature Scheme** | ECDSA (secp256k1) | Schnorr + ML-DSA + ECDSA | Multiple schemes, quantum-resistant option |
|
|
432
432
|
| **Quantum Resistance** | Not supported | ML-DSA (FIPS 204) | Future-proof security |
|
|
@@ -441,7 +441,7 @@ OPNet provides significant advantages over Solidity for signature verification,
|
|
|
441
441
|
|
|
442
442
|
### Signature Scheme Comparison
|
|
443
443
|
|
|
444
|
-
| Aspect | Solidity (ECDSA) |
|
|
444
|
+
| Aspect | Solidity (ECDSA) | OP_NET (ECDSA) | OP_NET (Schnorr) | OP_NET (ML-DSA) |
|
|
445
445
|
|--------|------------------|---------------|-----------------|----------------|
|
|
446
446
|
| Algorithm | secp256k1 ECDSA | secp256k1 ECDSA | BIP340 Schnorr | FIPS 204 Lattice |
|
|
447
447
|
| Public Key Size | 33 or 65 bytes | 33, 64, or 65 bytes | 32 bytes | 1,312+ bytes |
|
|
@@ -454,7 +454,7 @@ OPNet provides significant advantages over Solidity for signature verification,
|
|
|
454
454
|
|
|
455
455
|
### Capability Matrix
|
|
456
456
|
|
|
457
|
-
| Capability | Solidity |
|
|
457
|
+
| Capability | Solidity | OP_NET |
|
|
458
458
|
|------------|:--------:|:-----:|
|
|
459
459
|
| ECDSA verification (Ethereum ecrecover) | Yes | Yes (deprecated) |
|
|
460
460
|
| ECDSA verification (Bitcoin direct) | No | Yes (deprecated) |
|
|
@@ -502,10 +502,10 @@ function verifySignature(
|
|
|
502
502
|
}
|
|
503
503
|
```
|
|
504
504
|
|
|
505
|
-
####
|
|
505
|
+
#### OP_NET: verifySignature
|
|
506
506
|
|
|
507
507
|
```typescript
|
|
508
|
-
//
|
|
508
|
+
// OP_NET - verifySignature (simple, safe)
|
|
509
509
|
function verifySignature(
|
|
510
510
|
signer: Address,
|
|
511
511
|
signature: Uint8Array,
|
|
@@ -557,7 +557,7 @@ function permit(
|
|
|
557
557
|
```
|
|
558
558
|
|
|
559
559
|
```typescript
|
|
560
|
-
//
|
|
560
|
+
// OP_NET
|
|
561
561
|
@method(
|
|
562
562
|
{ name: 'owner', type: ABIDataTypes.ADDRESS },
|
|
563
563
|
{ name: 'spender', type: ABIDataTypes.ADDRESS },
|
|
@@ -593,7 +593,7 @@ public permit(calldata: Calldata): BytesWriter {
|
|
|
593
593
|
|
|
594
594
|
### Security Comparison
|
|
595
595
|
|
|
596
|
-
| Security Aspect | Solidity |
|
|
596
|
+
| Security Aspect | Solidity | OP_NET |
|
|
597
597
|
|-----------------|----------|-------|
|
|
598
598
|
| Signature Malleability | Vulnerable (requires OpenZeppelin) | Not vulnerable |
|
|
599
599
|
| Replay Attack Protection | Manual nonce tracking | Built-in patterns |
|
|
@@ -604,7 +604,7 @@ public permit(calldata: Calldata): BytesWriter {
|
|
|
604
604
|
|
|
605
605
|
### Implementation Complexity
|
|
606
606
|
|
|
607
|
-
| Task | Solidity Lines of Code |
|
|
607
|
+
| Task | Solidity Lines of Code | OP_NET Lines of Code |
|
|
608
608
|
|------|:----------------------:|:-------------------:|
|
|
609
609
|
| Basic signature verification | ~15 | ~5 |
|
|
610
610
|
| EIP-712 domain separator | ~20 | ~15 |
|
|
@@ -626,7 +626,7 @@ function verify(bytes32 hash, uint8 v, bytes32 r, bytes32 s) public view returns
|
|
|
626
626
|
```
|
|
627
627
|
|
|
628
628
|
```typescript
|
|
629
|
-
//
|
|
629
|
+
// OP_NET - Clear boolean result
|
|
630
630
|
function verify(hash: Uint8Array, signature: Uint8Array, signer: Address): bool {
|
|
631
631
|
// Returns false on invalid signature - no silent failures
|
|
632
632
|
// Returns false on malformed input - no exceptions
|
|
@@ -634,9 +634,9 @@ function verify(hash: Uint8Array, signature: Uint8Array, signer: Address): bool
|
|
|
634
634
|
}
|
|
635
635
|
```
|
|
636
636
|
|
|
637
|
-
### Why
|
|
637
|
+
### Why OP_NET for Signature Verification?
|
|
638
638
|
|
|
639
|
-
| Solidity Limitation |
|
|
639
|
+
| Solidity Limitation | OP_NET Solution |
|
|
640
640
|
|---------------------|----------------|
|
|
641
641
|
| ECDSA only | ECDSA + Schnorr + ML-DSA support |
|
|
642
642
|
| No quantum resistance | Built-in ML-DSA (FIPS 204) |
|
|
@@ -26,7 +26,7 @@ const timestamp = Blockchain.block.medianTimestamp;
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
**Solidity Comparison:**
|
|
29
|
-
| Solidity |
|
|
29
|
+
| Solidity | OP_NET |
|
|
30
30
|
|----------|-------|
|
|
31
31
|
| `block.number` | `Blockchain.block.number` |
|
|
32
32
|
| `block.timestamp` | `Blockchain.block.medianTimestamp` |
|
|
@@ -51,7 +51,7 @@ const unsafeAllowed = Blockchain.tx.consensus.unsafeSignaturesAllowed();
|
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
**Solidity Comparison:**
|
|
54
|
-
| Solidity |
|
|
54
|
+
| Solidity | OP_NET |
|
|
55
55
|
|----------|-------|
|
|
56
56
|
| `msg.sender` | `Blockchain.tx.sender` |
|
|
57
57
|
| `tx.origin` | `Blockchain.tx.origin` |
|
|
@@ -70,7 +70,7 @@ const deployer = Blockchain.contractDeployer;
|
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
**Solidity Comparison:**
|
|
73
|
-
| Solidity |
|
|
73
|
+
| Solidity | OP_NET |
|
|
74
74
|
|----------|-------|
|
|
75
75
|
| `address(this)` | `Blockchain.contractAddress` |
|
|
76
76
|
|
|
@@ -90,7 +90,7 @@ if (Blockchain.network === Networks.Mainnet) {
|
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
**Solidity Comparison:**
|
|
93
|
-
| Solidity |
|
|
93
|
+
| Solidity | OP_NET |
|
|
94
94
|
|----------|-------|
|
|
95
95
|
| `block.chainid` | `Blockchain.chainId` |
|
|
96
96
|
|
|
@@ -280,7 +280,7 @@ public getBalance(address: Address): u256 {
|
|
|
280
280
|
```
|
|
281
281
|
|
|
282
282
|
**Solidity Comparison:**
|
|
283
|
-
| Solidity |
|
|
283
|
+
| Solidity | OP_NET |
|
|
284
284
|
|----------|-------|
|
|
285
285
|
| `mapping(address => uint256) balances` | `AddressMemoryMap` with pointer |
|
|
286
286
|
| `balances[addr] = value` | `Blockchain.setStorageAt(pointerHash, value)` |
|
|
@@ -389,7 +389,7 @@ sequenceDiagram
|
|
|
389
389
|
```
|
|
390
390
|
|
|
391
391
|
**Solidity Comparison:**
|
|
392
|
-
| Solidity |
|
|
392
|
+
| Solidity | OP_NET |
|
|
393
393
|
|----------|-------|
|
|
394
394
|
| `target.call(data)` | `Blockchain.call(target, calldata, false)` |
|
|
395
395
|
| `target.functionCall(args)` | `Blockchain.call(target, calldata, true)` |
|
|
@@ -449,16 +449,16 @@ updateContractFromExisting(
|
|
|
449
449
|
| `calldata` | `BytesWriter \| null` | Optional calldata passed to VM (default: empty) |
|
|
450
450
|
|
|
451
451
|
```typescript
|
|
452
|
-
// Basic
|
|
452
|
+
// Basic update (not recommended without access control)
|
|
453
453
|
Blockchain.updateContractFromExisting(newBytecodeAddress);
|
|
454
454
|
|
|
455
455
|
// With calldata
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
Blockchain.updateContractFromExisting(newBytecodeAddress,
|
|
456
|
+
const updateData = new BytesWriter(32);
|
|
457
|
+
updateData.writeU256(migrationVersion);
|
|
458
|
+
Blockchain.updateContractFromExisting(newBytecodeAddress, updateData);
|
|
459
459
|
```
|
|
460
460
|
|
|
461
|
-
> **Warning:** This is a privileged operation. Always implement access control (e.g., `onlyDeployer`) and consider using the `
|
|
461
|
+
> **Warning:** This is a privileged operation. Always implement access control (e.g., `onlyDeployer`) and consider using the `Updatable` base class or `UpdatablePlugin` for timelock protection. See [Contract Updates](../advanced/updatable) for details.
|
|
462
462
|
|
|
463
463
|
## Cryptographic Operations
|
|
464
464
|
|
|
@@ -740,7 +740,7 @@ if (Blockchain.isContract(targetAddress)) {
|
|
|
740
740
|
```
|
|
741
741
|
|
|
742
742
|
**Solidity Comparison:**
|
|
743
|
-
| Solidity |
|
|
743
|
+
| Solidity | OP_NET |
|
|
744
744
|
|----------|-------|
|
|
745
745
|
| `address.code.length > 0` | `Blockchain.isContract(address)` |
|
|
746
746
|
|
|
@@ -772,7 +772,7 @@ const hash = Blockchain.getBlockHash(Blockchain.block.number - 10);
|
|
|
772
772
|
> **Warning:** Only ~256 recent blocks available. Older blocks return zeros.
|
|
773
773
|
|
|
774
774
|
**Solidity Comparison:**
|
|
775
|
-
| Solidity |
|
|
775
|
+
| Solidity | OP_NET |
|
|
776
776
|
|----------|-------|
|
|
777
777
|
| `blockhash(blockNumber)` | `Blockchain.getBlockHash(blockNumber)` |
|
|
778
778
|
|
|
@@ -791,7 +791,7 @@ Blockchain.emit(new TransferEvent(from, to, amount));
|
|
|
791
791
|
```
|
|
792
792
|
|
|
793
793
|
**Solidity Comparison:**
|
|
794
|
-
| Solidity |
|
|
794
|
+
| Solidity | OP_NET |
|
|
795
795
|
|----------|-------|
|
|
796
796
|
| `emit Transfer(from, to, amount)` | `Blockchain.emit(new TransferEvent(from, to, amount))` |
|
|
797
797
|
|
|
@@ -507,7 +507,7 @@ class Unpaused extends NetEvent {
|
|
|
507
507
|
|
|
508
508
|
### Indexed-Style Events
|
|
509
509
|
|
|
510
|
-
While
|
|
510
|
+
While OP_NET doesn't have Solidity's indexed parameters, you can structure events for efficient filtering:
|
|
511
511
|
|
|
512
512
|
```typescript
|
|
513
513
|
@final
|
|
@@ -621,7 +621,7 @@ class Withdraw extends NetEvent {
|
|
|
621
621
|
|
|
622
622
|
## Solidity Comparison
|
|
623
623
|
|
|
624
|
-
| Solidity |
|
|
624
|
+
| Solidity | OP_NET |
|
|
625
625
|
|----------|-------|
|
|
626
626
|
| `event Transfer(address indexed from, address indexed to, uint256 value)` | `class TransferredEvent extends NetEvent` |
|
|
627
627
|
| `emit Transfer(from, to, value)` | `emitEvent(new TransferredEvent(operator, from, to, value))` |
|
|
@@ -151,7 +151,7 @@ public override onDeployment(calldata: Calldata): void {
|
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
**Solidity Comparison:**
|
|
154
|
-
| Solidity (ERC20) |
|
|
154
|
+
| Solidity (ERC20) | OP_NET (OP20) |
|
|
155
155
|
|------------------|--------------|
|
|
156
156
|
| `constructor(string name, string symbol)` | `onDeployment(calldata)` + `instantiate()` |
|
|
157
157
|
|
|
@@ -292,7 +292,7 @@ protected _allowance(owner: Address, spender: Address): u256
|
|
|
292
292
|
```
|
|
293
293
|
|
|
294
294
|
**Solidity Comparison:**
|
|
295
|
-
| Solidity (ERC20) |
|
|
295
|
+
| Solidity (ERC20) | OP_NET (OP20) |
|
|
296
296
|
|------------------|--------------|
|
|
297
297
|
| `function name() view returns (string)` | `name(calldata): BytesWriter` |
|
|
298
298
|
| `function balanceOf(address) view returns (uint256)` | `balanceOf(calldata): BytesWriter` |
|
|
@@ -405,7 +405,7 @@ sequenceDiagram
|
|
|
405
405
|
```
|
|
406
406
|
|
|
407
407
|
**Solidity Comparison:**
|
|
408
|
-
| Solidity (ERC20) |
|
|
408
|
+
| Solidity (ERC20) | OP_NET (OP20) |
|
|
409
409
|
|------------------|--------------|
|
|
410
410
|
| `function transfer(address to, uint256 amount) returns (bool)` | `transfer(calldata): BytesWriter` |
|
|
411
411
|
| `function transferFrom(address from, address to, uint256 amount) returns (bool)` | `transferFrom(calldata): BytesWriter` |
|
|
@@ -553,7 +553,7 @@ sequenceDiagram
|
|
|
553
553
|
```
|
|
554
554
|
|
|
555
555
|
**Solidity Comparison:**
|
|
556
|
-
| Solidity (ERC20) |
|
|
556
|
+
| Solidity (ERC20) | OP_NET (OP20) |
|
|
557
557
|
|------------------|--------------|
|
|
558
558
|
| `function approve(address, uint256) returns (bool)` | N/A (use increaseAllowance/decreaseAllowance) |
|
|
559
559
|
| `function increaseAllowance(address, uint256) returns (bool)` | `increaseAllowance(calldata): BytesWriter` |
|
|
@@ -639,7 +639,7 @@ protected _spendAllowance(owner: Address, spender: Address, amount: u256): void
|
|
|
639
639
|
```
|
|
640
640
|
|
|
641
641
|
**Solidity Comparison:**
|
|
642
|
-
| Solidity (ERC20) |
|
|
642
|
+
| Solidity (ERC20) | OP_NET (OP20) |
|
|
643
643
|
|------------------|--------------|
|
|
644
644
|
| `function _mint(address, uint256) internal` | `_mint(Address, u256): void` |
|
|
645
645
|
| `function _burn(address, uint256) internal` | `_burn(Address, u256): void` |
|
|
@@ -781,7 +781,7 @@ class BurnedEvent extends NetEvent {
|
|
|
781
781
|
```
|
|
782
782
|
|
|
783
783
|
**Solidity Comparison:**
|
|
784
|
-
| Solidity (ERC20) |
|
|
784
|
+
| Solidity (ERC20) | OP_NET (OP20) |
|
|
785
785
|
|------------------|--------------|
|
|
786
786
|
| `event Transfer(address indexed from, address indexed to, uint256 value)` | `TransferredEvent(operator, from, to, amount)` |
|
|
787
787
|
| `event Approval(address indexed owner, address indexed spender, uint256 value)` | `ApprovedEvent(owner, spender, amount)` |
|
|
@@ -887,7 +887,7 @@ export class MyToken extends OP20 {
|
|
|
887
887
|
|
|
888
888
|
## Solidity Comparison Summary
|
|
889
889
|
|
|
890
|
-
| Solidity (ERC20) |
|
|
890
|
+
| Solidity (ERC20) | OP_NET (OP20) |
|
|
891
891
|
|------------------|--------------|
|
|
892
892
|
| `constructor(...)` | `onDeployment(calldata)` |
|
|
893
893
|
| `function name()` | `name(): string` |
|
|
@@ -136,7 +136,7 @@ public instantiate(
|
|
|
136
136
|
| `skipDeployerVerification` | `boolean` | Skip deployer check (default: false) |
|
|
137
137
|
|
|
138
138
|
**Solidity Comparison:**
|
|
139
|
-
| Solidity (ERC721) |
|
|
139
|
+
| Solidity (ERC721) | OP_NET (OP721) |
|
|
140
140
|
|-------------------|---------------|
|
|
141
141
|
| `constructor(string name, string symbol)` | `onDeployment(calldata)` + `instantiate()` |
|
|
142
142
|
|
|
@@ -223,7 +223,7 @@ public isApprovedForAll(owner: Address, operator: Address): bool
|
|
|
223
223
|
```
|
|
224
224
|
|
|
225
225
|
**Solidity Comparison:**
|
|
226
|
-
| Solidity (ERC721) |
|
|
226
|
+
| Solidity (ERC721) | OP_NET (OP721) |
|
|
227
227
|
|-------------------|---------------|
|
|
228
228
|
| `function ownerOf(uint256) view returns (address)` | `ownerOf(u256): Address` |
|
|
229
229
|
| `function balanceOf(address) view returns (uint256)` | `balanceOf(Address): u256` |
|
|
@@ -366,7 +366,7 @@ sequenceDiagram
|
|
|
366
366
|
```
|
|
367
367
|
|
|
368
368
|
**Solidity Comparison:**
|
|
369
|
-
| Solidity (ERC721) |
|
|
369
|
+
| Solidity (ERC721) | OP_NET (OP721) |
|
|
370
370
|
|-------------------|---------------|
|
|
371
371
|
| `function transferFrom(address, address, uint256)` | `safeTransferFrom(calldata): BytesWriter` |
|
|
372
372
|
| `function safeTransferFrom(address, address, uint256, bytes)` | `safeTransferFrom(calldata): BytesWriter` |
|
|
@@ -403,7 +403,7 @@ public setApprovalForAll(calldata: Calldata): BytesWriter
|
|
|
403
403
|
| approved | bool | 1 byte |
|
|
404
404
|
|
|
405
405
|
**Solidity Comparison:**
|
|
406
|
-
| Solidity (ERC721) |
|
|
406
|
+
| Solidity (ERC721) | OP_NET (OP721) |
|
|
407
407
|
|-------------------|---------------|
|
|
408
408
|
| `function approve(address, uint256)` | `approve(calldata): BytesWriter` |
|
|
409
409
|
| `function setApprovalForAll(address, bool)` | `setApprovalForAll(calldata): BytesWriter` |
|
|
@@ -515,7 +515,7 @@ protected _isApprovedForAll(owner: Address, operator: Address): boolean
|
|
|
515
515
|
```
|
|
516
516
|
|
|
517
517
|
**Solidity Comparison:**
|
|
518
|
-
| Solidity (ERC721) |
|
|
518
|
+
| Solidity (ERC721) | OP_NET (OP721) |
|
|
519
519
|
|-------------------|---------------|
|
|
520
520
|
| `function _mint(address, uint256) internal` | `_mint(Address, u256): void` |
|
|
521
521
|
| `function _burn(uint256) internal` | `_burn(u256): void` |
|
|
@@ -693,7 +693,7 @@ class URIEvent extends NetEvent {
|
|
|
693
693
|
```
|
|
694
694
|
|
|
695
695
|
**Solidity Comparison:**
|
|
696
|
-
| Solidity (ERC721) |
|
|
696
|
+
| Solidity (ERC721) | OP_NET (OP721) |
|
|
697
697
|
|-------------------|---------------|
|
|
698
698
|
| `event Transfer(address indexed, address indexed, uint256 indexed)` | `TransferredEvent(operator, from, to, tokenId)` |
|
|
699
699
|
| `event Approval(address indexed, address indexed, uint256 indexed)` | `ApprovedEvent(owner, spender, tokenId)` |
|
|
@@ -802,7 +802,7 @@ export class MyNFT extends OP721 {
|
|
|
802
802
|
|
|
803
803
|
## Solidity Comparison Summary
|
|
804
804
|
|
|
805
|
-
| Solidity (ERC721) |
|
|
805
|
+
| Solidity (ERC721) | OP_NET (OP721) |
|
|
806
806
|
|-------------------|---------------|
|
|
807
807
|
| `constructor(name, symbol)` | `instantiate(new OP721InitParameters(name, symbol, baseURI, maxSupply, ...))` |
|
|
808
808
|
| `function ownerOf(uint256)` | `ownerOf(u256): Address` |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Storage API Reference
|
|
2
2
|
|
|
3
|
-
Storage classes provide persistent state management for
|
|
3
|
+
Storage classes provide persistent state management for OP_NET smart contracts.
|
|
4
4
|
|
|
5
5
|
## Import
|
|
6
6
|
|
|
@@ -714,7 +714,7 @@ public updateBoth(a: u256, b: u256): void {
|
|
|
714
714
|
|
|
715
715
|
## Solidity Comparison
|
|
716
716
|
|
|
717
|
-
| Solidity |
|
|
717
|
+
| Solidity | OP_NET Storage |
|
|
718
718
|
|----------|---------------|
|
|
719
719
|
| `uint256 public value` | `StoredU256` |
|
|
720
720
|
| `mapping(address => uint256)` | `AddressMemoryMap` |
|