Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit cd3036e

Browse files
authored
Merge pull request #148 from euler-xyz/read-only-reentrancy
make view methods that loadAssetCacheRO check the re-entrancy guard i…
2 parents 0fade57 + effa84e commit cd3036e

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

contracts/BaseLogic.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ abstract contract BaseLogic is BaseModule {
257257
}
258258

259259
function loadAssetCacheRO(address underlying, AssetStorage storage assetStorage) internal view returns (AssetCache memory assetCache) {
260+
require(reentrancyLock == REENTRANCYLOCK__UNLOCKED, "e/ro-reentrancy");
261+
initAssetCache(underlying, assetStorage, assetCache);
262+
}
263+
264+
function internalLoadAssetCacheRO(address underlying, AssetStorage storage assetStorage) internal view returns (AssetCache memory assetCache) {
260265
initAssetCache(underlying, assetStorage, assetCache);
261266
}
262267

contracts/modules/RiskManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ contract RiskManager is IRiskManager, BaseLogic {
250250
function getPrice(address underlying) external view override returns (uint twap, uint twapPeriod) {
251251
AssetConfig memory config = resolveAssetConfig(underlying);
252252
AssetStorage storage assetStorage = eTokenLookup[config.eTokenAddress];
253-
AssetCache memory assetCache = loadAssetCacheRO(underlying, assetStorage);
253+
AssetCache memory assetCache = internalLoadAssetCacheRO(underlying, assetStorage);
254254

255255
(twap, twapPeriod) = getPriceInternal(assetCache, config);
256256
}
@@ -261,7 +261,7 @@ contract RiskManager is IRiskManager, BaseLogic {
261261
function getPriceFull(address underlying) external view override returns (uint twap, uint twapPeriod, uint currPrice) {
262262
AssetConfig memory config = resolveAssetConfig(underlying);
263263
AssetStorage storage assetStorage = eTokenLookup[config.eTokenAddress];
264-
AssetCache memory assetCache = loadAssetCacheRO(underlying, assetStorage);
264+
AssetCache memory assetCache = internalLoadAssetCacheRO(underlying, assetStorage);
265265

266266
(twap, twapPeriod) = getPriceInternal(assetCache, config);
267267

test/maliciousToken.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ et.testSet({
151151
})
152152

153153

154+
.test({
155+
desc: "deposit - transfer from reenters view method",
156+
actions: ctx => [
157+
{ send: 'tokens.TST.configure', args: ['transfer-from/call', et.abiEncode(
158+
['address', 'bytes'],
159+
[
160+
ctx.contracts.eTokens.eTST.address,
161+
ctx.contracts.eTokens.eTST.interface.encodeFunctionData('balanceOfUnderlying', [ctx.wallet.address]),
162+
]
163+
)]},
164+
{ send: 'eTokens.eTST.deposit', args: [0, et.eth(1)], expectError: 'e/ro-reentrancy', },
165+
],
166+
})
167+
168+
154169
.test({
155170
desc: "withdraw - underflow",
156171
actions: ctx => [

0 commit comments

Comments
 (0)