Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function getPastTotalLocks may return incorrect values #84

Closed
code423n4 opened this issue Apr 2, 2022 · 2 comments
Closed

Function getPastTotalLocks may return incorrect values #84

code423n4 opened this issue Apr 2, 2022 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists invalid This doesn't seem right sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-03-paladin/blob/9c26ec8556298fb1dc3cf71f471aadad3a5c74a0/contracts/HolyPaladinToken.sol#L515-L529

Vulnerability details

Impact

totalLocks array can contain elements with the same fromBlock property but different total locked amounts. This edge case is not considered in the implementation of getPastTotalLock function, which returns a value as soon as it finds a TotalLock with matching fromBlock property (see HolyPaladinToken.sol:520-522). If there are more total locks with the same block number that function should return the latest one, i.e. the one with the highest index.
In its current implementation getPastTotalLock function can also return a different value after changing the length of the log, either from the correct value to an incorrect or the other way.

Recommended mitigation steps

There are two obvious ways of fixing this issue: either by removing the check in HolyPaladinToken.sol:520-522)) or by not allowing adding elements to the totalLocks array with the same fromBlock properties. While both ways are viable, the latter one is preferred as it is a gas optimization.
Checks should be added whether or not the block number of the last element of totalLocks array is equal to the current block number, and if it is, modify that element instead of adding a new one.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Apr 2, 2022
code423n4 added a commit that referenced this issue Apr 2, 2022
@Kogaroshi Kogaroshi added duplicate This issue or pull request already exists sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels Apr 3, 2022
@Kogaroshi
Copy link
Collaborator

Duplicate of #20
See in this issue for PR with changes

@0xean
Copy link
Collaborator

0xean commented Apr 8, 2022

closing as same warden submitted #86 with the same vulnerability.

@0xean 0xean closed this as completed Apr 8, 2022
@0xean 0xean added invalid This doesn't seem right and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists invalid This doesn't seem right sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants