@btc-vision/btc-runtime 1.4.6 → 1.4.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/btc-runtime",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "scripts": {
@@ -65,12 +65,13 @@ export class StoredAddressArray {
65
65
  */
66
66
  @inline
67
67
  public get(index: u64): Address {
68
- if (index >= this._length) {
69
- throw new Revert('Get operation failed: Index out of bounds.');
68
+ if (index > this.MAX_LENGTH) {
69
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
70
70
  }
71
71
 
72
72
  const slotIndex: u32 = <u32>index;
73
73
  this.ensureValues(slotIndex);
74
+
74
75
  const value = this._values.get(slotIndex);
75
76
  return value ? value : this.defaultValue;
76
77
  }
@@ -189,8 +190,8 @@ export class StoredAddressArray {
189
190
  * @param {u64} index - The global index of the Address value to delete.
190
191
  */
191
192
  public delete(index: u64): void {
192
- if (index >= this._length) {
193
- throw new Revert('Delete operation failed: Index out of bounds.');
193
+ if (index > this.MAX_LENGTH) {
194
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
194
195
  }
195
196
 
196
197
  const slotIndex: u32 = <u32>index;
@@ -64,13 +64,15 @@ export class StoredBooleanArray {
64
64
  */
65
65
  @inline
66
66
  public get(index: u64): bool {
67
- if (index >= this._length) {
68
- return false;
67
+ if (index > this.MAX_LENGTH) {
68
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
69
69
  }
70
70
 
71
71
  const slotIndex: u64 = index / 256; // Each slot holds 256 bits
72
72
  const bitIndex: u16 = <u16>(index % 256); // 0 to 255
73
+
73
74
  this.ensureValues(slotIndex);
75
+
74
76
  const slotValue = this._values.get(slotIndex);
75
77
  if (slotValue) {
76
78
  return this.getBit(slotValue, bitIndex);
@@ -121,6 +123,7 @@ export class StoredBooleanArray {
121
123
  const effectiveIndex: u64 = this._startIndex + newIndex;
122
124
  const wrappedIndex: u64 =
123
125
  effectiveIndex < this.MAX_LENGTH ? effectiveIndex : effectiveIndex % this.MAX_LENGTH;
126
+
124
127
  const slotIndex: u64 = wrappedIndex / 256;
125
128
  const bitIndex: u8 = <u8>(wrappedIndex % 256);
126
129
 
@@ -145,8 +148,8 @@ export class StoredBooleanArray {
145
148
  * @param {u64} index - The global index of the boolean value to delete.
146
149
  */
147
150
  public delete(index: u64): void {
148
- if (index >= this._length) {
149
- throw new Revert('Delete operation failed: Index out of bounds.');
151
+ if (index > this.MAX_LENGTH) {
152
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
150
153
  }
151
154
 
152
155
  const slotIndex: u64 = index / 256;
@@ -64,13 +64,15 @@ export class StoredU128Array {
64
64
  */
65
65
  @inline
66
66
  public get(index: u64): u128 {
67
- if (index >= this._length) {
68
- return u128.Zero;
67
+ if (index > this.MAX_LENGTH) {
68
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
69
69
  }
70
70
 
71
71
  const slotIndex: u32 = <u32>(index / 2); // Each slot holds two u128s
72
72
  const subIndex: u8 = <u8>(index % 2); // 0 or 1
73
+
73
74
  this.ensureValues(slotIndex);
75
+
74
76
  const slotValues = this._values.get(slotIndex);
75
77
  if (slotValues) {
76
78
  return slotValues[subIndex];
@@ -142,9 +144,8 @@ export class StoredU128Array {
142
144
  * @param {u64} index - The global index of the u128 value to delete.
143
145
  */
144
146
  public delete(index: u64): void {
145
- if (index >= this._length) {
146
- // If the index is out of bounds, revert the transaction
147
- throw new Revert('Delete operation failed: Index out of bounds.');
147
+ if (index > this.MAX_LENGTH) {
148
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
148
149
  }
149
150
 
150
151
  const slotIndex: u32 = <u32>(index / 2);
@@ -64,13 +64,15 @@ export class StoredU16Array {
64
64
  */
65
65
  @inline
66
66
  public get(index: u64): u16 {
67
- if (index >= this._length) {
68
- return 0;
67
+ if (index > this.MAX_LENGTH) {
68
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
69
69
  }
70
70
 
71
71
  const slotIndex: u64 = index / 16; // Each slot holds sixteen u16s
72
72
  const subIndex: u8 = <u8>(index % 16); // 0 to 15
73
+
73
74
  this.ensureValues(slotIndex);
75
+
74
76
  const slotValues = this._values.get(slotIndex);
75
77
  return slotValues ? slotValues[subIndex] : 0;
76
78
  }
@@ -138,8 +140,8 @@ export class StoredU16Array {
138
140
  * @param {u64} index - The global index of the u16 value to delete.
139
141
  */
140
142
  public delete(index: u64): void {
141
- if (index >= this._length) {
142
- throw new Revert('Delete operation failed: Index out of bounds.');
143
+ if (index > this.MAX_LENGTH) {
144
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
143
145
  }
144
146
 
145
147
  const slotIndex: u64 = index / 16;
@@ -65,12 +65,13 @@ export class StoredU256Array {
65
65
  */
66
66
  @inline
67
67
  public get(index: u64): u256 {
68
- if (index >= this._length) {
69
- return u256.Zero;
68
+ if (index > this.MAX_LENGTH) {
69
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
70
70
  }
71
71
 
72
72
  const slotIndex: u32 = <u32>index;
73
73
  this.ensureValues(slotIndex);
74
+
74
75
  const value = this._values.get(slotIndex);
75
76
  return value ? value : u256.Zero;
76
77
  }
@@ -157,8 +158,8 @@ export class StoredU256Array {
157
158
  * @param {u64} index - The global index of the u256 value to delete.
158
159
  */
159
160
  public delete(index: u64): void {
160
- if (index >= this._length) {
161
- throw new Revert('Delete operation failed: Index out of bounds.');
161
+ if (index > this.MAX_LENGTH) {
162
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
162
163
  }
163
164
 
164
165
  const slotIndex: u32 = <u32>index;
@@ -65,13 +65,15 @@ export class StoredU32Array {
65
65
  */
66
66
  @inline
67
67
  public get(index: u64): u32 {
68
- if (index >= this._length) {
69
- return 0;
68
+ if (index > this.MAX_LENGTH) {
69
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
70
70
  }
71
71
 
72
72
  const slotIndex: u64 = index / 8; // Each slot holds 8 u32s
73
73
  const subIndex: u8 = <u8>(index % 8); // 0..7
74
+
74
75
  this.ensureValues(slotIndex);
76
+
75
77
  const slotValues = this._values.get(slotIndex);
76
78
  return slotValues ? slotValues[subIndex] : 0;
77
79
  }
@@ -139,8 +141,8 @@ export class StoredU32Array {
139
141
  * @param {u64} index - The global index of the u32 value to delete.
140
142
  */
141
143
  public delete(index: u64): void {
142
- if (index >= this._length) {
143
- throw new Revert('Delete operation failed: Index out of bounds.');
144
+ if (index > this.MAX_LENGTH) {
145
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
144
146
  }
145
147
 
146
148
  const slotIndex: u64 = index / 8;
@@ -63,13 +63,15 @@ export class StoredU8Array {
63
63
  */
64
64
  @inline
65
65
  public get(index: u64): u8 {
66
- if (index >= this._length) {
67
- return 0;
66
+ if (index > this.MAX_LENGTH) {
67
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
68
68
  }
69
69
 
70
70
  const slotIndex: u64 = index / 32; // Each slot holds thirty-two u8s
71
71
  const subIndex: u8 = <u8>(index % 32);
72
+
72
73
  this.ensureValues(slotIndex);
74
+
73
75
  const slotValues = this._values.get(slotIndex);
74
76
  return slotValues ? slotValues[subIndex] : 0;
75
77
  }
@@ -134,8 +136,8 @@ export class StoredU8Array {
134
136
  * @param {u64} index - The global index of the u8 value to delete.
135
137
  */
136
138
  public delete(index: u64): void {
137
- if (index >= this._length) {
138
- throw new Revert('Delete operation failed: Index out of bounds.');
139
+ if (index > this.MAX_LENGTH) {
140
+ throw new Revert('Operation failed: Index exceeds maximum allowed value.');
139
141
  }
140
142
 
141
143
  const slotIndex: u64 = index / 32;