Skip to content

Commit 3e39a40

Browse files
feat: add publish time validation in parse_price_feed_updates_internal
- Add validation to check if publish times are within [min_allowed_publish_time, max_allowed_publish_time] range - Return PythReceiverError::PriceFeedNotFoundWithinRange (error code 16) when publish times are outside allowed range - Fix type casting from u64 to i64 for proper comparison with price_feed_message.publish_time Co-Authored-By: [email protected] <[email protected]>
1 parent 9e45927 commit 3e39a40

File tree

1 file changed

+8
-1
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+8
-1
lines changed

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,15 @@ impl PythReceiver {
382382

383383
match msg {
384384
Message::PriceFeedMessage(price_feed_message) => {
385+
let publish_time = price_feed_message.publish_time;
386+
387+
if (min_allowed_publish_time > 0 && publish_time < min_allowed_publish_time as i64) ||
388+
(max_allowed_publish_time > 0 && publish_time > max_allowed_publish_time as i64) {
389+
return Err(PythReceiverError::PriceFeedNotFoundWithinRange);
390+
}
391+
385392
let price_info_return = (
386-
U64::from(price_feed_message.publish_time),
393+
U64::from(publish_time),
387394
I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
388395
I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
389396
U64::from(price_feed_message.conf),

0 commit comments

Comments
 (0)