Skip to content

Commit 7bf23f2

Browse files
authored
add comments and ignore bounced messages (#2151)
1 parent f3ec2b5 commit 7bf23f2

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

target_chains/ton/contracts/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,21 @@ CHAIN_ID=<CHAIN-ID> npx blueprint run --custom https://testnet.toncenter.com/api
3030
### Add a new contract
3131

3232
`npx blueprint create ContractName` or `yarn blueprint create ContractName`
33+
34+
## Important Note on Message Handling
35+
36+
When using the Pyth price feed in the recommended flow (User/App -> Pyth -> Protocol), be aware that:
37+
38+
### Security Warning ⚠️
39+
40+
**CRITICAL**: Integrators MUST validate the sender address in their receive function to ensure messages are coming from the Pyth Oracle contract. Failure to do so could allow attackers to:
41+
42+
- Send invalid price responses
43+
- Impersonate users via the sender_address and custom_payload fields
44+
- Potentially drain the protocol
45+
46+
### Message Bouncing Behavior
47+
48+
- If the target protocol bounces the message (e.g., due to invalid custom payload or other errors), the forwarded TON will remain in the Pyth contract and will not be automatically refunded to the original sender.
49+
- This could be significant when dealing with large amounts of TON (e.g., in DeFi operations).
50+
- Integrators should implement proper error handling and refund mechanisms in their applications.

target_chains/ton/contracts/contracts/Main.fc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
;; Get sender address from message
2020
slice cs = in_msg_full.begin_parse();
21-
cs~skip_bits(4); ;; skip flags
21+
int flags = cs~load_uint(4);
22+
if (flags & 1) { ;; ignore all bounced messages
23+
return ();
24+
}
2225
slice sender_address = cs~load_msg_addr(); ;; load sender address
2326

2427
;; * The remainder of the message body is specific for each supported value of `op`.

target_chains/ton/contracts/contracts/Pyth.fc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,15 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
349349
int total_fees = compute_fee + update_fee;
350350
int excess = msg_value - total_fees;
351351

352+
;; SECURITY: Integrators MUST validate that messages are from this Pyth contract
353+
;; in their receive function. Otherwise, attackers could:
354+
;; 1. Send invalid price responses
355+
;; 2. Impersonate users via sender_address and custom_payload fields
356+
;; 3. Potentially drain the protocol
357+
;;
358+
;; Note: This message is bounceable. If the target contract rejects the message,
359+
;; the excess TON will remain in this contract and won't be automatically refunded to the
360+
;; original sender. Integrators should handle failed requests and refunds in their implementation.
352361
send_raw_message(begin_cell()
353362
.store_uint(0x18, 6)
354363
.store_slice(target_address)

0 commit comments

Comments
 (0)