Skip to content

Commit

Permalink
AA-283 L-03 Inconsistent Oracle Configuration (eth-infinitism#423)
Browse files Browse the repository at this point in the history
* Requiring native oracle to be zero address if unused
  • Loading branch information
shahafn authored Jan 30, 2024
1 parent 69ef318 commit 41857d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions contracts/samples/utils/OracleHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract contract OracleHelper {
/// @notice The Oracle contract used to fetch the latest token prices
IOracle tokenOracle;

/// @notice The Oracle contract used to fetch the latest ETH prices
/// @notice The Oracle contract used to fetch the latest ETH prices. Only needed if tokenToNativeOracle flag is not set.
IOracle nativeOracle;

/// @notice If 'true' we will fetch price directly from tokenOracle
Expand Down Expand Up @@ -76,7 +76,12 @@ abstract contract OracleHelper {
oracleHelperConfig = _oracleHelperConfig;
require(_oracleHelperConfig.priceUpdateThreshold <= PRICE_DENOMINATOR, "TPM: update threshold too high");
tokenOracleDecimalPower = uint128(10 ** oracleHelperConfig.tokenOracle.decimals());
nativeOracleDecimalPower = uint128(10 ** oracleHelperConfig.nativeOracle.decimals());
if (oracleHelperConfig.tokenToNativeOracle) {
require(address(oracleHelperConfig.nativeOracle) == address(0), "TPM: native oracle must be zero");
nativeOracleDecimalPower = 1;
} else {
nativeOracleDecimalPower = uint128(10 ** oracleHelperConfig.nativeOracle.decimals());
}
}

/// @notice Updates the token price by fetching the latest price from the Oracle.
Expand Down
6 changes: 3 additions & 3 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 1 │ 128503 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 2 │ │ 6612137142
║ token paymaster with diff │ 2 │ │ 6613337154
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 10 │ 723935 │ │ ║
║ token paymaster │ 10 │ 723911 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 11 │ │ 6620437225
║ token paymaster with diff │ 11 │ │ 6619237213
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

2 changes: 1 addition & 1 deletion test/samples/OracleHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('OracleHelper', function () {
nativeOracleReverse,
tokenOracleReverse,
tokenToNativeOracle,
nativeOracle: testEnv.nativeAssetOracle.address,
nativeOracle: tokenToNativeOracle ? AddressZero : testEnv.nativeAssetOracle.address,
tokenOracle: testEnv.tokenOracle.address,
cacheTimeToLive: 0,
maxOracleRoundAge: 0,
Expand Down

0 comments on commit 41857d5

Please sign in to comment.