|
|
@@ -175,76 +175,6 @@ abstract contract Pyth is
|
|
|
if (price.publishTime == 0) revert PythErrors.PriceFeedNotFound();
|
|
|
}
|
|
|
|
|
|
- function parseBatchAttestationHeader(
|
|
|
- bytes memory encoded
|
|
|
- )
|
|
|
- internal
|
|
|
- pure
|
|
|
- returns (uint index, uint nAttestations, uint attestationSize)
|
|
|
- {
|
|
|
- unchecked {
|
|
|
- index = 0;
|
|
|
-
|
|
|
- // Check header
|
|
|
- {
|
|
|
- uint32 magic = UnsafeBytesLib.toUint32(encoded, index);
|
|
|
- index += 4;
|
|
|
- if (magic != 0x50325748) revert PythErrors.InvalidUpdateData();
|
|
|
-
|
|
|
- uint16 versionMajor = UnsafeBytesLib.toUint16(encoded, index);
|
|
|
- index += 2;
|
|
|
- if (versionMajor != 3) revert PythErrors.InvalidUpdateData();
|
|
|
-
|
|
|
- // This value is only used as the check below which currently
|
|
|
- // never reverts
|
|
|
- // uint16 versionMinor = UnsafeBytesLib.toUint16(encoded, index);
|
|
|
- index += 2;
|
|
|
-
|
|
|
- // This check is always false as versionMinor is 0, so it is commented.
|
|
|
- // in the future that the minor version increases this will have effect.
|
|
|
- // if(versionMinor < 0) revert InvalidUpdateData();
|
|
|
-
|
|
|
- uint16 hdrSize = UnsafeBytesLib.toUint16(encoded, index);
|
|
|
- index += 2;
|
|
|
-
|
|
|
- // NOTE(2022-04-19): Currently, only payloadId comes after
|
|
|
- // hdrSize. Future extra header fields must be read using a
|
|
|
- // separate offset to respect hdrSize, i.e.:
|
|
|
- //
|
|
|
- // uint hdrIndex = 0;
|
|
|
- // bpa.header.payloadId = UnsafeBytesLib.toUint8(encoded, index + hdrIndex);
|
|
|
- // hdrIndex += 1;
|
|
|
- //
|
|
|
- // bpa.header.someNewField = UnsafeBytesLib.toUint32(encoded, index + hdrIndex);
|
|
|
- // hdrIndex += 4;
|
|
|
- //
|
|
|
- // // Skip remaining unknown header bytes
|
|
|
- // index += bpa.header.hdrSize;
|
|
|
-
|
|
|
- uint8 payloadId = UnsafeBytesLib.toUint8(encoded, index);
|
|
|
-
|
|
|
- // Skip remaining unknown header bytes
|
|
|
- index += hdrSize;
|
|
|
-
|
|
|
- // Payload ID of 2 required for batch headerBa
|
|
|
- if (payloadId != 2) revert PythErrors.InvalidUpdateData();
|
|
|
- }
|
|
|
-
|
|
|
- // Parse the number of attestations
|
|
|
- nAttestations = UnsafeBytesLib.toUint16(encoded, index);
|
|
|
- index += 2;
|
|
|
-
|
|
|
- // Parse the attestation size
|
|
|
- attestationSize = UnsafeBytesLib.toUint16(encoded, index);
|
|
|
- index += 2;
|
|
|
-
|
|
|
- // Given the message is valid the arithmetic below should not overflow, and
|
|
|
- // even if it overflows then the require would fail.
|
|
|
- if (encoded.length != (index + (attestationSize * nAttestations)))
|
|
|
- revert PythErrors.InvalidUpdateData();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
function parsePriceFeedUpdatesInternal(
|
|
|
bytes[] calldata updateData,
|
|
|
bytes32[] calldata priceIds,
|