blueprint-tsa 1.0.2 → 1.0.4

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,12 +1,12 @@
1
1
  {
2
2
  "name": "blueprint-tsa",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "TSA plugin for TON Blueprint",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist",
9
- "checkers"
9
+ "src/checkers"
10
10
  ],
11
11
  "license": "MIT",
12
12
  "scripts": {
@@ -0,0 +1,37 @@
1
+ #include "imports/stdlib.fc";
2
+ #include "imports/tsa_functions.fc";
3
+
4
+ global int opcode;
5
+ global slice initial_sender;
6
+
7
+ () on_internal_message_send(int balance, int msg_value, cell in_msg_full, slice msg_body, int input_id) impure method_id {
8
+ slice cs = in_msg_full.begin_parse();
9
+ cs~load_uint(4); ;; flags
10
+ initial_sender = cs~load_msg_addr(); ;; src
11
+ slice contract_address = cs~load_msg_addr(); ;; dst
12
+ cs~load_coins(); ;; value
13
+
14
+ int cur_opcode = msg_body~load_uint(32);
15
+ tsa_assert(cur_opcode == opcode);
16
+
17
+ cell c4 = tsa_get_c4(1);
18
+ tsa_make_slice_independent_from_random_addresses(c4.begin_parse());
19
+ tsa_make_slice_independent_from_random_addresses(contract_address);
20
+ }
21
+
22
+ () main() impure {
23
+ tsa_forbid_failures();
24
+
25
+ slice ds = get_data().begin_parse();
26
+ opcode = ds~load_uint(32);
27
+
28
+ tsa_send_internal_message(1, 0);
29
+
30
+ tsa_allow_failures();
31
+
32
+ int random_sender = tsa_mk_int(1, -1);
33
+ throw_if(1001, ~ random_sender);
34
+
35
+ tsa_make_address_random(initial_sender);
36
+ throw(1000);
37
+ }
@@ -0,0 +1,20 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "inOpcodeToDestination": {},
5
+ "other": {
6
+ "type": "out_opcodes",
7
+ "outOpcodeToDestination": {},
8
+ "other": [2]
9
+ }
10
+ },
11
+ {
12
+ "id": 2,
13
+ "inOpcodeToDestination": {},
14
+ "other": {
15
+ "type": "out_opcodes",
16
+ "outOpcodeToDestination": {},
17
+ "other": [1]
18
+ }
19
+ }
20
+ ]
@@ -0,0 +1,35 @@
1
+ #include "imports/stdlib.fc";
2
+ #include "imports/tsa_functions.fc";
3
+
4
+ const int error::failed_to_handle_bounce = 1000;
5
+ const int error::sent_messages_on_bounce = 1000;
6
+
7
+ global int counter;
8
+
9
+ () on_compute_phase_exit(cell c5, int exit_code, int compute_fee, int contract_id) impure method_id {
10
+ if (contract_id != 1) {
11
+ return ();
12
+ }
13
+ ;; on the first entrance, we are ending the execution triggered by checker
14
+ ;; on the consecutive entrance, we are ending the execution triggered by bounced message
15
+ if (counter > 0) {
16
+ throw_if(error::failed_to_handle_bounce, exit_code > 0);
17
+ int sent_messages_on_bounce = c5.begin_parse().slice_refs() > 0;
18
+ throw_if(error::sent_messages_on_bounce, sent_messages_on_bounce);
19
+ }
20
+ counter += 1;
21
+ }
22
+
23
+ () on_internal_message_send(int balance, int msg_value, cell in_msg_full, slice msg_body, int input_id) impure method_id {
24
+ counter = 0;
25
+ tsa_forbid_failures();
26
+ slice cs = in_msg_full.begin_parse();
27
+ int flags = cs~load_uint(4);
28
+ tsa_assert_not(flags & 1);
29
+
30
+ tsa_allow_failures();
31
+ }
32
+
33
+ () main() impure {
34
+ tsa_send_internal_message(1, 0);
35
+ }
@@ -0,0 +1,8 @@
1
+ #include "imports/stdlib.fc";
2
+
3
+ () recv_internal(int msg_value, cell in_msg_full, slice in_msg) impure {
4
+ var data = in_msg~load_ref();
5
+ var code = in_msg~load_ref();
6
+ set_data(data);
7
+ set_code(code);
8
+ }
@@ -0,0 +1,50 @@
1
+ #include "imports/stdlib.fc";
2
+ #include "imports/tsa_functions.fc";
3
+
4
+ global slice initial_sender;
5
+ global int initial_value;
6
+ global int received_value;
7
+ global int max_value;
8
+
9
+ () on_internal_message_send(int balance, int msg_value, cell in_msg_full, slice msg_body, int input_id) impure method_id {
10
+ slice cs = in_msg_full.begin_parse();
11
+ cs~load_uint(4); ;; flags
12
+ slice sender = cs~load_msg_addr(); ;; src
13
+ cs~load_msg_addr(); ;; dst
14
+ initial_value = cs~load_coins(); ;; value
15
+
16
+ tsa_assert(equal_slice_bits(sender, initial_sender));
17
+ tsa_assert(initial_value <= max_value);
18
+ }
19
+
20
+ () on_out_message(cell msg_full, slice msg_body, int receiver_contract_id, int sender_contract_id) impure method_id {
21
+ if ((sender_contract_id != 1) | (receiver_contract_id != -1)) {
22
+ return ();
23
+ }
24
+
25
+ slice cs = msg_full.begin_parse();
26
+ cs~skip_bits(4); ;; message headers
27
+ cs~load_msg_addr(); ;; src address
28
+ slice dest = cs~load_msg_addr();
29
+ int value = cs~load_grams();
30
+
31
+ if (equal_slice_bits(dest, initial_sender)) {
32
+ received_value += value;
33
+ }
34
+ }
35
+
36
+ () main() impure {
37
+ received_value = 0;
38
+
39
+ tsa_forbid_failures();
40
+
41
+ slice ds = get_data().begin_parse();
42
+ initial_sender = ds~load_msg_addr();
43
+ max_value = ds~load_coins();
44
+
45
+ tsa_send_internal_message(1, 0);
46
+
47
+ tsa_allow_failures();
48
+
49
+ throw_if(1000, received_value > initial_value);
50
+ }
@@ -0,0 +1,48 @@
1
+ #include "imports/stdlib.fc";
2
+ #include "imports/tsa_functions.fc";
3
+
4
+ global slice initial_sender;
5
+ global slice contract_address;
6
+ global int initial_value;
7
+ global int received_value;
8
+
9
+ () on_internal_message_send(int balance, int msg_value, cell in_msg_full, slice msg_body, int input_id) impure method_id {
10
+ slice cs = in_msg_full.begin_parse();
11
+ cs~load_uint(4); ;; flags
12
+ initial_sender = cs~load_msg_addr(); ;; src
13
+ contract_address = cs~load_msg_addr(); ;; dst
14
+ initial_value = cs~load_coins(); ;; value
15
+
16
+ cell c4 = tsa_get_c4(1);
17
+ tsa_make_address_random(initial_sender);
18
+ tsa_make_slice_independent_from_random_addresses(c4.begin_parse());
19
+ tsa_make_slice_independent_from_random_addresses(contract_address);
20
+ }
21
+
22
+ () on_out_message(cell msg_full, slice msg_body, int receiver_contract_id, int sender_contract_id) impure method_id {
23
+ if ((sender_contract_id != 1) | (receiver_contract_id != -1)) {
24
+ return ();
25
+ }
26
+
27
+ slice cs = msg_full.begin_parse();
28
+ cs~skip_bits(4); ;; message headers
29
+ cs~load_msg_addr(); ;; src address
30
+ slice dest = cs~load_msg_addr();
31
+ int value = cs~load_grams();
32
+
33
+ if (equal_slice_bits(dest, initial_sender)) {
34
+ received_value += value;
35
+ }
36
+ }
37
+
38
+ () main() impure {
39
+ received_value = 0;
40
+
41
+ tsa_forbid_failures();
42
+
43
+ tsa_send_internal_message(1, 0);
44
+
45
+ tsa_allow_failures();
46
+
47
+ throw_if(1000, received_value > initial_value);
48
+ }