Skip to content

Commit 69ef318

Browse files
authored
AA-282 L-02: Imprecise refresh requirement (eth-infinitism#424)
* AA-282 L-02: Imprecies refresh requirement
1 parent fdacc98 commit 69ef318

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

contracts/samples/utils/OracleHelper.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ abstract contract OracleHelper {
2323
/// @notice The price cache will be returned without even fetching the oracles for this number of seconds
2424
uint48 cacheTimeToLive;
2525

26+
/// @notice The maximum acceptable age of the price oracle round
27+
uint48 maxOracleRoundAge;
28+
2629
/// @notice The Oracle contract used to fetch the latest token prices
2730
IOracle tokenOracle;
2831

@@ -157,8 +160,7 @@ abstract contract OracleHelper {
157160
function fetchPrice(IOracle _oracle) internal view returns (uint256 price) {
158161
(uint80 roundId, int256 answer,, uint256 updatedAt, uint80 answeredInRound) = _oracle.latestRoundData();
159162
require(answer > 0, "TPM: Chainlink price <= 0");
160-
// 2 days old price is considered stale since the price is updated every 24 hours
161-
require(updatedAt >= block.timestamp - 60 * 60 * 24 * 2, "TPM: Incomplete round");
163+
require(updatedAt >= block.timestamp - oracleHelperConfig.maxOracleRoundAge, "TPM: Incomplete round");
162164
require(answeredInRound >= roundId, "TPM: Stale price");
163165
price = uint256(answer);
164166
}

gascalc/5-token-paymaster.gas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ context('Token Paymaster', function () {
5858

5959
const oracleHelperConfig: OracleHelperNamespace.OracleHelperConfigStruct = {
6060
cacheTimeToLive: 100000000,
61+
maxOracleRoundAge: 0,
6162
nativeOracle: nativeAssetOracleAddress,
6263
nativeOracleReverse: false,
6364
priceUpdateThreshold: priceDenominator.mul(2).div(10), // +20%

reports/gas-checker.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
4545
║ paymaster+postOp with diff │ 11 │ │ 42927 │ 13948 ║
4646
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
47-
║ token paymaster │ 1 │ 128491 │ │ ║
47+
║ token paymaster │ 1 │ 128503 │ │ ║
4848
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
49-
║ token paymaster with diff │ 2 │ │ 6614537166
49+
║ token paymaster with diff │ 2 │ │ 6612137142
5050
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
51-
║ token paymaster │ 10 │ 723875 │ │ ║
51+
║ token paymaster │ 10 │ 723935 │ │ ║
5252
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
53-
║ token paymaster with diff │ 11 │ │ 6622837249
53+
║ token paymaster with diff │ 11 │ │ 6620437225
5454
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝
5555

test/samples/OracleHelper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe('OracleHelper', function () {
8585
nativeOracle: testEnv.nativeAssetOracle.address,
8686
tokenOracle: testEnv.tokenOracle.address,
8787
cacheTimeToLive: 0,
88+
maxOracleRoundAge: 0,
8889
priceUpdateThreshold: 0
8990
}
9091
}

test/samples/TokenPaymaster.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ describe('TokenPaymaster', function () {
9999

100100
const oracleHelperConfig: OracleHelperNamespace.OracleHelperConfigStruct = {
101101
cacheTimeToLive: 0,
102+
maxOracleRoundAge: 0,
102103
nativeOracle: nativeAssetOracle.address,
103104
nativeOracleReverse: false,
104105
priceUpdateThreshold: priceDenominator.mul(12).div(100).toString(), // 20%

0 commit comments

Comments
 (0)