Unnecessary internal function call in 'modifyVote' function costs gas inefficiency
Summary
The '_modifyVote' function in the EthosVote contract includes an unnecessary internal function call, which increases gas consumption. Since the function is called only once in the contract, using an internal call here introduces avoidable JUMP instructions and stack operations. This inefficiency result in higher gas fees for users, particularly for contracts deployed on mainnet, where gas costs can significantly impact usage.
In EthosVote.sol:166-201, the internal function was called only once throughout the contract. Internal functions cost more gas due to additional JUMP instructions and stack operations.
Example:
The choice to use internal function and it being only called once throughout the contract will only cost more gas due to the additional JUMP instructions add overhead to vote toggling operations.
Internal pre-conditions
'_modifyVote' is called to toggle or modify votes within the EthosVote contract.
Votes frequently updated or modified by users.
Gas consumption is a critical factor, especially when deployed on the mainnet.
External pre-conditions
Gas prices on the mainnet is high, causing increased transaction fees for users interacting with the voting contract.
Users are expected to frequently call '_modifyVote' for upvote/downvote operations, resulting in cumulative gas inefficiencies.
Attack Path
User calls '_modifyVote' to upvote or downvote, resulting in a gas consumption higher than necessary due to the internal function call, particularly on mainnet.
Impact
The protocol would suffer from increased transaction costs per '_modifyVote' function call. Users incur additional fees without any added benefit, as the unnecessary internal function call adds extra steps to each vote update.
PoC
No response
Mitigation
The internal function should be in-lined directly within the calling function to reduce gas costs associated with stack operations and function calls.
Soft Tangerine Kitten
Low/Info
Unnecessary internal function call in 'modifyVote' function costs gas inefficiency
Summary
The '_modifyVote' function in the EthosVote contract includes an unnecessary internal function call, which increases gas consumption. Since the function is called only once in the contract, using an internal call here introduces avoidable JUMP instructions and stack operations. This inefficiency result in higher gas fees for users, particularly for contracts deployed on mainnet, where gas costs can significantly impact usage.
Root Cause
https://github.com/sherlock-audit/2024-10-ethos-network/blob/main/ethos/packages/contracts/contracts/EthosVote.sol#L166
In
EthosVote.sol:166-201
, the internal function was called only once throughout the contract. Internal functions cost more gas due to additional JUMP instructions and stack operations.Example:
Internal pre-conditions
External pre-conditions
Attack Path
Impact
The protocol would suffer from increased transaction costs per '_modifyVote' function call. Users incur additional fees without any added benefit, as the unnecessary internal function call adds extra steps to each vote update.
PoC
No response
Mitigation
The internal function should be in-lined directly within the calling function to reduce gas costs associated with stack operations and function calls.