Skip to content

Commit

Permalink
Report for issue #257 updated by __141345__
Browse files Browse the repository at this point in the history
  • Loading branch information
code423n4 committed Sep 19, 2022
1 parent 58eb56b commit 7159d97
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions data/__141345__-G.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#### FOR-LOOP LENGTH COULD BE CACHED

The for loop length can be cached to memory before the loop, even for memory variables.
Expand Down Expand Up @@ -337,27 +336,63 @@ src/rewards/StakingRewards.sol
mapping(address => uint256) private _balances;
```

#### Unnecessary vault share calculation

Since the share is 1:1 ratio with the deposit, there is no need to call `previewDeposit()`:

```solidity
// src/Vault.sol
165: require((shares = previewDeposit(id, assets)) != 0, "ZeroValue");
```


#### Duplicate call to `totalAssets(id)`

`totalAssets(id)` call is duplicate, it can be called before and pass the result.

```solidity
// src/Controller.sol
220: insrVault.endEpoch(epochEnd, false);
221: riskVault.endEpoch(epochEnd, false);
// src/Vault.sol
function endEpoch(uint256 id, bool depeg)
public
onlyController
marketExists(id)
{
idDepegged[id] = depeg;
idFinalTVL[id] = totalAssets(id);
}
```

#### Duplicate call to `getLatestPrice()`

In `triggerDepeg()`, the call to `getLatestPrice()` is duplicate, including in the modifier. The result can be saved in a local variable, instead of multiple gas intensive calls.

```solidity
// src/Controller.sol
function triggerDepeg(uint256 marketIndex, uint256 epochEnd)
public
isDisaster(marketIndex, epochEnd)
{
// ...
emit DepegInsurance(...,
getLatestPrice(insrVault.tokenInsured())
);
}
modifier isDisaster(uint256 marketIndex, uint256 epochEnd) {
// ...
if(
vault.strikePrice() < getLatestPrice(vault.tokenInsured())
)
revert PriceNotAtStrikePrice(getLatestPrice(vault.tokenInsured()));
// ...
}
```

#### Recycle ended vaults for gas refund













The ended epoch or settled epoch with depeg can delete the vault storage to get some gas refund.

0 comments on commit 7159d97

Please sign in to comment.