@@ -7,6 +7,7 @@ import "../libraries/external/UnsafeBytesLib.sol";
7
7
import "@pythnetwork/pyth-sdk-solidity/AbstractPyth.sol " ;
8
8
import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol " ;
9
9
10
+ import "@pythnetwork/pyth-sdk-solidity/PythErrors.sol " ;
10
11
import "./PythGetters.sol " ;
11
12
import "./PythSetters.sol " ;
12
13
import "./PythInternalStructs.sol " ;
@@ -21,11 +22,10 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
21
22
) internal {
22
23
setWormhole (wormhole);
23
24
24
- require (
25
- dataSourceEmitterChainIds.length ==
26
- dataSourceEmitterAddresses.length ,
27
- "data source arguments should have the same length "
28
- );
25
+ if (
26
+ dataSourceEmitterChainIds.length !=
27
+ dataSourceEmitterAddresses.length
28
+ ) revert PythErrors.InvalidArgument ();
29
29
30
30
for (uint i = 0 ; i < dataSourceEmitterChainIds.length ; i++ ) {
31
31
PythInternalStructs.DataSource memory ds = PythInternalStructs
@@ -34,10 +34,8 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
34
34
dataSourceEmitterAddresses[i]
35
35
);
36
36
37
- require (
38
- ! PythGetters.isValidDataSource (ds.chainId, ds.emitterAddress),
39
- "Data source already added "
40
- );
37
+ if (PythGetters.isValidDataSource (ds.chainId, ds.emitterAddress))
38
+ revert PythErrors.InvalidArgument ();
41
39
42
40
_state.isValidDataSource[hashDataSource (ds)] = true ;
43
41
_state.validDataSources.push (ds);
@@ -57,7 +55,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
57
55
bytes [] calldata updateData
58
56
) public payable override {
59
57
uint requiredFee = getUpdateFee (updateData);
60
- require (msg .value >= requiredFee, " insufficient paid fee amount " );
58
+ if (msg .value < requiredFee) revert PythErrors. InsufficientFee ( );
61
59
62
60
for (uint i = 0 ; i < updateData.length ; ) {
63
61
updatePriceBatchFromVm (updateData[i]);
@@ -245,10 +243,8 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
245
243
}
246
244
}
247
245
248
- require (
249
- attestationIndex <= attestationSize,
250
- "INTERNAL: Consumed more than `attestationSize` bytes "
251
- );
246
+ if (attestationIndex > attestationSize)
247
+ revert PythErrors.InvalidUpdateData ();
252
248
}
253
249
}
254
250
@@ -259,10 +255,8 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
259
255
bytes32 [] calldata priceIds ,
260
256
uint64 [] calldata publishTimes
261
257
) external payable override {
262
- require (
263
- priceIds.length == publishTimes.length ,
264
- "priceIds and publishTimes arrays should have same length "
265
- );
258
+ if (priceIds.length != publishTimes.length )
259
+ revert PythErrors.InvalidArgument ();
266
260
267
261
for (uint i = 0 ; i < priceIds.length ; ) {
268
262
// If the price does not exist, then the publish time is zero and
@@ -277,9 +271,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
277
271
}
278
272
}
279
273
280
- revert (
281
- "no prices in the submitted batch have fresh prices, so this update will have no effect "
282
- );
274
+ revert PythErrors.NoFreshUpdate ();
283
275
}
284
276
285
277
// This is an overwrite of the same method in AbstractPyth.sol
@@ -295,10 +287,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
295
287
price.price = info.price;
296
288
price.conf = info.conf;
297
289
298
- require (
299
- price.publishTime != 0 ,
300
- "price feed for the given id is not pushed or does not exist "
301
- );
290
+ if (price.publishTime == 0 ) revert PythErrors.PriceFeedNotFound ();
302
291
}
303
292
304
293
// This is an overwrite of the same method in AbstractPyth.sol
@@ -314,10 +303,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
314
303
price.price = info.emaPrice;
315
304
price.conf = info.emaConf;
316
305
317
- require (
318
- price.publishTime != 0 ,
319
- "price feed for the given id is not pushed or does not exist "
320
- );
306
+ if (price.publishTime == 0 ) revert PythErrors.PriceFeedNotFound ();
321
307
}
322
308
323
309
function parseBatchAttestationHeader (
@@ -334,18 +320,20 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
334
320
{
335
321
uint32 magic = UnsafeBytesLib.toUint32 (encoded, index);
336
322
index += 4 ;
337
- require (magic == 0x50325748 , " invalid magic value " );
323
+ if (magic != 0x50325748 ) revert PythErrors. InvalidUpdateData ( );
338
324
339
325
uint16 versionMajor = UnsafeBytesLib.toUint16 (encoded, index);
340
326
index += 2 ;
341
- require (versionMajor == 3 , " invalid version major, expected 3 " );
327
+ if (versionMajor != 3 ) revert PythErrors. InvalidUpdateData ( );
342
328
343
- uint16 versionMinor = UnsafeBytesLib.toUint16 (encoded, index);
329
+ // This value is only used as the check below which currently
330
+ // never reverts
331
+ // uint16 versionMinor = UnsafeBytesLib.toUint16(encoded, index);
344
332
index += 2 ;
345
- require (
346
- versionMinor >= 0 ,
347
- " invalid version minor, expected 0 or more "
348
- );
333
+
334
+ // This check is always false as versionMinor is 0, so it is commented.
335
+ // in the future that the minor version increases this will have effect.
336
+ // if(versionMinor < 0) revert InvalidUpdateData( );
349
337
350
338
uint16 hdrSize = UnsafeBytesLib.toUint16 (encoded, index);
351
339
index += 2 ;
@@ -370,10 +358,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
370
358
index += hdrSize;
371
359
372
360
// Payload ID of 2 required for batch headerBa
373
- require (
374
- payloadId == 2 ,
375
- "invalid payload ID, expected 2 for BatchPriceAttestation "
376
- );
361
+ if (payloadId != 2 ) revert PythErrors.InvalidUpdateData ();
377
362
}
378
363
379
364
// Parse the number of attestations
@@ -386,10 +371,8 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
386
371
387
372
// Given the message is valid the arithmetic below should not overflow, and
388
373
// even if it overflows then the require would fail.
389
- require (
390
- encoded.length == (index + (attestationSize * nAttestations)),
391
- "invalid BatchPriceAttestation size "
392
- );
374
+ if (encoded.length != (index + (attestationSize * nAttestations)))
375
+ revert PythErrors.InvalidUpdateData ();
393
376
}
394
377
}
395
378
@@ -398,12 +381,11 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
398
381
) internal view returns (IWormhole.VM memory vm ) {
399
382
{
400
383
bool valid;
401
- string memory reason;
402
- (vm, valid, reason) = wormhole ().parseAndVerifyVM (encodedVm);
403
- require (valid, reason);
384
+ (vm, valid, ) = wormhole ().parseAndVerifyVM (encodedVm);
385
+ if (! valid) revert PythErrors.InvalidWormholeVaa ();
404
386
}
405
387
406
- require ( verifyPythVM (vm), " invalid data source chain/emitter ID " );
388
+ if ( ! verifyPythVM (vm)) revert PythErrors. InvalidUpdateDataSource ( );
407
389
}
408
390
409
391
function parsePriceFeedUpdates (
@@ -420,10 +402,8 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
420
402
unchecked {
421
403
{
422
404
uint requiredFee = getUpdateFee (updateData);
423
- require (
424
- msg .value >= requiredFee,
425
- "insufficient paid fee amount "
426
- );
405
+ if (msg .value < requiredFee)
406
+ revert PythErrors.InsufficientFee ();
427
407
}
428
408
429
409
priceFeeds = new PythStructs.PriceFeed [](priceIds.length );
@@ -509,10 +489,9 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
509
489
}
510
490
511
491
for (uint k = 0 ; k < priceIds.length ; k++ ) {
512
- require (
513
- priceFeeds[k].id != 0 ,
514
- "1 or more price feeds are not found in the updateData or they are out of the given time range "
515
- );
492
+ if (priceFeeds[k].id == 0 ) {
493
+ revert PythErrors.PriceFeedNotFoundWithinRange ();
494
+ }
516
495
}
517
496
}
518
497
}
@@ -522,10 +501,7 @@ abstract contract Pyth is PythGetters, PythSetters, AbstractPyth {
522
501
) public view override returns (PythStructs.PriceFeed memory priceFeed ) {
523
502
// Look up the latest price info for the given ID
524
503
PythInternalStructs.PriceInfo memory info = latestPriceInfo (id);
525
- require (
526
- info.publishTime != 0 ,
527
- "price feed for the given id is not pushed or does not exist "
528
- );
504
+ if (info.publishTime == 0 ) revert PythErrors.PriceFeedNotFound ();
529
505
530
506
priceFeed.id = id;
531
507
priceFeed.price.price = info.price;
0 commit comments