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

Rename functions to reduce gas costs #185

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bxmmm1
Copy link
Contributor

@bxmmm1 bxmmm1 commented Jul 19, 2022

See issue for description and explanation

@bxmmm1 bxmmm1 self-assigned this Jul 19, 2022
@bxmmm1 bxmmm1 linked an issue Jul 19, 2022 that may be closed by this pull request
1 task
@@ -430,13 +430,13 @@
/// @notice claims rewards from a specific pool
/// @param _pid the id of the pool
/// @param _gauge address of the gauge
function claimRewards(uint256 _pid, address _gauge) external {
function claimRewards_poF(uint256 _pid, address _gauge) external {

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Parameter Controller.claimRewards_poF(uint256,address)._gauge (contracts/Controller.sol#444) is not in mixedCase
@@ -208,13 +208,18 @@

/// @notice Claims rewards from a pool and disperses them to the rewards contract
/// @param _pid the id of the pool where lp tokens are held
function earmarkRewards(uint256 _pid) external;
/// weird naming reduces gas cost
function earmarkRewards_pcp(uint256 _pid) external;

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Function IController.earmarkRewards_pcp(uint256) (contracts/utils/Interfaces.sol#227) is not in mixedCase
@@ -227,8 +232,11 @@
bool
);

function claimRewards(uint256, address) external;
/// weird naming reduces gas cost
function claimRewards_poF(uint256, address) external;

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Function IController.claimRewards_poF(uint256,address) (contracts/utils/Interfaces.sol#251) is not in mixedCase

function claimRewards() external;
function claimRewards_6H10() external;

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Function IStash.claimRewards_6H10() (contracts/utils/Interfaces.sol#133) is not in mixedCase
@@ -430,13 +430,13 @@
/// @notice claims rewards from a specific pool
/// @param _pid the id of the pool
/// @param _gauge address of the gauge
function claimRewards(uint256 _pid, address _gauge) external {
function claimRewards_poF(uint256 _pid, address _gauge) external {

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Parameter Controller.claimRewards_poF(uint256,address)._pid (contracts/Controller.sol#444) is not in mixedCase
@@ -62,7 +62,7 @@

function release() external;

function claimBal(address _gauge) external returns (uint256);
function claimBal__mo(address _gauge) external returns (uint256);

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Function IVoterProxy.claimBal__mo(address) (contracts/utils/Interfaces.sol#77) is not in mixedCase
@@ -485,27 +485,27 @@
}

/// @inheritdoc IController
function earmarkRewards(uint256 _pid) external {
function earmarkRewards_pcp(uint256 _pid) external {

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Parameter Controller.earmarkRewards_pcp(uint256)._pid (contracts/Controller.sol#499) is not in mixedCase
@@ -116,9 +116,9 @@
}

interface IStash {
function processStash() external;
function processStash_WfQ() external;

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Function IStash.processStash_WfQ() (contracts/utils/Interfaces.sol#131) is not in mixedCase
@@ -179,17 +179,17 @@
/// @notice Claims VeBal tokens
/// @param _gauge The gauge to claim from
/// @return amount claimed
function claimBal(address _gauge) external onlyOperator returns (uint256) {
function claimBal__mo(address _gauge) external onlyOperator returns (uint256) {

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Parameter VoterProxy.claimBal__mo(address)._gauge (contracts/VoterProxy.sol#182) is not in mixedCase

/// @notice Claims rewards from the Balancer's fee distributor contract and transfers the tokens into the rewards contract
function earmarkFees() external;
/// weird naming reduces gas cost
function earmarkFees_F4P() external;

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions

Function IController.earmarkFees_F4P() (contracts/utils/Interfaces.sol#231) is not in mixedCase
@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Merging #185 (77016ce) into main (27f856f) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 77016ce differs from pull request most recent head 110c837. Consider uploading reports for the commit 110c837 to get more accurate results

@@           Coverage Diff           @@
##             main     #185   +/-   ##
=======================================
  Coverage   99.85%   99.85%           
=======================================
  Files          13       13           
  Lines         697      697           
  Branches       88       88           
=======================================
  Hits          696      696           
  Misses          1        1           
Impacted Files Coverage Δ
contracts/Controller.sol 100.00% <100.00%> (ø)
contracts/ExtraRewardStash.sol 100.00% <100.00%> (ø)
contracts/VoterProxy.sol 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27f856f...110c837. Read the comment docs.

@bxmmm1 bxmmm1 requested a review from BritikovKI July 19, 2022 11:50
@BritikovKI
Copy link
Contributor

BritikovKI commented Jul 19, 2022

Just tbh I don't like this solution. I understand that it maybe saves 40 gas for each call, which is like 10^11 wei, but what we have is 10^18 is one ether, which means we need to have 10 000 000 calls to reach the price of 1 ether. And due to the fact that the contract call is let's say 20-40k gas, this thing is just 0,1% increase of the cost, but in return we get beautiful and easier to read/understand function names.
Huge protocols like Uniswap/Sushi/Balancer/Curve don't do this magic for the contract names. If we will need to truly optimize costs, it's a lot better and more optimal to use inline bytecode or develop in Yul/Viper

@bxmmm1
Copy link
Contributor Author

bxmmm1 commented Jul 22, 2022

Just tbh I don't like this solution. I understand that it maybe saves 40 gas for each call, which is like 10^11 wei, but what we have is 10^18 is one ether, which means we need to have 10 000 000 calls to reach the price of 1 ether. And due to the fact that the contract call is let's say 20-40k gas, this thing is just 0,1% increase of the cost, but in return we get beautiful and easier to read/understand function names. Huge protocols like Uniswap/Sushi/Balancer/Curve don't do this magic for the contract names. If we will need to truly optimize costs, it's a lot better and more optimal to use inline bytecode or develop in Yul/Viper

Normal name earmarkRewards consumes 252510 and weird name one 252395. The difference is 115.
I got these values by running npm run test on main / this branch.

Convex called earmarkRewards 125903 times from the start (8/05/21)
https://bloxy.info/txs/calls_sc/0xf403c135812408bfbe8713b5a23a04b3d48aae31?signature_id=1913750

Let's say that we do half of that.
For 62951 calls * 115 we'd save ~ 7 239 365.
I agree that it is important to have nice and readable functions that are intended to be called by the public, but for these functions, it shouldn't matter that much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chore: Gas optimization for external function names
2 participants