Skip to content

Commit a9013fd

Browse files
authored
fix leak (#3181)
Signed-off-by: master_jedy <yura.zarudny@gmail.com>
1 parent 9f595ae commit a9013fd

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

target_chains/ton/contracts/contracts/Pyth.fc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,11 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
340340
cell custom_payload_cell = begin_cell().store_slice(custom_payload).end_cell();
341341
response = response.store_ref(price_feeds_cell).store_slice(sender_address).store_ref(custom_payload_cell);
342342

343-
int num_price_feeds = price_feeds.tlen();
344-
345-
;; Calculate all fees
346-
int compute_fee = get_compute_fee(WORKCHAIN, get_gas_consumed());
343+
;; Calculate update fee
347344
int update_fee = single_update_fee * price_feeds.tlen();
348345

349-
;; Calculate total fees and remaining excess
350-
int total_fees = compute_fee + update_fee;
351-
int excess = msg_value - total_fees;
346+
;; Reserve current_balance + fee
347+
raw_reserve(update_fee, RESERVE_MODE::INCREASE_BY_ORIGINAL_BALANCE);
352348

353349
;; SECURITY: Integrators MUST validate that messages are from this Pyth contract
354350
;; in their receive function. Otherwise, attackers could:
@@ -362,11 +358,11 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
362358
send_raw_message(begin_cell()
363359
.store_uint(0x18, 6)
364360
.store_slice(target_address)
365-
.store_coins(excess)
361+
.store_coins(0)
366362
.store_uint(1, MSG_SERIALIZE_BITS)
367363
.store_ref(response.end_cell())
368364
.end_cell(),
369-
0);
365+
SENDMODE::CARRY_ALL_BALANCE);
370366
}
371367

372368
;; Helper function to parse price IDs from a slice, handling cell chain traversal

target_chains/ton/contracts/contracts/common/constants.fc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ const int PRICE_FEED_BITS = 256 + 224 + 224;
5252
- Masterchain: 1 gas = 10000 nanotons = 0.00001 TON (25x more expensive)
5353
-}
5454
const int WORKCHAIN = 0;
55+
56+
const int RESERVE_MODE::INCREASE_BY_ORIGINAL_BALANCE = 4;
57+
const int SENDMODE::CARRY_ALL_BALANCE = 128;

0 commit comments

Comments
 (0)