Livepeer Onchain Treasury Upgrade - turvy_fuzz's results

Decentralized video infrastructure protocol powering video in web3's leading social and media applications.

General Information

Platform: Code4rena

Start Date: 31/08/2023

Pot Size: $55,000 USDC

Total HM: 5

Participants: 30

Period: 6 days

Judge: hickuphh3

Total Solo HM: 2

Id: 282

League: ETH

Livepeer

Findings Distribution

Researcher Performance

Rank: 24/30

Findings: 1

Award: $27.00

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: c3phas

Also found by: 0x11singh99, 0x3b, 0xta, JCK, K42, ReyAdmirado, SAQ, Sathish9098, hunter_w3b, kaveyjoe, lsaudit, turvy_fuzz

Labels

bug
G (Gas Optimization)
grade-b
G-06

Awards

27.0048 USDC - $27.00

External Links

Costly redundant operation in _handleVoteOverrides() and _countVote() on storage mapping can be prevented

when _countVote() is called, it makes a call to _handleVoteOverrides() which handles vote overrides that delegators can make to their corresponding delegated transcoder votes. Within this function, it also makes a costly operation with the storage tally mapping which later gets remodified again in the _countVote() as part of the overriding process. However when voters.support is the same as delegateVoter.support, this costly tally modification and remodification are not needed as it just going to cost more.

Below is the suggested revised code to save this redundant operation:

function _handleVoteOverrides(
        uint256 _proposalId,
        ProposalTally storage _tally,
        ProposalVoterState storage _voter,
        address _account,
        uint256 _weight
+   ) internal returns (uint256, bool) {
-    ) internal returns (uint256) {
        uint256 timepoint = proposalSnapshot(_proposalId);
        address delegate = votes().delegatedAt(_account, timepoint);

        bool isTranscoder = _account == delegate;
        if (isTranscoder) {
            // deduce weight from any previous delegators for this transcoder to
            // make a vote
+            return (_weight - _voter.deductions, false);
-            return _weight - _voter.deductions;
        }

        // this is a delegator, so add a deduction to the delegated transcoder
        ProposalVoterState storage delegateVoter = _tally.voters[delegate];
        delegateVoter.deductions += _weight;

        if (delegateVoter.hasVoted) {
            // this is a delegator overriding its delegated transcoder vote,
            // we need to update the current totals to move the weight of
            // the delegator vote to the right outcome.
            VoteType delegateSupport = delegateVoter.support;
+            if (delegateSupport == _voters.support) return (_weight, true);

            if (delegateSupport == VoteType.Against) {
                _tally.againstVotes -= _weight;
            } else if (delegateSupport == VoteType.For) {
                _tally.forVotes -= _weight;
            } else {
                assert(delegateSupport == VoteType.Abstain);
                _tally.abstainVotes -= _weight;
            }
        }

+        return (_weight, false);
-        return _weight;
    }

in _countVotes()

+  (_weight, bool isSame) = _handleVoteOverrides(_proposalId, tally, voter, _account, _weight);
-  _weight = _handleVoteOverrides(_proposalId, tally, voter, _account, _weight);

+  if (isSame) return;

if (support == VoteType.Against) {
      tally.againstVotes += _weight;
} else if (support == VoteType.For) {
      tally.forVotes += _weight;
} else {
      tally.abstainVotes += _weight;
}

#0 - c4-judge

2023-09-21T10:35:02Z

HickupHH3 marked the issue as grade-c

#1 - c4-judge

2023-09-21T10:36:20Z

HickupHH3 marked the issue as grade-b

#2 - HickupHH3

2023-09-21T10:36:29Z

decent recommendation!

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter