@btc-vision/btc-runtime 1.0.13 → 1.0.14

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 CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  ## Introduction
13
13
 
14
- The OPNet Smart Contract Runtime contains all the necessary components to effectively create smart contracts for Bitcoin
14
+ The OPNet Smart Contract Runtime contains all the necessary components to effectively create smart contracts on Bitcoin
15
15
  L1. The runtime is written in AssemblyScript.
16
16
 
17
17
  ### Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/btc-runtime",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "types": "btc/index.ts",
@@ -299,7 +299,7 @@ export class BytesWriter {
299
299
 
300
300
  private fromAddress(value: Address): Uint8Array {
301
301
  if (value.length > i32(ADDRESS_BYTE_LENGTH)) {
302
- throw new Revert('Address is too long');
302
+ throw new Revert(`Address is too long ${value.length} > ${ADDRESS_BYTE_LENGTH} bytes`);
303
303
  }
304
304
 
305
305
  const bytes: Uint8Array = new Uint8Array(ADDRESS_BYTE_LENGTH);
@@ -81,6 +81,10 @@ export class BlockchainEnvironment {
81
81
  return this.currentBlock;
82
82
  }
83
83
 
84
+ public get blockNumberU64(): u64 {
85
+ return this.currentBlock.toU64();
86
+ }
87
+
84
88
  public callee(): Address {
85
89
  if (!this._callee) {
86
90
  throw this.error('Callee is required');
package/runtime/index.ts CHANGED
@@ -43,6 +43,7 @@ export * from './memory/MultiAddressMemoryMap';
43
43
 
44
44
  /** Storage */
45
45
  export * from './storage/StoredU256';
46
+ export * from './storage/StoredString';
46
47
 
47
48
  /** Universal */
48
49
  export * from './universal/ABIRegistry';
@@ -1,5 +1,5 @@
1
1
  import { Potential } from '../lang/Definitions';
2
2
 
3
- export const ADDRESS_BYTE_LENGTH: u8 = 64;
3
+ export const ADDRESS_BYTE_LENGTH: u8 = 66;
4
4
  export declare type Address = string;
5
5
  export declare type PotentialAddress = Potential<Address>;
@@ -19,6 +19,30 @@ export class SafeMath {
19
19
  return u256.sub(a, b);
20
20
  }
21
21
 
22
+ // Computes (a * b) % modulus with full precision
23
+ public static mulmod(a: u256, b: u256, modulus: u256): u256 {
24
+ if (u256.eq(modulus, u256.Zero)) throw new Error('SafeMath: modulo by zero');
25
+
26
+ const mul = SafeMath.mul(a, b);
27
+ return SafeMath.mod(mul, modulus);
28
+ }
29
+
30
+ @inline
31
+ @unsafe
32
+ @operator('%')
33
+ public static mod(a: u256, b: u256): u256 {
34
+ if (u256.eq(b, u256.Zero)) {
35
+ throw new Error('SafeMath: modulo by zero');
36
+ }
37
+
38
+ let result = a.clone();
39
+ while (u256.ge(result, b)) {
40
+ result = u256.sub(result, b);
41
+ }
42
+
43
+ return result;
44
+ }
45
+
22
46
  public static mul(a: u256, b: u256): u256 {
23
47
  if (a === SafeMath.ZERO || b === SafeMath.ZERO) {
24
48
  return SafeMath.ZERO;
@@ -37,7 +61,7 @@ export class SafeMath {
37
61
  @inline
38
62
  @unsafe
39
63
  @operator('/')
40
- static div(a: u256, b: u256): u256 {
64
+ public static div(a: u256, b: u256): u256 {
41
65
  if (b.isZero()) {
42
66
  throw new Error('Division by zero');
43
67
  }
@@ -110,7 +134,7 @@ export class SafeMath {
110
134
 
111
135
  @inline
112
136
  @unsafe
113
- static shl(value: u256, shift: i32): u256 {
137
+ public static shl(value: u256, shift: i32): u256 {
114
138
  if (shift == 0) {
115
139
  return value.clone();
116
140
  }