code-423n4 / 2021-04-vader-findings

1 stars 0 forks source link

Gas savings by replacing public visibility with internal/private for isEqual() function of DAO.sol #181

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

0xRajeev

Vulnerability details

Impact

isEqual() helper function is never meant to be called from outside the contract and so does not require public visibility. As described in https://mudit.blog/solidity-gas-optimization-tips/: “For all the public functions, the input parameters are copied to memory automatically, and it costs gas. If your function is only called externally, then you should explicitly mark it as external. External function’s parameters are not copied into memory but are read from calldata directly. This small optimization in your solidity code can save you a lot of gas when the function input parameters are huge.”

Given the two parameters of isEqual() function, this will save some amount of gas.

Proof of Concept

https://github.com/code-423n4/2021-04-vader/blob/3041f20c920821b89d01f652867d5207d18c8703/vader-protocol/contracts/DAO.sol#L192

Tools Used

Manual Analysis

Recommended Mitigation Steps

Change visibility of isEqual() to internal/private