-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtonnel.fc
393 lines (323 loc) · 23.1 KB
/
tonnel.fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#include "imports/merkleTree.fc";
#include "jetton/imports/jetton-utils.fc";
#include "jetton/imports/op-codes.fc";
const ONE_TON = 1000000000;
const const::tx_fee_send_jetton = 40000000; ;; 0.04 TON
const const::tx_fee_send_tree = 30000000; ;; 0.04 TON
const SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE = 64;
() mint_tonnel(slice recepient, int amount, slice JETTON_MASTER_ADDRESS) impure inline {
if (amount == 0) {
return ();
}
var msg = begin_cell()
.store_uint(0x18, 6) ;; nobounce - int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 011000
.store_slice(JETTON_MASTER_ADDRESS)
.store_coins(const::tx_fee_send_jetton)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_uint(op::mint(), 32)
.store_uint(0, 64)
.store_slice(recepient)
.store_coins(20000000)
.store_ref(
begin_cell().store_uint(op::internal_transfer(), 32)
.store_uint(0, 64)
.store_coins(amount)
.store_slice(JETTON_MASTER_ADDRESS)
.store_uint(0, 200)
.store_uint(0, 67)
.store_coins(0)
.store_uint(0, 1)
.end_cell()
);
send_raw_message(msg.end_cell(), 2); ;; paying fees, revert on errors
}
() send_message_tonnel_tree(slice recepient, builder payload) impure inline {
var msg = begin_cell()
.store_uint(0x18, 6) ;; nobounce - int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 011000
.store_slice(recepient)
.store_coins(const::tx_fee_send_tree)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.store_builder(payload);
send_raw_message(msg.end_cell(), 2); ;; paying fees, revert on errors
}
() send_ton(slice recepient, int amount, int mode) impure inline {
var msg = begin_cell()
.store_uint(0x10, 6)
.store_slice(recepient)
.store_grams(amount)
.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
.end_cell();
send_raw_message(msg, mode);
}
() emit_log_simple (int event_id, slice data) impure inline {
var msg = begin_cell()
.store_uint (12, 4) ;; ext_out_msg_info$11 src:MsgAddressInt ()
.store_uint (1, 2)
.store_uint (256, 9)
.store_uint(event_id, 256)
.store_uint(0, 64 + 32 + 2) ;; created_lt, created_at, init:Maybe, body:Either
.store_slice(data)
.end_cell();
send_raw_message(msg, 0);
}
(int) check_proof_for_insert(int old_root, int new_root, int commitment, int pathIndices, slice insert_proof) impure inline {
slice alf1 = begin_cell().store_uint(182000286537471, 48).store_uint(188678401565571, 48).store_uint(187245209450396, 48).store_uint(127518005434324, 48).store_uint(144397100865470, 48).store_uint(258741821310885, 48).store_uint(125665759774218, 48).store_uint(36382829990144, 48).end_cell().begin_parse();
slice IC0 = begin_cell().store_uint(149463881306625, 48).store_uint(144872300902732, 48).store_uint(174187054867017, 48).store_uint(116683277427982, 48).store_uint(265686967952922, 48).store_uint(252921879845267, 48).store_uint(114778485693866, 48).store_uint(5303972209837, 48).end_cell().begin_parse();
slice IC1 = begin_cell().store_uint(163889391969450, 48).store_uint(246380033874386, 48).store_uint(73095240576401, 48).store_uint(93872595764167, 48).store_uint(209061551175750, 48).store_uint(145133340025488, 48).store_uint(118965754737971, 48).store_uint(114963008012871, 48).end_cell().begin_parse();
slice IC2 = begin_cell().store_uint(154611330325417, 48).store_uint(56883882533380, 48).store_uint(256864073646890, 48).store_uint(110223718526805, 48).store_uint(41488761585151, 48).store_uint(66949550052602, 48).store_uint(59725992543201, 48).store_uint(60822399158111, 48).end_cell().begin_parse();
slice IC3 = begin_cell().store_uint(204323902231497, 48).store_uint(146515902261225, 48).store_uint(223686418609716, 48).store_uint(63159927913005, 48).store_uint(266511227424255, 48).store_uint(139647823215357, 48).store_uint(243275058806357, 48).store_uint(113688717611142, 48).end_cell().begin_parse();
slice IC4 = begin_cell().store_uint(183046732570304, 48).store_uint(73751093200306, 48).store_uint(222619922391300, 48).store_uint(264954189415027, 48).store_uint(63818347814842, 48).store_uint(185189879229344, 48).store_uint(215937361595168, 48).store_uint(212335368650295, 48).end_cell().begin_parse();
slice beta2 = begin_cell().store_uint(45268298785829999156800790826, 96).store_uint(49616257531946340397706624184, 96).store_uint(21860288103068343353898458482, 96).store_uint(44130212597109342573800170705, 96).store_uint(4047260717587677040649332350, 96).store_uint(38438004468883114874440114862, 96).store_uint(37382830912273952379501564462, 96).store_uint(68660724947650442889836600213, 96).end_cell().begin_parse();
slice gamma2 = begin_cell().store_uint(45765300665918301128790692768, 96).store_uint(42137484379184671317244818970, 96).store_uint(56280794141317933024253112594, 96).store_uint(6059577009407902906031811454, 96).store_uint(709198854518927808499549479, 96).store_uint(14165060894806320894179293954, 96).store_uint(55805278558791767872231965478, 96).store_uint(52000413785700509085167893944, 96).end_cell().begin_parse();
slice delta2 = begin_cell().store_uint(57404885677640579730243374799, 96).store_uint(74640312393593044018703206431, 96).store_uint(72169551985828096175287641873, 96).store_uint(73191377323043092450051400364, 96).store_uint(2166075833178725585951546652, 96).store_uint(27864811610718394234613231021, 96).store_uint(5303551526686084678103393224, 96).store_uint(16202961803211306031003898654, 96).end_cell().begin_parse();
cell A_cell = insert_proof~load_ref();
cell B_cell = insert_proof~load_ref();
cell C_cell = insert_proof~load_ref();
slice A = A_cell.begin_parse();
slice B = B_cell.begin_parse();
slice C = C_cell.begin_parse();
slice vk_x = IC0;
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC1, old_root));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC2, new_root));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC3, commitment));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC4, pathIndices));
slice neg_a = bls_g1_negate(A);
int success = bls_pairing_check(neg_a,
B,
alf1,
beta2,
vk_x,
gamma2,
C,
delta2,
4);
ifnot (success) {
return 0;
}
return 1;
}
;; recv_internal is the main function of the contract and is called when it receives a message from other contracts
() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure {
if (in_msg_body.slice_empty?()) { ;; ignore all empty messages
return ();
}
slice cs = in_msg_full.begin_parse();
int flags = cs~load_uint(4);
if (flags & 1) { ;; ignore all bounced messages
return ();
}
slice sender_address = cs~load_msg_addr();
(cell merkle, cell fee_info, cell nullifiers, cell stucks) = load_data(); ;; here we populate the storage variables
slice fee_info_slice = fee_info.begin_parse();
slice fee_recepient = fee_info_slice~load_msg_addr();
slice tonnel_jetton_master_address = fee_info_slice~load_msg_addr();
int fee_percent = fee_info_slice~load_uint(10);
int tonnel_mint_amount_deposit = fee_info_slice~load_uint(32); ;; amount of jetton to mint for depositor, it should be multiplied by 10^9
int tonnel_mint_amount_relayer = fee_info_slice~load_uint(32); ;; amount of jetton to mint for relayers, it should be multiplied by 10^9
slice TONNEL_TREE = fee_info_slice~load_msg_addr();
int op = in_msg_body~load_uint(32); ;; by convention, the first 32 bits of incoming message is the op
int query_id = in_msg_body~load_uint(64); ;; also by convention, the next 64 bits contain the "query id", although this is not always the case
if (op == op::deposit) {
int fee_amount = POOL_SIZE * fee_percent / 1000; ;; protocol fee
throw_unless(error::fund, msg_value >= POOL_SIZE + fee_amount + const::tx_fee);
cell commitment = in_msg_body~load_ref();
slice commitment_slice = commitment.begin_parse();
int commitment_value = commitment_slice~load_uint(256);
int new_root = commitment_slice~load_uint(256);
int given_old_root = commitment_slice~load_uint(256);
cell insert_proof = commitment_slice~load_ref();
slice insert_proof_slice = insert_proof.begin_parse();
(int old_root, int last_index) = get_last_root_handler(merkle);
throw_unless(error::verify_failed_input, commitment_value < FIELD_SIZE);
throw_unless(error::verify_failed_input, new_root < FIELD_SIZE);
int check = 0;
if (given_old_root == old_root){
check = check_proof_for_insert(old_root, new_root, commitment_value, last_index, insert_proof_slice);
}
if (check == 0) {
stucks~udict_set(256, commitment_value, begin_cell().store_uint(commitment_value, 256).end_cell().begin_parse());
} else {
(int index, merkle) = insert(new_root, merkle);
emit_log_simple(op::deposit, begin_cell().store_uint(0 ,8).store_uint(commitment_value, 256).store_uint(index, 32).end_cell().begin_parse());
}
if (fee_amount > 0) {
send_ton(fee_recepient, fee_amount, 1);
}
mint_tonnel(sender_address, tonnel_mint_amount_deposit * ONE_TON / 100, tonnel_jetton_master_address);
send_message_tonnel_tree(TONNEL_TREE,
begin_cell()
.store_uint(0x888, 32)
.store_uint(0, 64)
.store_ref(
begin_cell().store_uint(commitment_value, 256).store_uint(now(), 32).end_cell()
)
);
save_data(merkle, fee_info, nullifiers, stucks);
return ();
}
if (op == op::withdraw) {
;;
;;
;; Proof inputs
;;
;;
cell withdraw_info = in_msg_body~load_ref();
slice withdraw_info_slice1 = withdraw_info.begin_parse();
int root = withdraw_info_slice1~load_uint(256);
int nullifier_hash = withdraw_info_slice1~load_uint(256);
int fee_coef = withdraw_info_slice1~load_uint(10);
cell addresses = withdraw_info_slice1~load_ref();
slice addresses_slice = addresses.begin_parse();
slice recipient = addresses_slice~load_msg_addr();
throw_unless(error::verify_failed_double_spend, is_unknown_nullifier(nullifier_hash, nullifiers));
throw_unless(error::verify_failed_input, root < FIELD_SIZE);
throw_unless(error::verify_failed_input, nullifier_hash < FIELD_SIZE);
throw_unless(error::verify_failed_fee, fee_coef < 1000);
throw_unless(error::verify_failed_root, is_known_root(root));
;; Verifying Key constants
slice alf1 = begin_cell().store_uint(182000286537471, 48).store_uint(188678401565571, 48).store_uint(187245209450396, 48).store_uint(127518005434324, 48).store_uint(144397100865470, 48).store_uint(258741821310885, 48).store_uint(125665759774218, 48).store_uint(36382829990144, 48).end_cell().begin_parse();
slice IC0 = begin_cell().store_uint(198693471336772, 48).store_uint(15156426526669, 48).store_uint(21195839689806, 48).store_uint(134982884807240, 48).store_uint(98831944029365, 48).store_uint(259765280790088, 48).store_uint(226730109320416, 48).store_uint(68580818820928, 48).end_cell().begin_parse();
slice IC1 = begin_cell().store_uint(176967888897437, 48).store_uint(52716870066022, 48).store_uint(266882219203136, 48).store_uint(188956541049375, 48).store_uint(9638093056127, 48).store_uint(67879553530711, 48).store_uint(230356572703382, 48).store_uint(141548705617042, 48).end_cell().begin_parse();
slice IC2 = begin_cell().store_uint(185395607204924, 48).store_uint(103443686280834, 48).store_uint(16299229901343, 48).store_uint(112743106922236, 48).store_uint(67855685651818, 48).store_uint(19837995827628, 48).store_uint(5441989873390, 48).store_uint(68958062110528, 48).end_cell().begin_parse();
slice IC3 = begin_cell().store_uint(191936250497323, 48).store_uint(102852184355624, 48).store_uint(24212641576709, 48).store_uint(49960405572007, 48).store_uint(18362271019258, 48).store_uint(136287956340028, 48).store_uint(1904901475255, 48).store_uint(217912711665299, 48).end_cell().begin_parse();
slice IC4 = begin_cell().store_uint(147302141626805, 48).store_uint(120430951176259, 48).store_uint(71432139964580, 48).store_uint(205694061489863, 48).store_uint(151837152275069, 48).store_uint(13848984095571, 48).store_uint(278746640718118, 48).store_uint(253311207974946, 48).end_cell().begin_parse();
slice beta2 = begin_cell().store_uint(45268298785829999156800790826, 96).store_uint(49616257531946340397706624184, 96).store_uint(21860288103068343353898458482, 96).store_uint(44130212597109342573800170705, 96).store_uint(4047260717587677040649332350, 96).store_uint(38438004468883114874440114862, 96).store_uint(37382830912273952379501564462, 96).store_uint(68660724947650442889836600213, 96).end_cell().begin_parse();
slice gamma2 = begin_cell().store_uint(45765300665918301128790692768, 96).store_uint(42137484379184671317244818970, 96).store_uint(56280794141317933024253112594, 96).store_uint(6059577009407902906031811454, 96).store_uint(709198854518927808499549479, 96).store_uint(14165060894806320894179293954, 96).store_uint(55805278558791767872231965478, 96).store_uint(52000413785700509085167893944, 96).end_cell().begin_parse();
slice delta2 = begin_cell().store_uint(55611436019896542363365837820, 96).store_uint(36626239938280781222883835257, 96).store_uint(52040279991528111570885655812, 96).store_uint(2749671938796122801512470023, 96).store_uint(5914597108141076486454435704, 96).store_uint(13817988269852185537550968540, 96).store_uint(77612211829949484497625105164, 96).store_uint(61055469537419651796629832676, 96).end_cell().begin_parse();
cell A_cell = withdraw_info_slice1~load_ref();
cell B_cell = withdraw_info_slice1~load_ref();
cell C_cell = withdraw_info_slice1~load_ref();
slice A = A_cell.begin_parse();
slice B = B_cell.begin_parse();
slice C = C_cell.begin_parse();
slice vk_x = IC0;
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC1, root));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC2, nullifier_hash));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC3, recipient.preload_uint(256)));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC4, fee_coef));
slice neg_a = bls_g1_negate(A);
int success = bls_pairing_check(neg_a,
B,
alf1,
beta2,
vk_x,
gamma2,
C,
delta2,
4);
ifnot (success) {
throw(error::verify_failed);
}
nullifiers~udict_set(256, nullifier_hash, begin_cell().end_cell().begin_parse());
int fee_amount = fee_coef * POOL_SIZE / 1000;
send_ton(recipient, POOL_SIZE - fee_amount, 1);
send_ton(sender_address, fee_amount, 1);
mint_tonnel(sender_address, tonnel_mint_amount_relayer * ONE_TON / 100, tonnel_jetton_master_address);
save_data(merkle, fee_info, nullifiers, stucks);
emit_log_simple(op::withdraw, begin_cell().store_uint(1 ,8).store_uint(nullifier_hash, 256).store_slice(recipient).store_uint(fee_coef, 32).end_cell().begin_parse());
send_message_tonnel_tree(TONNEL_TREE,
begin_cell()
.store_uint(0x777, 32)
.store_uint(0, 64)
.store_ref(
begin_cell().store_uint(nullifier_hash, 256).store_uint(now(), 32).end_cell()
)
);
send_ton(sender_address, 0, SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE);
return ();
}
if (op == op::remove_stuck_min) {
(stucks, _, slice val, int flag) = stucks.udict_delete_get_min(256);
throw_unless(error::empty_stuck, flag);
int commitment_value_stuck = val~load_uint(256);
cell commitment = in_msg_body~load_ref();
slice commitment_slice = commitment.begin_parse();
int commitment_value = commitment_slice~load_uint(256);
int new_root = commitment_slice~load_uint(256);
int given_old_root = commitment_slice~load_uint(256);
cell insert_proof = commitment_slice~load_ref();
slice insert_proof_slice = insert_proof.begin_parse();
(int old_root, int last_index) = get_last_root_handler(merkle);
throw_unless(error::verify_failed_input + 100, commitment_value_stuck == commitment_value);
throw_unless(error::verify_failed_input + 101, commitment_value < FIELD_SIZE);
throw_unless(error::verify_failed_input + 102, new_root < FIELD_SIZE);
int check = 0;
if (given_old_root == old_root){
check = check_proof_for_insert(old_root, new_root, commitment_value, last_index, insert_proof_slice);
}
throw_unless(error::verify_failed_input + 103, check == 1);
(int index, merkle) = insert(new_root, merkle);
emit_log_simple(op::deposit, begin_cell().store_uint(0 ,8).store_uint(commitment_value, 256).store_uint(index, 32).end_cell().begin_parse());
save_data(merkle, fee_info, nullifiers, stucks);
return ();
}
if (op == op::change_config) {
throw_unless(error::access_denied, equal_slices(sender_address, fee_recepient));
int new_fee_percent = in_msg_body~load_uint(10);
int new_tonnel_mint_amount_deposit = in_msg_body~load_uint(32);
int new_tonnel_mint_amount_relayer = in_msg_body~load_uint(32);
slice new_tonnel_tree = in_msg_body~load_msg_addr();
save_data(merkle,
begin_cell()
.store_slice(fee_recepient).store_slice(tonnel_jetton_master_address)
.store_uint(new_fee_percent, 10)
.store_uint(new_tonnel_mint_amount_deposit, 32)
.store_uint(new_tonnel_mint_amount_relayer, 32)
.store_slice(new_tonnel_tree)
.end_cell(),
nullifiers, stucks);
return ();
}
throw(0xffff); ;; if the message contains an op that is not known to this contract, we throw
}
(int) check_verify(slice in_msg_body) method_id {
in_msg_body~load_uint(32 + 64);
(_, _, cell nullifiers, _) = load_data(); ;; here we populate the storage variables
slice alf1 = begin_cell().store_uint(182000286537471, 48).store_uint(188678401565571, 48).store_uint(187245209450396, 48).store_uint(127518005434324, 48).store_uint(144397100865470, 48).store_uint(258741821310885, 48).store_uint(125665759774218, 48).store_uint(36382829990144, 48).end_cell().begin_parse();
slice IC0 = begin_cell().store_uint(198693471336772, 48).store_uint(15156426526669, 48).store_uint(21195839689806, 48).store_uint(134982884807240, 48).store_uint(98831944029365, 48).store_uint(259765280790088, 48).store_uint(226730109320416, 48).store_uint(68580818820928, 48).end_cell().begin_parse();
slice IC1 = begin_cell().store_uint(176967888897437, 48).store_uint(52716870066022, 48).store_uint(266882219203136, 48).store_uint(188956541049375, 48).store_uint(9638093056127, 48).store_uint(67879553530711, 48).store_uint(230356572703382, 48).store_uint(141548705617042, 48).end_cell().begin_parse();
slice IC2 = begin_cell().store_uint(185395607204924, 48).store_uint(103443686280834, 48).store_uint(16299229901343, 48).store_uint(112743106922236, 48).store_uint(67855685651818, 48).store_uint(19837995827628, 48).store_uint(5441989873390, 48).store_uint(68958062110528, 48).end_cell().begin_parse();
slice IC3 = begin_cell().store_uint(191936250497323, 48).store_uint(102852184355624, 48).store_uint(24212641576709, 48).store_uint(49960405572007, 48).store_uint(18362271019258, 48).store_uint(136287956340028, 48).store_uint(1904901475255, 48).store_uint(217912711665299, 48).end_cell().begin_parse();
slice IC4 = begin_cell().store_uint(147302141626805, 48).store_uint(120430951176259, 48).store_uint(71432139964580, 48).store_uint(205694061489863, 48).store_uint(151837152275069, 48).store_uint(13848984095571, 48).store_uint(278746640718118, 48).store_uint(253311207974946, 48).end_cell().begin_parse();
slice beta2 = begin_cell().store_uint(45268298785829999156800790826, 96).store_uint(49616257531946340397706624184, 96).store_uint(21860288103068343353898458482, 96).store_uint(44130212597109342573800170705, 96).store_uint(4047260717587677040649332350, 96).store_uint(38438004468883114874440114862, 96).store_uint(37382830912273952379501564462, 96).store_uint(68660724947650442889836600213, 96).end_cell().begin_parse();
slice gamma2 = begin_cell().store_uint(45765300665918301128790692768, 96).store_uint(42137484379184671317244818970, 96).store_uint(56280794141317933024253112594, 96).store_uint(6059577009407902906031811454, 96).store_uint(709198854518927808499549479, 96).store_uint(14165060894806320894179293954, 96).store_uint(55805278558791767872231965478, 96).store_uint(52000413785700509085167893944, 96).end_cell().begin_parse();
slice delta2 = begin_cell().store_uint(55611436019896542363365837820, 96).store_uint(36626239938280781222883835257, 96).store_uint(52040279991528111570885655812, 96).store_uint(2749671938796122801512470023, 96).store_uint(5914597108141076486454435704, 96).store_uint(13817988269852185537550968540, 96).store_uint(77612211829949484497625105164, 96).store_uint(61055469537419651796629832676, 96).end_cell().begin_parse();
cell withdraw_info = in_msg_body~load_ref();
slice withdraw_info_slice1 = withdraw_info.begin_parse();
int root = withdraw_info_slice1~load_uint(256);
int nullifier_hash = withdraw_info_slice1~load_uint(256);
int fee_coef = withdraw_info_slice1~load_uint(10);
cell addresses = withdraw_info_slice1~load_ref();
slice addresses_slice = addresses.begin_parse();
slice recipient = addresses_slice~load_msg_addr();
throw_unless(error::verify_failed_double_spend, is_unknown_nullifier(nullifier_hash, nullifiers));
throw_unless(error::verify_failed_input, root < FIELD_SIZE);
throw_unless(error::verify_failed_input, nullifier_hash < FIELD_SIZE);
throw_unless(error::verify_failed_fee, fee_coef < 1000);
throw_unless(error::verify_failed_root, is_known_root(root));
cell A_cell = withdraw_info_slice1~load_ref();
cell B_cell = withdraw_info_slice1~load_ref();
cell C_cell = withdraw_info_slice1~load_ref();
slice A = A_cell.begin_parse();
slice B = B_cell.begin_parse();
slice C = C_cell.begin_parse();
slice vk_x = IC0;
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC1, root));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC2, nullifier_hash));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC3, recipient.preload_uint(256)));
vk_x = bls_g1_add(vk_x, bls_g1_mul(IC4, fee_coef));
slice neg_a = bls_g1_negate(A);
int success = bls_pairing_check(neg_a,
B,
alf1,
beta2,
vk_x,
gamma2,
C,
delta2,
4);
ifnot (success) {
return 0;
}
return 1;
}