Skip to content

Commit 92a42e5

Browse files
committed
fix: abis, interfaces
1 parent aadb43b commit 92a42e5

File tree

8 files changed

+65
-63
lines changed

8 files changed

+65
-63
lines changed

target_chains/ethereum/contracts/contracts/pyth/Pyth.sol

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ abstract contract Pyth is
208208
if (k < context.priceIds.length && context.priceFeeds[k].id == 0) {
209209
uint publishTime = uint(priceInfo.publishTime);
210210
if (
211-
publishTime >= context.config.minPublishTime &&
212-
publishTime <= context.config.maxPublishTime &&
213-
(!context.config.checkUniqueness ||
214-
context.config.minPublishTime > prevPublishTime)
211+
publishTime >= context.minAllowedPublishTime &&
212+
publishTime <= context.maxAllowedPublishTime &&
213+
(!context.checkUniqueness ||
214+
context.minAllowedPublishTime > prevPublishTime)
215215
) {
216216
context.priceFeeds[k].id = priceId;
217217
context.priceFeeds[k].price.price = priceInfo.price;
@@ -231,7 +231,7 @@ abstract contract Pyth is
231231
function _processSingleUpdateDataBlob(
232232
bytes calldata singleUpdateData,
233233
PythInternalStructs.UpdateParseContext memory context
234-
) internal view {
234+
) internal view returns (uint64 numUpdates) {
235235
// Check magic number and length first
236236
if (
237237
singleUpdateData.length <= 4 ||
@@ -281,12 +281,18 @@ abstract contract Pyth is
281281
if (offset != encoded.length) {
282282
revert PythErrors.InvalidUpdateData();
283283
}
284+
285+
// Return the number of updates in this blob for tracking
286+
return merkleData.numUpdates;
284287
}
285288

286289
function parsePriceFeedUpdatesInternal(
287290
bytes[] calldata updateData,
288291
bytes32[] calldata priceIds,
289-
PythInternalStructs.ParseConfig memory config
292+
uint64 minAllowedPublishTime,
293+
uint64 maxAllowedPublishTime,
294+
bool checkUniqueness,
295+
bool checkUpdateDataIsMinimal
290296
)
291297
internal
292298
returns (
@@ -299,39 +305,38 @@ abstract contract Pyth is
299305
if (msg.value < requiredFee) revert PythErrors.InsufficientFee();
300306
}
301307

302-
// In minimal update data mode, revert if we have more or less updates than price IDs
303-
if (config.checkUpdateDataIsMinimal) {
304-
uint64 totalUpdatesAcrossBlobs = 0;
305-
for (uint i = 0; i < updateData.length; i++) {
306-
(uint offset, ) = extractUpdateTypeFromAccumulatorHeader(
307-
updateData[i]
308-
);
309-
310-
totalUpdatesAcrossBlobs += parseWormholeMerkleHeaderNumUpdates(
311-
updateData[i],
312-
offset
313-
);
314-
}
315-
if (totalUpdatesAcrossBlobs != priceIds.length) {
316-
revert PythErrors.InvalidArgument();
317-
}
318-
}
319-
320308
// Create the context struct that holds all shared parameters
321309
PythInternalStructs.UpdateParseContext memory context;
322310
context.priceIds = priceIds;
323-
context.config = config;
311+
context.minAllowedPublishTime = minAllowedPublishTime;
312+
context.maxAllowedPublishTime = maxAllowedPublishTime;
313+
context.checkUniqueness = checkUniqueness;
314+
context.checkUpdateDataIsMinimal = checkUpdateDataIsMinimal;
324315
context.priceFeeds = new PythStructs.PriceFeed[](priceIds.length);
325316
context.slots = new uint64[](priceIds.length);
326317

318+
// Track total updates for minimal update data check
319+
uint64 totalUpdatesAcrossBlobs = 0;
320+
327321
unchecked {
328322
// Process each update, passing the context struct
329323
// Parsed results will be filled in context.priceFeeds and context.slots
330324
for (uint i = 0; i < updateData.length; i++) {
331-
_processSingleUpdateDataBlob(updateData[i], context);
325+
totalUpdatesAcrossBlobs += _processSingleUpdateDataBlob(
326+
updateData[i],
327+
context
328+
);
332329
}
333330
}
334331

332+
// In minimal update data mode, revert if we have more or less updates than price IDs
333+
if (
334+
checkUpdateDataIsMinimal &&
335+
totalUpdatesAcrossBlobs != priceIds.length
336+
) {
337+
revert PythErrors.InvalidArgument();
338+
}
339+
335340
// Check all price feeds were found
336341
for (uint k = 0; k < priceIds.length; k++) {
337342
if (context.priceFeeds[k].id == 0) {
@@ -356,12 +361,10 @@ abstract contract Pyth is
356361
(priceFeeds, ) = parsePriceFeedUpdatesInternal(
357362
updateData,
358363
priceIds,
359-
PythInternalStructs.ParseConfig(
360-
minPublishTime,
361-
maxPublishTime,
362-
false,
363-
false
364-
)
364+
minPublishTime,
365+
maxPublishTime,
366+
false,
367+
false
365368
);
366369
}
367370

@@ -383,12 +386,10 @@ abstract contract Pyth is
383386
parsePriceFeedUpdatesInternal(
384387
updateData,
385388
priceIds,
386-
PythInternalStructs.ParseConfig(
387-
minPublishTime,
388-
maxPublishTime,
389-
false,
390-
true
391-
)
389+
minPublishTime,
390+
maxPublishTime,
391+
false,
392+
true
392393
);
393394
}
394395

@@ -567,12 +568,10 @@ abstract contract Pyth is
567568
(priceFeeds, ) = parsePriceFeedUpdatesInternal(
568569
updateData,
569570
priceIds,
570-
PythInternalStructs.ParseConfig(
571-
minPublishTime,
572-
maxPublishTime,
573-
true,
574-
false
575-
)
571+
minPublishTime,
572+
maxPublishTime,
573+
true,
574+
false
576575
);
577576
}
578577

target_chains/ethereum/contracts/contracts/pyth/PythInternalStructs.sol

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@ import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";
99
contract PythInternalStructs {
1010
using BytesLib for bytes;
1111

12-
struct ParseConfig {
13-
uint64 minPublishTime;
14-
uint64 maxPublishTime;
15-
bool checkUniqueness;
16-
/// When checkUpdateDataIsMinimal is true, parsing will revert
17-
/// if the number of passed in updates exceeds or is less than
18-
/// the length of priceIds.
19-
bool checkUpdateDataIsMinimal;
20-
}
21-
2212
/// Internal struct to hold parameters for update processing
2313
/// @dev Storing these variable in a struct rather than local variables
2414
/// helps reduce stack depth when passing arguments to functions.
2515
struct UpdateParseContext {
2616
bytes32[] priceIds;
27-
ParseConfig config;
17+
uint64 minAllowedPublishTime;
18+
uint64 maxAllowedPublishTime;
19+
bool checkUniqueness;
20+
/// When checkUpdateDataIsMinimal is true, parsing will revert
21+
/// if the number of passed in updates exceeds or is less than
22+
/// the length of priceIds.
23+
bool checkUpdateDataIsMinimal;
2824
PythStructs.PriceFeed[] priceFeeds;
2925
uint64[] slots;
3026
}

target_chains/ethereum/contracts/forge-test/PulseScheduler.t.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ contract SchedulerTest is Test, SchedulerEvents, PulseSchedulerTestUtils {
248248
numInitialFeeds
249249
);
250250

251-
mockParsePriceFeedUpdatesWithSlotsStrict(pyth, initialPriceFeeds, slots);
251+
mockParsePriceFeedUpdatesWithSlotsStrict(
252+
pyth,
253+
initialPriceFeeds,
254+
slots
255+
);
252256
bytes[] memory updateData = createMockUpdateData(initialPriceFeeds);
253257

254258
vm.prank(pusher);
@@ -1855,7 +1859,7 @@ contract SchedulerTest is Test, SchedulerEvents, PulseSchedulerTestUtils {
18551859
slots[1] = 100; // Same slot
18561860

18571861
// Mock Pyth response (should succeed in the real world as minValidTime is 0)
1858-
mockParsePriceFeedUpdatesWithSlots(pyth, priceFeeds, slots);
1862+
mockParsePriceFeedUpdatesWithSlotsStrict(pyth, priceFeeds, slots);
18591863
bytes[] memory updateData = createMockUpdateData(priceFeeds);
18601864

18611865
// Expect PricesUpdated event with the latest valid timestamp
@@ -1908,7 +1912,7 @@ contract SchedulerTest is Test, SchedulerEvents, PulseSchedulerTestUtils {
19081912
slots[1] = 100; // Same slot
19091913

19101914
// Mock Pyth response (should succeed in the real world as minValidTime is 0)
1911-
mockParsePriceFeedUpdatesWithSlots(pyth, priceFeeds, slots);
1915+
mockParsePriceFeedUpdatesWithSlotsStrict(pyth, priceFeeds, slots);
19121916
bytes[] memory updateData = createMockUpdateData(priceFeeds);
19131917

19141918
// Expect revert with TimestampTooOld (checked in _validateShouldUpdatePrices)

target_chains/ethereum/sdk/solidity/MockPyth.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ contract MockPyth is AbstractPyth {
164164
);
165165
}
166166

167-
function parsePriceFeedUpdatesWithSlots(
167+
function parsePriceFeedUpdatesWithSlotsStrict(
168168
bytes[] calldata updateData,
169169
bytes32[] calldata priceIds,
170170
uint64 minPublishTime,

target_chains/ethereum/sdk/solidity/PythAggregatorV3.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ contract PythAggregatorV3 {
3131
pyth.updatePriceFeeds{value: fee}(priceUpdateData);
3232

3333
// refund remaining eth
34-
payable(msg.sender).call{value: address(this).balance}("");
34+
// solhint-disable-next-line no-unused-vars
35+
(bool success, ) = payable(msg.sender).call{
36+
value: address(this).balance
37+
}("");
3538
}
3639

3740
function decimals() public view virtual returns (uint8) {

target_chains/ethereum/sdk/solidity/abis/AbstractPyth.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@
589589
"type": "uint64"
590590
}
591591
],
592-
"name": "parsePriceFeedUpdatesWithSlots",
592+
"name": "parsePriceFeedUpdatesWithSlotsStrict",
593593
"outputs": [
594594
{
595595
"components": [

target_chains/ethereum/sdk/solidity/abis/IPyth.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@
479479
"type": "uint64"
480480
}
481481
],
482-
"name": "parsePriceFeedUpdatesWithSlots",
482+
"name": "parsePriceFeedUpdatesWithSlotsStrict",
483483
"outputs": [
484484
{
485485
"components": [

target_chains/ethereum/sdk/solidity/abis/MockPyth.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@
728728
"type": "uint64"
729729
}
730730
],
731-
"name": "parsePriceFeedUpdatesWithSlots",
731+
"name": "parsePriceFeedUpdatesWithSlotsStrict",
732732
"outputs": [
733733
{
734734
"components": [

0 commit comments

Comments
 (0)