-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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.
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.
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 theonPersistmethod to eliminate repeated use of thevalues()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:
go-ethereum/contracts/solidity/Governance.sol
Line 313 in ca856ce
| address[] memory candidates = candidateList.values(); |
go-ethereum/contracts/solidity/Governance.sol
Line 325 in ca856ce
| currentConsensus = _computeConsensus(); |

