Skip to content

GVN-01 - High Resource Consumption in candidateList [High] #197

@shargon

Description

@shargon

A critical vulnerability related to excessive resource consumption has been identified in the onPersist method of the NeoX Governance contract, which uses the EnumerableSet library. Specifically, the values() method of this library is called multiple times: directly on line 313 and via the _computeConsensus() function on line 325. This method is known for its high gas demand, as it copies all values of the candidateList set in memory, which is described in the OpenZeppelin documentation as potentially expensive.

image

The main concern is that repeatedly using values() in a method that alters the state of the contract increases the gas cost significantly, especially as the candidateList set grows. This increase in gas consumption not only increases operating costs, but also represents a serious security vulnerability.

image

Since the registration of new candidates in candidateList is public, an attacker could exploit this feature to register a large number of candidates, causing the execution of onPersist to consume more resources than can be provided in a block, effectively blocking the function and causing a denial of service (DoS).

Remediation:

  • Limit the use of values() in critical functions: Redesign the onPersist method to eliminate repeated use of the values() method within operations that change the state of the contract. Consider using iterators or alternative mechanisms that do not require copying the entire set into memory.

  • Perform load testing and contract optimization to ensure that key functions can handle a high number of interactions without exceeding resource limits. These tests will help identify and mitigate potential failure points due to excessive gas consumption.

References:

Source references:

address[] memory candidates = candidateList.values();

currentConsensus = _computeConsensus();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions