Skip to content

Commit d351d3e

Browse files
Merge pull request #36 from morpho-org/fix/512-bit-multiplication
fix(oracle): use 512 bit multiplication
2 parents c5d2258 + e94270f commit d351d3e

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "lib/morpho-blue"]
55
path = lib/morpho-blue
66
url = https://github.com/morpho-org/morpho-blue
7+
[submodule "lib/openzeppelin-contracts"]
8+
path = lib/openzeppelin-contracts
9+
url = https://github.com/OpenZeppelin/openzeppelin-contracts

lib/openzeppelin-contracts

Submodule openzeppelin-contracts added at 932fddf

src/ChainlinkOracle.sol

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
2-
pragma solidity 0.8.19;
2+
pragma solidity 0.8.21;
33

44
import {IOracle} from "../lib/morpho-blue/src/interfaces/IOracle.sol";
55

66
import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol";
77
import {IERC4626, VaultLib} from "./libraries/VaultLib.sol";
88
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
9+
import {Math} from "../lib/openzeppelin-contracts/contracts/utils/math/Math.sol";
910

1011
/// @title ChainlinkOracle
1112
/// @author Morpho Labs
1213
/// @custom:contact [email protected]
1314
/// @notice Morpho Blue oracle using Chainlink-compliant feeds.
1415
contract ChainlinkOracle is IOracle {
16+
using Math for uint256;
1517
using VaultLib for IERC4626;
1618
using ChainlinkDataFeedLib for AggregatorV3Interface;
1719

@@ -35,12 +37,13 @@ contract ChainlinkOracle is IOracle {
3537

3638
/* CONSTRUCTOR */
3739

38-
/// @dev Here is the list of assumptions on the inputs that guarantees the oracle behaves as expected:
40+
/// @dev Here is the list of assumptions that guarantees the oracle behaves as expected:
3941
/// - Feeds are either Chainlink-compliant or the address zero.
4042
/// - Feeds have the same behavioral assumptions as Chainlink's.
4143
/// - Feeds are set in the correct order.
4244
/// - Decimals passed as argument are correct.
43-
/// - The vault conversion sample is low enough to avoid overflows.
45+
/// - The vault's sample shares quoted as assets and the base feed prices don't overflow when multiplied.
46+
/// - The quote feed prices don't overflow when multiplied.
4447
/// - The vault, if set, is ERC4626-compliant.
4548
/// @param vault Vault. Pass address zero to omit this parameter.
4649
/// @param baseFeed1 First base feed. Pass address zero if the price = 1.
@@ -111,8 +114,9 @@ contract ChainlinkOracle is IOracle {
111114

112115
/// @inheritdoc IOracle
113116
function price() external view returns (uint256) {
114-
return (
115-
VAULT.getAssets(VAULT_CONVERSION_SAMPLE) * BASE_FEED_1.getPrice() * BASE_FEED_2.getPrice() * SCALE_FACTOR
116-
) / (QUOTE_FEED_1.getPrice() * QUOTE_FEED_2.getPrice());
117+
return SCALE_FACTOR.mulDiv(
118+
VAULT.getAssets(VAULT_CONVERSION_SAMPLE) * BASE_FEED_1.getPrice() * BASE_FEED_2.getPrice(),
119+
QUOTE_FEED_1.getPrice() * QUOTE_FEED_2.getPrice()
120+
);
117121
}
118122
}

0 commit comments

Comments
 (0)