@btc-vision/btc-runtime 1.11.0-alpha → 1.11.0-alpha.2
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/package.json +1 -1
- package/runtime/buffer/BytesReader.ts +3 -1
- package/runtime/contracts/OP721.ts +1 -1
- package/runtime/contracts/Upgradeable.ts +1 -1
- package/runtime/generic/AddressMap.ts +14 -14
- package/runtime/generic/ExtendedAddressMap.ts +25 -27
- package/runtime/generic/MapUint8Array.ts +14 -14
- package/runtime/plugins/UpgradeablePlugin.ts +22 -22
- package/runtime/storage/arrays/StoredPackedArray.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/btc-runtime",
|
|
3
|
-
"version": "1.11.0-alpha",
|
|
3
|
+
"version": "1.11.0-alpha.2",
|
|
4
4
|
"description": "Bitcoin L1 Smart Contract Runtime for OPNet. Build decentralized applications on Bitcoin using AssemblyScript and WebAssembly. Fully audited.",
|
|
5
5
|
"main": "btc/index.ts",
|
|
6
6
|
"types": "btc/index.ts",
|
|
@@ -290,7 +290,9 @@ export class BytesReader {
|
|
|
290
290
|
* @returns A SchnorrSignature containing the address and signature
|
|
291
291
|
*/
|
|
292
292
|
public readSchnorrSignature(): SchnorrSignature {
|
|
293
|
-
this.verifyEnd(
|
|
293
|
+
this.verifyEnd(
|
|
294
|
+
this.currentOffset + EXTENDED_ADDRESS_BYTE_LENGTH + SCHNORR_SIGNATURE_BYTE_LENGTH,
|
|
295
|
+
);
|
|
294
296
|
|
|
295
297
|
const address = this.readExtendedAddress();
|
|
296
298
|
const signature = this.readBytes(SCHNORR_SIGNATURE_BYTE_LENGTH);
|
|
@@ -716,7 +716,7 @@ export abstract class OP721 extends ReentrancyGuard implements IOP721 {
|
|
|
716
716
|
}
|
|
717
717
|
|
|
718
718
|
protected _safeTransfer(from: Address, to: Address, tokenId: u256, data: Uint8Array): void {
|
|
719
|
-
this._transfer(from,
|
|
719
|
+
this._transfer(from, to, tokenId);
|
|
720
720
|
|
|
721
721
|
if (Blockchain.isContract(to)) {
|
|
722
722
|
this._checkOnOP721Received(from, to, tokenId, data);
|
|
@@ -8,9 +8,9 @@ import { Revert } from '../types/Revert';
|
|
|
8
8
|
import { BytesWriter } from '../buffer/BytesWriter';
|
|
9
9
|
import { EMPTY_POINTER } from '../math/bytes';
|
|
10
10
|
import {
|
|
11
|
-
UpgradeSubmittedEvent,
|
|
12
11
|
UpgradeAppliedEvent,
|
|
13
12
|
UpgradeCancelledEvent,
|
|
13
|
+
UpgradeSubmittedEvent,
|
|
14
14
|
} from '../events/upgradeable/UpgradeableEvents';
|
|
15
15
|
|
|
16
16
|
const pendingUpgradeAddressPointer: u16 = Blockchain.nextPointer;
|
|
@@ -99,20 +99,6 @@ export class AddressMap<V> implements IMap<Address, V> {
|
|
|
99
99
|
return -1;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
private isLastIndex(key: Uint8Array): bool {
|
|
103
|
-
if (this._lastIndex !== -1) {
|
|
104
|
-
const cachedKey = unchecked(this._keys[this._lastIndex]);
|
|
105
|
-
// Check length first, then full content equality
|
|
106
|
-
if (cachedKey.length === key.length) {
|
|
107
|
-
if (memory.compare(cachedKey.dataStart, key.dataStart, key.length) === 0) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
102
|
@inline
|
|
117
103
|
public has(key: Address): bool {
|
|
118
104
|
return this.indexOf(key) !== -1;
|
|
@@ -148,4 +134,18 @@ export class AddressMap<V> implements IMap<Address, V> {
|
|
|
148
134
|
public toString(): string {
|
|
149
135
|
return `Map(size=${this._keys.length})`;
|
|
150
136
|
}
|
|
137
|
+
|
|
138
|
+
private isLastIndex(key: Uint8Array): bool {
|
|
139
|
+
if (this._lastIndex !== -1) {
|
|
140
|
+
const cachedKey = unchecked(this._keys[this._lastIndex]);
|
|
141
|
+
// Check length first, then full content equality
|
|
142
|
+
if (cachedKey.length === key.length) {
|
|
143
|
+
if (memory.compare(cachedKey.dataStart, key.dataStart, key.length) === 0) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
151
|
}
|
|
@@ -67,9 +67,7 @@ export class ExtendedAddressMap<V> implements IMap<ExtendedAddress, V> {
|
|
|
67
67
|
if (load<u64>(key.dataStart) !== load<u64>(searchMldsaData)) continue;
|
|
68
68
|
|
|
69
69
|
// Quick prefix check on tweaked public key (first 8 bytes)
|
|
70
|
-
if (
|
|
71
|
-
load<u64>(key.tweakedPublicKey.dataStart) !== load<u64>(searchTweakedData)
|
|
72
|
-
)
|
|
70
|
+
if (load<u64>(key.tweakedPublicKey.dataStart) !== load<u64>(searchTweakedData))
|
|
73
71
|
continue;
|
|
74
72
|
|
|
75
73
|
// Full comparison of ML-DSA key hash (32 bytes)
|
|
@@ -85,30 +83,6 @@ export class ExtendedAddressMap<V> implements IMap<ExtendedAddress, V> {
|
|
|
85
83
|
return -1;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
private isLastIndex(key: ExtendedAddress): bool {
|
|
89
|
-
if (this._lastIndex !== -1) {
|
|
90
|
-
const cachedKey = unchecked(this._keys[this._lastIndex]);
|
|
91
|
-
|
|
92
|
-
// Check ML-DSA key hash equality
|
|
93
|
-
if (memory.compare(cachedKey.dataStart, key.dataStart, 32) !== 0) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Check tweaked public key equality
|
|
98
|
-
if (
|
|
99
|
-
memory.compare(
|
|
100
|
-
cachedKey.tweakedPublicKey.dataStart,
|
|
101
|
-
key.tweakedPublicKey.dataStart,
|
|
102
|
-
32,
|
|
103
|
-
) === 0
|
|
104
|
-
) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
86
|
@inline
|
|
113
87
|
public has(key: ExtendedAddress): bool {
|
|
114
88
|
return this.indexOf(key) !== -1;
|
|
@@ -144,4 +118,28 @@ export class ExtendedAddressMap<V> implements IMap<ExtendedAddress, V> {
|
|
|
144
118
|
public toString(): string {
|
|
145
119
|
return `ExtendedAddressMap(size=${this._keys.length})`;
|
|
146
120
|
}
|
|
121
|
+
|
|
122
|
+
private isLastIndex(key: ExtendedAddress): bool {
|
|
123
|
+
if (this._lastIndex !== -1) {
|
|
124
|
+
const cachedKey = unchecked(this._keys[this._lastIndex]);
|
|
125
|
+
|
|
126
|
+
// Check ML-DSA key hash equality
|
|
127
|
+
if (memory.compare(cachedKey.dataStart, key.dataStart, 32) !== 0) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Check tweaked public key equality
|
|
132
|
+
if (
|
|
133
|
+
memory.compare(
|
|
134
|
+
cachedKey.tweakedPublicKey.dataStart,
|
|
135
|
+
key.tweakedPublicKey.dataStart,
|
|
136
|
+
32,
|
|
137
|
+
) === 0
|
|
138
|
+
) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
147
145
|
}
|
|
@@ -107,20 +107,6 @@ export class MapUint8Array implements IMap<Uint8Array, Uint8Array> {
|
|
|
107
107
|
return -1;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
private isLastIndex(key: Uint8Array): bool {
|
|
111
|
-
if (this._lastIndex !== -1) {
|
|
112
|
-
const cachedKey = unchecked(this._keys[this._lastIndex]);
|
|
113
|
-
// Check length first, then full content equality
|
|
114
|
-
if (cachedKey.length === key.length) {
|
|
115
|
-
if (memory.compare(cachedKey.dataStart, key.dataStart, key.length) === 0) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
110
|
@inline
|
|
125
111
|
public has(key: Uint8Array): bool {
|
|
126
112
|
return this.indexOf(key) !== -1;
|
|
@@ -180,4 +166,18 @@ export class MapUint8Array implements IMap<Uint8Array, Uint8Array> {
|
|
|
180
166
|
public toString(): string {
|
|
181
167
|
return `Map(size=${this._keys.length})`;
|
|
182
168
|
}
|
|
169
|
+
|
|
170
|
+
private isLastIndex(key: Uint8Array): bool {
|
|
171
|
+
if (this._lastIndex !== -1) {
|
|
172
|
+
const cachedKey = unchecked(this._keys[this._lastIndex]);
|
|
173
|
+
// Check length first, then full content equality
|
|
174
|
+
if (cachedKey.length === key.length) {
|
|
175
|
+
if (memory.compare(cachedKey.dataStart, key.dataStart, key.length) === 0) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
183
|
}
|
|
@@ -11,9 +11,9 @@ import { ADDRESS_BYTE_LENGTH } from '../utils';
|
|
|
11
11
|
import { Calldata } from '../types';
|
|
12
12
|
import { EMPTY_POINTER } from '../math/bytes';
|
|
13
13
|
import {
|
|
14
|
-
UpgradeSubmittedEvent,
|
|
15
14
|
UpgradeAppliedEvent,
|
|
16
15
|
UpgradeCancelledEvent,
|
|
16
|
+
UpgradeSubmittedEvent,
|
|
17
17
|
} from '../events/upgradeable/UpgradeableEvents';
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -42,27 +42,6 @@ import {
|
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
export class UpgradeablePlugin extends Plugin {
|
|
45
|
-
// Method selectors
|
|
46
|
-
public static get SUBMIT_UPGRADE_SELECTOR(): Selector {
|
|
47
|
-
return encodeSelector('submitUpgrade(address)');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public static get APPLY_UPGRADE_SELECTOR(): Selector {
|
|
51
|
-
return encodeSelector('applyUpgrade(address)');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public static get CANCEL_UPGRADE_SELECTOR(): Selector {
|
|
55
|
-
return encodeSelector('cancelUpgrade()');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public static get PENDING_UPGRADE_SELECTOR(): Selector {
|
|
59
|
-
return encodeSelector('pendingUpgrade()');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public static get UPGRADE_DELAY_SELECTOR(): Selector {
|
|
63
|
-
return encodeSelector('upgradeDelay()');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
45
|
private readonly _pendingUpgradeAddress: StoredAddress;
|
|
67
46
|
private readonly _pendingUpgradeBlock: StoredU256;
|
|
68
47
|
private readonly _upgradeDelay: u64;
|
|
@@ -90,6 +69,27 @@ export class UpgradeablePlugin extends Plugin {
|
|
|
90
69
|
this._pendingUpgradeBlock = new StoredU256(blockPointer, EMPTY_POINTER);
|
|
91
70
|
}
|
|
92
71
|
|
|
72
|
+
// Method selectors
|
|
73
|
+
public static get SUBMIT_UPGRADE_SELECTOR(): Selector {
|
|
74
|
+
return encodeSelector('submitUpgrade(address)');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static get APPLY_UPGRADE_SELECTOR(): Selector {
|
|
78
|
+
return encodeSelector('applyUpgrade(address)');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public static get CANCEL_UPGRADE_SELECTOR(): Selector {
|
|
82
|
+
return encodeSelector('cancelUpgrade()');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public static get PENDING_UPGRADE_SELECTOR(): Selector {
|
|
86
|
+
return encodeSelector('pendingUpgrade()');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public static get UPGRADE_DELAY_SELECTOR(): Selector {
|
|
90
|
+
return encodeSelector('upgradeDelay()');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
93
|
/**
|
|
94
94
|
* Returns the pending upgrade source address.
|
|
95
95
|
*/
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
bigEndianAdd,
|
|
3
|
+
GET_EMPTY_BUFFER,
|
|
4
|
+
readLengthAndStartIndex,
|
|
5
|
+
writeLengthAndStartIndex,
|
|
6
|
+
} from '../../math/bytes';
|
|
2
7
|
import { Blockchain } from '../../env';
|
|
3
8
|
import { Revert } from '../../types/Revert';
|
|
4
9
|
import { encodePointer } from '../../math/abi';
|