Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more efficient calls to DAO functions #4

Open
code423n4 opened this issue Jul 15, 2021 · 0 comments
Open

more efficient calls to DAO functions #4

code423n4 opened this issue Jul 15, 2021 · 0 comments
Assignees

Comments

@code423n4
Copy link
Contributor

Handle

gpersoon

Vulnerability details

Impact

Sometimes the reference to function calls, that are done via the DAO, are looked up multiple times in one function call.
For example mintSynth calls: ​

  • _DAO() 4x
  • _DAO().UTILS() 3x

This can be done more efficient by caching the result of _DAO() and _DAO().UTILS()

f## Proof of Concept
// https://github.com/code-423n4/2021-07-spartan/blob/main/contracts/Pool.sol#L229
​function mintSynth(address synthOut, address member) external returns(uint outputAmount, uint fee) {
​require(iSYNTHFACTORY(_DAO().SYNTHFACTORY()).isSynth(synthOut) == true, "!synth"); // Must be a valid Synth
​..
​uint output = iUTILS(_DAO().UTILS()).calcSwapOutput(_actualInputBase, baseAmount, tokenAmount); // Calculate value of swapping SPARTA to the relevant underlying TOKEN
​uint _liquidityUnits = iUTILS(_DAO().UTILS()).calcLiquidityUnitsAsym(_actualInputBase, address(this)); // Calculate LP tokens to be minted
​..
​uint _fee = iUTILS(_DAO().UTILS()).calcSwapFee(_actualInputBase, baseAmount, tokenAmount); // Calc slip fee in TOKEN
​fee = iUTILS(_DAO().UTILS()).calcSpotValueInBase(TOKEN, _fee); // Convert TOKEN fee to SPARTA

function _DAO() internal view returns(iDAO) {
​return iBASE(BASE).DAO();
​}

//https://github.com/code-423n4/2021-07-spartan/blob/main/contracts/Dao.sol#L624
​function UTILS() public view returns(iUTILS){
​if(daoHasMoved){
​return Dao(DAO).UTILS();
​} else {
​return _UTILS;
​}
​}

Tools Used

Recommended Mitigation Step

Cache _DAO() and cache the sub functions like: _DAO().UTILS())
If called multiple times from function

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jul 15, 2021
code423n4 added a commit that referenced this issue Jul 15, 2021
@SamusElderg SamusElderg self-assigned this Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants