Skip to content
Verified contractExactMIT

OwnerAuthority

Address0x20148b5ea3e8db4c89f25e3b8aae6be0983b585f
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.7.6

 

Same code

1 more contract

 

Details

Compiler
solc 0.7.6+commit.7338295f
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,295,866
Creation transaction
0x644b4d21e4…293bbe6d9d

contracts/ocr_v1/OwnerAuthority.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;

/**
 * @title OwnedAggregatorInterface
 * @dev The subset of OffchainAggregator 4.0.0 (including Owned) that
 * OwnerAuthority calls. Declared locally so the authority compiles without
 * the aggregator sources; tests assert these selectors against the
 * aggregator ABI.
 */
interface OwnedAggregatorInterface {
  function owner() external view returns (address);
  function transferOwnership(address to) external;
  function acceptOwnership() external;
  function setConfig(
    address[] calldata signers,
    address[] calldata transmitters,
    uint8 threshold,
    uint64 encodedConfigVersion,
    bytes calldata encoded
  ) external;
  function latestConfigDetails()
    external
    view
    returns (uint32 configCount, uint32 blockNumber, bytes16 configDigest);
}

/**
 * @title OwnerAuthority
 * @notice holds the ownership of one or more OCR1 aggregators ("feeds") for
 * its own owner and exposes two write paths to them:
 * - the authority owner keeps the full owner surface of every held feed via
 *   setConfig, forward and transferAggregatorOwnership;
 * - a global operator list may change only the heartbeat (deltaC) and the
 *   deviation threshold (alphaPPB) of a feed's current config, via
 *   setPricingParams, which replays the current setConfig tuple with just
 *   those two words patched.
 * @dev the authority keeps no per-feed state. Whether a feed is held is read
 * live from feed.owner(); the operator grant on a feed starts when the
 * authority accepts its ownership and ends the moment another address
 * accepts it.
 *
 * Governance of the authority itself is a two-step transfer named apart
 * from Owned (authorityOwner / pendingAuthorityOwner), so the two kinds of
 * owner cannot be confused. Operators form one global enumerable list that
 * is only ever replaced as a whole. The only constant is an immutable lower
 * bound for the deltaC floor, and the only tunable is that floor, applied to
 * both write paths.
 *
 * Deliberate non-features: no fallback (the owner path is the explicit
 * forward, which rejects the three selectors that must go through the
 * recording wrappers), no per-feed policy, no deltaC ceiling, no alphaPPB
 * bounds, no cooldown, not upgradeable.
 *
 * Revert codes (short on purpose; each appears once in this source):
 *   OA00 caller is not the authority owner
 *   OA01 caller is not an operator
 *   OA02 the feed already had a config set in this block
 *   OA04 deltaC below the current floor
 *   OA05 operator path: version is not 1 or bad encoded length
 *   OA06 submitted tuple does not match the feed's current config digest
 *   OA07 operator path: outer offset not 0x20, non-canonical pricing words
 *        or no-op (both values unchanged)
 *   OA08 reentrant call
 *   OA09 zero address (operator, feed, signer, transmitter)
 *   OA10 operator list too long or repeated, or floor below the constant
 *   OA11 forward: calldata shorter than a selector or blacklisted selector
 *   OA12 feed has no code, its owner() cannot be read, or it is not owned
 *        by this authority
 *   OA13 feed configCount exhausted
 *   OA14 owner path, version 1: bad length, outer offset or a
 *        non-canonical word in the fixed-size head
 *   OA15 acceptAggregatorOwnership: caller is neither owner nor operator
 *   OA16 acceptAuthorityOwnership: caller is not the pending owner
 *   OA17 operator path, version 1: a dynamic root offset of the blob points
 *        back into the fixed-size head
 */
contract OwnerAuthority {

  /// @dev the address that holds the owner surface of every held feed
  address public authorityOwner;
  /// @dev the address proposed by the owner, zero when nothing is pending
  address public pendingAuthorityOwner;

  /// @dev upper bound on the number of operators in the list
  uint8 constant public MAX_OPERATORS = 16;
  /// @dev the operator list, enumerable, in the order it was set
  address[] private s_operators;
  /// @dev membership of s_operators, true for every listed address
  mapping(address => bool) private s_isOperator;

  /// @dev immutable lower bound for minDeltaCSeconds, in seconds
  uint32 constant public CONST_MIN_DELTA_C_SECONDS = 10 minutes;

  /// @dev deltaC floor applied to both write paths, in seconds
  uint32 public minDeltaCSeconds;

  /// @dev shared by every entry point that calls a feed
  bool private entered;

  /// @dev deltaC is carried in nanoseconds inside the encoded config
  uint64 constant private NANOSECONDS_PER_SECOND = 1_000_000_000;
  /// @dev the only encoded config version whose layout is known here
  uint64 constant private ENCODED_CONFIG_VERSION_V1 = 1;
  /**
   * @dev Version 1 encoded config: [0,32) outer tuple offset (must be 0x20),
   * then a 12-word tuple head whose first 8 words are fixed-size:
   * deltaProgress, deltaResend, deltaRound, deltaGrace, deltaC (int64),
   * alphaPPB (uint64), deltaStage (int64), rMax (uint8). 416 = 32 + 12 * 32
   * is the shortest blob with a complete head; 20000 is the largest encoded
   * config accepted.
   */
  uint256 constant private V1_MIN_ENCODED_LENGTH = 416;
  /// @dev largest encoded config accepted, in bytes
  uint256 constant private MAX_ENCODED_LENGTH = 20_000;
  /// @dev blob byte offset of the deltaC word
  uint256 constant private V1_DELTA_C_OFFSET = 160;
  /// @dev blob byte offset of the alphaPPB word
  uint256 constant private V1_ALPHA_PPB_OFFSET = 192;
  /**
   * @dev The last 4 head words, blob [288,416), are the root offsets of the
   * dynamic fields (s, offchainPublicKeys, peerIDs, sharedSecretEncryptions),
   * relative to the tuple start at blob byte 32; the head they must clear
   * is 12 words long.
   */
  uint256 constant private V1_FIRST_ROOT_OFFSET = 288;
  /// @dev length of the 12-word tuple head, relative to the tuple start
  uint256 constant private V1_TUPLE_HEAD_LENGTH = 384;

  /**
   * @notice emitted when the authority owner proposes a new owner
   * @param from the current authority owner
   * @param to the proposed owner, zero when a pending proposal is withdrawn
   */
  event AuthorityOwnershipTransferRequested(address indexed from, address indexed to);
  /**
   * @notice emitted when the authority changes owner
   * @param from the previous authority owner, zero at construction
   * @param to the new authority owner
   */
  event AuthorityOwnershipTransferred(address indexed from, address indexed to);
  /**
   * @notice emitted when the operator list is replaced
   * @param operators the complete new list, empty when every operator is
   * revoked
   */
  event OperatorsSet(address[] operators);
  /**
   * @notice emitted when the deltaC floor is set, including at construction
   * @param minDeltaCSeconds the floor now applied to both write paths
   */
  event MinDeltaCSet(uint32 minDeltaCSeconds);
  /**
   * @notice emitted when the authority accepts a feed's ownership
   * @param feed the feed now held by the authority
   * @param caller the owner or operator that completed the transfer
   */
  event AggregatorAccepted(address indexed feed, address indexed caller);
  /**
   * @notice emitted when the authority offers a held feed to another address
   * @param feed the feed whose ownership is offered
   * @param to the proposed new owner, zero when a pending offer is withdrawn
   */
  event AggregatorTransferRequested(address indexed feed, address indexed to);
  /**
   * @notice emitted when an operator retunes a feed's pricing parameters
   * @param feed the feed whose config was replayed
   * @param operator the operator that submitted the update
   * @param configCount the feed's config count after the replay
   * @param configDigest the feed's config digest after the replay
   * @param previousDeltaCNanoseconds the heartbeat before the update
   * @param currentDeltaCNanoseconds the heartbeat after the update
   * @param previousAlphaPPB the deviation threshold before the update
   * @param currentAlphaPPB the deviation threshold after the update
   */
  event PricingParamsSet(
    address indexed feed,
    address indexed operator,
    uint32 configCount,
    bytes16 configDigest,
    int64 previousDeltaCNanoseconds,
    int64 currentDeltaCNanoseconds,
    uint64 previousAlphaPPB,
    uint64 currentAlphaPPB
  );
  /**
   * @notice emitted when the authority owner sets a full config on a feed
   * @param feed the feed that received the config
   * @param configCount the feed's config count after the call
   * @param configDigest the feed's config digest after the call
   */
  event ConfigForwarded(address indexed feed, uint32 configCount, bytes16 configDigest);

  /// @dev reverts unless the caller is the authority owner
  modifier onlyAuthorityOwner() {
    require(msg.sender == authorityOwner, "OA00");
    _;
  }

  /// @dev one lock for every entry point that calls a feed
  modifier nonReentrant() {
    require(!entered, "OA08");
    entered = true;
    _;
    entered = false;
  }

  /**
   * @dev the deployer becomes the authority owner and the deltaC floor starts
   * at 30 minutes; both are announced with the same events later changes use
   */
  constructor() {
    authorityOwner = msg.sender;
    minDeltaCSeconds = 30 minutes;
    emit AuthorityOwnershipTransferred(address(0), msg.sender);
    emit MinDeltaCSet(30 minutes);
  }

  /*
   * Authority governance
   */

  /**
   * @notice begins transferring the authority to `to`
   * @dev `to == 0` withdraws a pending transfer, since the zero address can
   * never accept
   * @param to the proposed authority owner, or zero to withdraw
   */
  function transferAuthorityOwnership(address to) external onlyAuthorityOwner() {
    pendingAuthorityOwner = to;
    emit AuthorityOwnershipTransferRequested(authorityOwner, to);
  }

  /**
   * @notice completes a pending authority transfer
   * @dev only the proposed owner may call; the pending slot is cleared
   */
  function acceptAuthorityOwnership() external {
    require(msg.sender == pendingAuthorityOwner, "OA16");
    address previous = authorityOwner;
    authorityOwner = msg.sender;
    pendingAuthorityOwner = address(0);
    emit AuthorityOwnershipTransferred(previous, msg.sender);
  }

  /**
   * @notice replaces the whole operator list; an empty list revokes every
   * operator
   * @dev same shape as the aggregator's own oracle set: clear from the tail,
   * then rebuild
   * @param list the complete new operator list, at most MAX_OPERATORS
   * entries, no zero address, no repeated address
   */
  function setOperators(address[] calldata list) external onlyAuthorityOwner() {
    _requireWithinLimits(list.length <= MAX_OPERATORS);
    while (s_operators.length != 0) {
      delete s_isOperator[s_operators[s_operators.length - 1]];
      s_operators.pop();
    }
    for (uint256 i = 0; i < list.length; i++) {
      _requireNonZero(list[i]);
      _requireWithinLimits(!s_isOperator[list[i]]);
      s_isOperator[list[i]] = true;
      s_operators.push(list[i]);
    }
    emit OperatorsSet(list);
  }

  /**
   * @notice sets the deltaC floor applied to both write paths on every feed
   * from now on
   * @dev never below CONST_MIN_DELTA_C_SECONDS. Configs already set on feeds
   * are not affected.
   * @param seconds_ the new floor, in seconds
   */
  function setMinDeltaC(uint32 seconds_) external onlyAuthorityOwner() {
    _requireWithinLimits(seconds_ >= CONST_MIN_DELTA_C_SECONDS);
    minDeltaCSeconds = seconds_;
    emit MinDeltaCSet(seconds_);
  }

  /*
   * Feed lifecycle
   */

  /**
   * @notice completes a feed ownership transfer that its owner offered to
   * this authority
   * @dev open to operators as well as the owner: it can only accept what was
   * already offered, and afterwards the operators' power on the feed is
   * limited to setPricingParams. After the accept call the feed must report
   * this authority as its owner.
   * @param feed the aggregator whose owner has offered it to this authority
   */
  function acceptAggregatorOwnership(address feed) external nonReentrant() {
    require(msg.sender == authorityOwner || isOperator(msg.sender), "OA15");
    _requireNonZero(feed);
    // Low-level call: a target without code then fails the ownership check
    // below (OA12) instead of the compiler's silent extcodesize revert.
    _call(feed, abi.encodeWithSelector(OwnedAggregatorInterface.acceptOwnership.selector));
    _requireOwnedFeed(feed);
    emit AggregatorAccepted(feed, msg.sender);
  }

  /**
   * @notice offers a held feed's ownership to `to`
   * @dev `to == 0` withdraws a pending offer. The feed stays held, and both
   * write paths keep working, until `to` accepts.
   * @param feed the held aggregator
   * @param to the proposed new owner of the feed, or zero to withdraw
   */
  function transferAggregatorOwnership(address feed, address to)
    external
    onlyAuthorityOwner()
    nonReentrant()
  {
    _requireOwnedFeed(feed);
    OwnedAggregatorInterface(feed).transferOwnership(to);
    emit AggregatorTransferRequested(feed, to);
  }

  /*
   * Owner path
   */

  /**
   * @notice forwards an arbitrary owner call to a held feed and returns its
   * return data
   * @dev a failed call reverts with the feed's revert data. setConfig,
   * transferOwnership and acceptOwnership are rejected: they must go through
   * their wrappers, which check and record them. The calldata is checked
   * before the feed is, so a rejected selector costs no external call.
   * @param feed the held aggregator
   * @param data the complete calldata of the owner call, selector included
   * @return ret the feed's return data
   */
  function forward(address feed, bytes calldata data)
    external
    onlyAuthorityOwner()
    nonReentrant()
    returns (bytes memory ret)
  {
    // Local checks first: a rejected selector costs no external call.
    bytes4 selector;
    // solhint-disable-next-line no-inline-assembly
    assembly { selector := calldataload(data.offset) }
    require(
      data.length >= 4 &&
      selector != OwnedAggregatorInterface.setConfig.selector &&
      selector != OwnedAggregatorInterface.transferOwnership.selector &&
      selector != OwnedAggregatorInterface.acceptOwnership.selector,
      "OA11"
    );
    _requireOwnedFeed(feed);
    // Plain return: an assembly return would skip the unlock in nonReentrant.
    ret = _call(feed, data);
  }

  /**
   * @notice full setConfig on a held feed, for the authority owner
   * @dev not authenticated against the current config (this is a new
   * config), but gated like the operator path: one config per block, no
   * zero oracle address, configCount not exhausted, and for version 1 a
   * canonical fixed-size head whose deltaC is at or above the floor. Other
   * versions are passed through unparsed.
   * @param feed the held aggregator
   * @param signers addresses with which oracles sign the reports
   * @param transmitters addresses oracles use to transmit the reports
   * @param threshold number of faulty oracles the system can tolerate
   * @param encodedConfigVersion version number for the encoded config
   * @param encoded encoded off-chain oracle configuration
   */
  function setConfig(
    address feed,
    address[] calldata signers,
    address[] calldata transmitters,
    uint8 threshold,
    uint64 encodedConfigVersion,
    bytes calldata encoded
  )
    external
    onlyAuthorityOwner()
    nonReentrant()
  {
    _requireOwnedFeed(feed);
    _configDetailsForWrite(feed);
    _requireNonZeroOracles(signers, transmitters);
    if (encodedConfigVersion == ENCODED_CONFIG_VERSION_V1) {
      _requireDeltaCAtOrAboveFloor(_requireCanonicalV1Head(encoded));
    }
    OwnedAggregatorInterface(feed).setConfig(
      signers, transmitters, threshold, encodedConfigVersion, encoded
    );
    (uint32 configCount, , bytes16 configDigest) =
      OwnedAggregatorInterface(feed).latestConfigDetails();
    emit ConfigForwarded(feed, configCount, configDigest);
  }

  /*
   * Operator path
   */

  /// @dev relieves stack pressure in setPricingParams
  struct PricingUpdate {
    uint32 configCount;
    bytes16 configDigest;
    uint64 deltaCNanoseconds;
    int64 previousDeltaCNanoseconds;
    uint64 previousAlphaPPB;
    bytes patched;
  }

  /**
   * @notice replays the feed's current config with only deltaC and alphaPPB
   * changed
   * @dev the caller submits the current tuple exactly as emitted by the
   * feed's latest ConfigSet event plus the new values; the tuple is
   * authenticated against the feed's config digest, and the blob's dynamic
   * fields must not reach back into the head (OA17), so no other decoded
   * field can change. Emits a regular ConfigSet on the feed.
   * @param feed the held aggregator
   * @param signers the current signers, as emitted by the latest ConfigSet
   * @param transmitters the current transmitters, as emitted by the latest
   * ConfigSet
   * @param threshold the current threshold, as emitted by the latest
   * ConfigSet
   * @param encodedConfigVersion the current encoded config version; must be
   * 1
   * @param encoded the current encoded config, as emitted by the latest
   * ConfigSet
   * @param deltaCSeconds new heartbeat in seconds (converted to nanoseconds
   * here, the only conversion point)
   * @param alphaPPB new deviation threshold in parts-per-billion
   */
  function setPricingParams(
    address feed,
    address[] calldata signers,
    address[] calldata transmitters,
    uint8 threshold,
    uint64 encodedConfigVersion,
    bytes calldata encoded,
    uint32 deltaCSeconds,
    uint64 alphaPPB
  )
    external
    nonReentrant()
  {
    require(isOperator(msg.sender), "OA01");
    _requireOwnedFeed(feed);
    PricingUpdate memory u;
    (u.configCount, u.configDigest) = _configDetailsForWrite(feed);
    // Widen before multiplying: a uint32 multiplication would wrap.
    u.deltaCNanoseconds = uint64(deltaCSeconds) * NANOSECONDS_PER_SECOND;
    _requireDeltaCAtOrAboveFloor(u.deltaCNanoseconds);
    _authenticateCurrentConfig(
      u.configCount, u.configDigest,
      feed, signers, transmitters, threshold, encodedConfigVersion, encoded
    );
    _requireDynamicFieldsIsolated(encoded);
    u.patched = encoded;
    (u.previousDeltaCNanoseconds, u.previousAlphaPPB) =
      _patchPricingWords(u.patched, u.deltaCNanoseconds, alphaPPB);
    OwnedAggregatorInterface(feed).setConfig(
      signers, transmitters, threshold, encodedConfigVersion, u.patched
    );
    (u.configCount, , u.configDigest) = OwnedAggregatorInterface(feed).latestConfigDetails();
    emit PricingParamsSet(
      feed,
      msg.sender,
      u.configCount,
      u.configDigest,
      u.previousDeltaCNanoseconds,
      int64(u.deltaCNanoseconds),
      u.previousAlphaPPB,
      alphaPPB
    );
  }

  /*
   * Read-only surface
   */

  /**
   * @notice whether an address is currently an operator
   * @param op the address to query
   * @return true if `op` is in the operator list
   */
  function isOperator(address op) public view returns (bool) {
    return s_isOperator[op];
  }

  /**
   * @notice the current operator list
   * @return the operators, in the order they were set
   */
  function operators() external view returns (address[] memory) {
    return s_operators;
  }

  /**
   * @notice the feed's config digest formula, for checking a tuple off-chain
   * before submitting it
   * @param feed the aggregator the config belongs to
   * @param configCount the config count the digest is computed for
   * @param signers addresses with which oracles sign the reports
   * @param transmitters addresses oracles use to transmit the reports
   * @param threshold number of faulty oracles the system can tolerate
   * @param encodedConfigVersion version number for the encoded config
   * @param encoded encoded off-chain oracle configuration
   * @return the digest the aggregator computes for the same tuple
   */
  function computeDigest(
    address feed,
    uint64 configCount,
    address[] calldata signers,
    address[] calldata transmitters,
    uint8 threshold,
    uint64 encodedConfigVersion,
    bytes calldata encoded
  )
    external
    pure
    returns (bytes16)
  {
    return _computeDigest(
      feed, configCount, signers, transmitters, threshold, encodedConfigVersion, encoded
    );
  }

  /*
   * Internals
   */

  function _requireNonZero(address a) private pure {
    require(a != address(0), "OA09");
  }

  function _requireWithinLimits(bool ok) private pure {
    require(ok, "OA10");
  }

  /**
   * @dev The feed must have code and be owned by this authority, read live.
   * The owner is read with a raw staticcall and decoded as a full word: a
   * target without owner(), a failed call, short return data or dirty upper
   * bits all land on OA12 rather than on a decoding revert without a code.
   */
  function _requireOwnedFeed(address feed) private view {
    _requireNonZero(feed);
    uint256 size;
    // solhint-disable-next-line no-inline-assembly
    assembly { size := extcodesize(feed) }
    (bool ok, bytes memory ret) =
      feed.staticcall(abi.encodeWithSelector(OwnedAggregatorInterface.owner.selector));
    require(
      size > 0 && ok && ret.length == 32 &&
      abi.decode(ret, (uint256)) == uint256(uint160(address(this))),
      "OA12"
    );
  }

  /**
   * @dev Shared gates of both write paths: at most one config per block on a
   * feed, and a configCount that the feed can still increment.
   */
  function _configDetailsForWrite(address feed)
    private
    view
    returns (uint32 configCount, bytes16 configDigest)
  {
    uint32 blockNumber;
    (configCount, blockNumber, configDigest) =
      OwnedAggregatorInterface(feed).latestConfigDetails();
    require(blockNumber < block.number, "OA02");
    require(configCount != type(uint32).max, "OA13");
  }

  function _requireNonZeroOracles(address[] calldata signers, address[] calldata transmitters)
    private
    pure
  {
    for (uint256 i = 0; i < signers.length; i++) _requireNonZero(signers[i]);
    for (uint256 i = 0; i < transmitters.length; i++) _requireNonZero(transmitters[i]);
  }

  /**
   * @dev Both paths compare in nanoseconds, in a wide type: the floor is
   * widened before the multiplication.
   */
  function _requireDeltaCAtOrAboveFloor(uint256 deltaCNanoseconds) private view {
    require(
      deltaCNanoseconds >= uint256(minDeltaCSeconds) * uint256(NANOSECONDS_PER_SECOND),
      "OA04"
    );
  }

  function _computeDigest(
    address feed,
    uint64 configCount,
    address[] calldata signers,
    address[] calldata transmitters,
    uint8 threshold,
    uint64 encodedConfigVersion,
    bytes calldata encoded
  )
    private
    pure
    returns (bytes16)
  {
    return bytes16(keccak256(abi.encode(
      feed, configCount, signers, transmitters, threshold, encodedConfigVersion, encoded
    )));
  }

  /**
   * @dev Operator path authentication: the submitted tuple must be the
   * feed's current config. The digest binds every field, so the caller
   * cannot change anything it did not receive from the latest ConfigSet
   * event.
   */
  function _authenticateCurrentConfig(
    uint32 configCount,
    bytes16 configDigest,
    address feed,
    address[] calldata signers,
    address[] calldata transmitters,
    uint8 threshold,
    uint64 encodedConfigVersion,
    bytes calldata encoded
  )
    private
    pure
  {
    require(
      encodedConfigVersion == ENCODED_CONFIG_VERSION_V1 &&
      V1_MIN_ENCODED_LENGTH <= encoded.length &&
      encoded.length <= MAX_ENCODED_LENGTH,
      "OA05"
    );
    _requireNonZeroOracles(signers, transmitters);
    require(
      _computeDigest(
        feed, uint64(configCount), signers, transmitters, threshold, encodedConfigVersion, encoded
      ) == configDigest,
      "OA06"
    );
  }

  /**
   * @dev Operator path, version 1 only (OA05 has already established the
   * version and the minimum length): the four dynamic root offsets must all
   * land after the fixed-size head. ABI decoders only check that an offset
   * stays inside the blob, so a root pointing back into the head would make
   * a dynamic field alias the pricing words and change with them; keeping
   * the roots past the head is what makes "only two words written" mean
   * "only two fields changed". Four calldataloads and comparisons: no offset
   * arithmetic, no alignment or range check, no normalisation. This is
   * isolation, not a canonical or decodability check.
   */
  function _requireDynamicFieldsIsolated(bytes calldata encoded) private pure {
    uint256 wS;
    uint256 wOffchainPublicKeys;
    uint256 wPeerIDs;
    uint256 wSharedSecretEncryptions;
    // solhint-disable-next-line no-inline-assembly
    assembly {
      let roots := add(encoded.offset, V1_FIRST_ROOT_OFFSET)
      wS := calldataload(roots)
      wOffchainPublicKeys := calldataload(add(roots, 0x20))
      wPeerIDs := calldataload(add(roots, 0x40))
      wSharedSecretEncryptions := calldataload(add(roots, 0x60))
    }
    require(
      wS >= V1_TUPLE_HEAD_LENGTH &&
      wOffchainPublicKeys >= V1_TUPLE_HEAD_LENGTH &&
      wPeerIDs >= V1_TUPLE_HEAD_LENGTH &&
      wSharedSecretEncryptions >= V1_TUPLE_HEAD_LENGTH,
      "OA17"
    );
  }

  /**
   * @dev Patches the two pricing words in place and returns the previous
   * values. In memory the bytes pointer addresses the length word, so blob
   * byte offsets 160 / 192 live at pointer offsets 0xc0 / 0xe0.
   */
  function _patchPricingWords(
    bytes memory blob,
    uint64 newDeltaCNanoseconds,
    uint64 newAlphaPPB
  )
    private
    pure
    returns (int64 previousDeltaCNanoseconds, uint64 previousAlphaPPB)
  {
    uint256 outerOffset;
    uint256 wDeltaC;
    uint256 wAlpha;
    // solhint-disable-next-line no-inline-assembly
    assembly {
      outerOffset := mload(add(blob, 0x20))
      wDeltaC := mload(add(blob, add(0x20, V1_DELTA_C_OFFSET)))
      wAlpha := mload(add(blob, add(0x20, V1_ALPHA_PPB_OFFSET)))
    }
    uint256 dNew = uint256(newDeltaCNanoseconds);
    uint256 aNew = uint256(newAlphaPPB);
    require(
      outerOffset == 0x20 &&
      wDeltaC < 2**63 && wAlpha < 2**64 &&
      (wDeltaC != dNew || wAlpha != aNew),
      "OA07"
    );
    previousDeltaCNanoseconds = int64(uint64(wDeltaC));
    previousAlphaPPB = uint64(wAlpha);
    // solhint-disable-next-line no-inline-assembly
    assembly {
      mstore(add(blob, add(0x20, V1_DELTA_C_OFFSET)), dNew)
      mstore(add(blob, add(0x20, V1_ALPHA_PPB_OFFSET)), aNew)
    }
  }

  /**
   * @dev Owner path, version 1 only: the length, the outer offset and all 8
   * fixed-size head words must be canonical; nothing is skipped when an
   * earlier word is malformed. Returns the deltaC word for the floor check.
   */
  function _requireCanonicalV1Head(bytes calldata encoded)
    private
    pure
    returns (uint256 wDeltaC)
  {
    uint256 outerOffset;
    uint256 wDeltaProgress;
    uint256 wDeltaResend;
    uint256 wDeltaRound;
    uint256 wDeltaGrace;
    uint256 wAlpha;
    uint256 wDeltaStage;
    uint256 wRMax;
    // solhint-disable-next-line no-inline-assembly
    assembly {
      let base := encoded.offset
      outerOffset := calldataload(base)
      wDeltaProgress := calldataload(add(base, 0x20))
      wDeltaResend := calldataload(add(base, 0x40))
      wDeltaRound := calldataload(add(base, 0x60))
      wDeltaGrace := calldataload(add(base, 0x80))
      wDeltaC := calldataload(add(base, V1_DELTA_C_OFFSET))
      wAlpha := calldataload(add(base, V1_ALPHA_PPB_OFFSET))
      wDeltaStage := calldataload(add(base, 0xe0))
      wRMax := calldataload(add(base, 0x100))
    }
    require(
      V1_MIN_ENCODED_LENGTH <= encoded.length && encoded.length <= MAX_ENCODED_LENGTH &&
      outerOffset == 0x20 &&
      wDeltaProgress < 2**63 && wDeltaResend < 2**63 && wDeltaRound < 2**63 &&
      wDeltaGrace < 2**63 && wDeltaC < 2**63 && wAlpha < 2**64 &&
      wDeltaStage < 2**63 && wRMax < 256,
      "OA14"
    );
  }

  /// @dev Low-level call to a feed that bubbles the feed's revert data.
  function _call(address feed, bytes memory data) private returns (bytes memory ret) {
    bool ok;
    (ok, ret) = feed.call(data);
    if (!ok) {
      // solhint-disable-next-line no-inline-assembly
      assembly { revert(add(ret, 0x20), mload(ret)) }
    }
  }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.