code-423n4 / 2023-05-ajna-findings

2 stars 0 forks source link

Integer Overflow in ScreeningVote Function of StandardFunding.sol. #430

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-05-ajna/blob/276942bc2f97488d07b887c8edceaaab7a5c3964/ajna-grants/src/grants/base/StandardFunding.sol#L711-L712

Vulnerability details

Impact

In the _screeningVote function of StandardFunding.sol contract, specifically in the line where the votes parameter is converted to a uint128 using the SafeCast.toUint128 function. The issue is that the votes_ parameter is not limited to 128 bits, which can result in an integer overflow. If an attacker can successfully exploit this vulnerability, they could potentially gain control over the proposal, which could allow them to influence the outcome of the vote and potentially steal funds.

Proof of Concept

#L711-L712

proposal_.votesReceived += SafeCast.toUint128(votes_);

The SafeCast.toUint128() function is used to convert the votes_ parameter into a uint128 data type. The issue is that the votes_ parameter is not limited to 128 bits, which can result in an integer overflow.

For Example:

Alice would call the _screeningVote function with the appropriate parameters, passing in her own address, the proposal object she created, and a votes_ parameter set to 2^129. Here is an example of the code she might use:

uint256 votes = 2**129;
Proposal storage myProposal = proposals[proposalId];
_screeningVote(msg.sender, myProposal, votes);

Note that proposalId should be the identifier for the proposal that Alice created earlier, and proposals should be the mapping that stores all the proposals.

Tools Used

vscode

Recommended Mitigation Steps

Replace the SafeCast.toUint128() function with a function that limits the votes_ parameter to 128 bits before conversion. Alternatively, convert the votes_ parameter to a larger data type before conversion to a uint128 data type to avoid integer overflow.

Assessed type

Under/Overflow

c4-judge commented 1 year ago

Picodes marked the issue as unsatisfactory: Invalid