sherlock-audit / 2024-10-ethos-network-judging

0 stars 0 forks source link

Soft Tangerine Kitten - Unnecessary internal function call in 'modifyVote' function costs gas inefficiency #323

Closed sherlock-admin3 closed 3 weeks ago

sherlock-admin3 commented 3 weeks ago

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

  1. '_modifyVote' is called to toggle or modify votes within the EthosVote contract.
  2. Votes frequently updated or modified by users.
  3. Gas consumption is a critical factor, especially when deployed on the mainnet.

External pre-conditions

  1. Gas prices on the mainnet is high, causing increased transaction fees for users interacting with the voting contract.
  2. Users are expected to frequently call '_modifyVote' for upvote/downvote operations, resulting in cumulative gas inefficiencies.

Attack Path

  1. 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.