Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Silvermist - TokenSale.sol#calculateMaxAllocation() Incorrect return values #158

Closed
sherlock-admin2 opened this issue Mar 20, 2024 · 17 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed

Comments

@sherlock-admin2
Copy link

sherlock-admin2 commented Mar 20, 2024

Silvermist

medium

TokenSale.sol#calculateMaxAllocation() Incorrect return values

Summary

A user can have 0 allocations and get themaxAllocation or a user can exceed the maximum allocations.

Vulnerability Detail

maxAllocation is the max baseline a user can invest in a pool. However, swapped return values allow a user to have 0 allocations and get themaxAllocation or to exceed the maximum allocations.

    function calculateMaxAllocation(address _sender) public returns (uint256) {
        uint256 userMaxAllc = _maxTierAllc(_sender);

        if (userMaxAllc > maxAllocation) {
            return userMaxAllc;
        } else {
            return maxAllocation;
        }
    }

Impact

A user can have 0 allocations and get themaxAllocation or a user can exceed the maximum allocations

Code Snippet

https://github.com/sherlock-audit/2024-03-zap-protocol/blob/c2ad35aa844899fa24f6ed0cbfcf6c7e611b061a/zap-contracts-labs/contracts/TokenSale.sol#L259-L267

Tool used

Manual Review

Recommendation

    function calculateMaxAllocation(address _sender) public returns (uint256) {
        uint256 userMaxAllc = _maxTierAllc(_sender);

        if (userMaxAllc > maxAllocation) {
-            return userMaxAllc;
+            return maxAllocation;
        } else {
-            return maxAllocation;
+            return userMaxAllc;

        }
    }

Duplicate of #152

@github-actions github-actions bot added Medium A valid Medium severity issue Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Mar 23, 2024
@Hash01011122 Hash01011122 added Non-Reward This issue will not receive a payout and removed Medium A valid Medium severity issue Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Mar 27, 2024
@Hash01011122 Hash01011122 added Excluded Excluded by the judge without consulting the protocol or the senior and removed Excluded Excluded by the judge without consulting the protocol or the senior labels Mar 27, 2024
@sherlock-admin2 sherlock-admin2 changed the title Elegant Aquamarine Goblin - TokenSale.sol#calculateMaxAllocation() Incorrect return values Silvermist - TokenSale.sol#calculateMaxAllocation() Incorrect return values Mar 28, 2024
@ZdravkoHr
Copy link

Escalate

Since the escalation period is coming to an end and there were no sponsor comments at all, I am escalating this issue because it's not clear if it's indended or not

@sherlock-admin2
Copy link
Author

Escalate

Since the escalation period is coming to an end and there were no sponsor comments at all, I am escalating this issue because it's not clear if it's indended or not

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin3 sherlock-admin3 added the Escalated This issue contains a pending escalation label Mar 31, 2024
@Hash01011122
Copy link
Collaborator

Had the same issue, sponsors weren't responding much so I was unable to confirm whether this was valid issue or design choice.
But on deeper inspection it appears maxAllocation is the default maxAllocation for all users,

@The-first-audit
Copy link

I believe this statement continuously increases user allocation even beyond maximum..

https://github.com/sherlock-audit/2024-03-zap-protocol/blob/c2ad35aa844899fa24f6ed0cbfcf6c7e611b061a/zap-contracts-labs/contracts/TokenSale.sol#L300

thus the reason why the if statement above to regulate the max allocation

@sherlock-admin4
Copy link
Contributor

sherlock-admin4 commented Apr 3, 2024

The protocol team fixed this issue in the following PRs/commits:
https://github.com/Lithium-Ventures/zap-contracts-labs/pull/1

@sherlock-admin2 sherlock-admin2 added Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed labels Apr 3, 2024
@s1ce
Copy link

s1ce commented Apr 3, 2024

@Hash01011122 @Czar102 Just noticed this but my issue #172 is incorrectly marked a duplicate of #152 when it is a duplicate of this issue instead. Honestly thought all of these were duplicates until I took a closer look.

@Evert0x
Copy link

Evert0x commented Apr 8, 2024

@Hash01011122 Do I understand correctly that you want to make this report valid?

@Hash01011122
Copy link
Collaborator

@Evert0x Yeah this is a valid finding and sponsors have confirmed it too.

@the-first-elder

This comment was marked as off-topic.

@Evert0x
Copy link

Evert0x commented Apr 9, 2024

Planning to accept escalation and make issue family Medium

@s1ce
Copy link

s1ce commented Apr 9, 2024

@Evert0x Can you make sure to duplicate #172 with this? It is the same issue but was duplicated with something else incorrectly.

@Hash01011122 please confirm

@Evert0x
Copy link

Evert0x commented Apr 10, 2024

@Hash01011122 revisiting the issue.

It's unclear what the protocol intention is with this function. It's one of the two below.

  1. It's a sanity check, if userMaxAllc is higher than the global limit maxAllocation, make sure that everyone adheres to the global limit. This would make the issue valid.

  2. It's a design choice to allow specific users to exceed the maxAllocation, this would make the issue invalid.

Is there any code comment / discord message that indicates the intention of the protocol team?

@Evert0x
Copy link

Evert0x commented Apr 10, 2024

I believe it's clear that 2) is the case https://discord.com/channels/812037309376495636/1217849746845339678/1219806056625078313

Planning to reject escalation and keep issue invalid

@The-first-audit
Copy link

The protocol team fixed this issue in PR/commit https://github.com/Lithium-Ventures/zap-contracts-labs/pull/1.

I think if the protocol intended it to exceed max. They won’t fix it as stated above.

@Evert0x
Copy link

Evert0x commented Apr 15, 2024

Result:
Invalid
Has Duplicates

@sherlock-admin4
Copy link
Contributor

sherlock-admin4 commented Apr 15, 2024

Escalations have been resolved successfully!

Escalation status:

@sherlock-admin2 sherlock-admin2 removed the Escalated This issue contains a pending escalation label Apr 15, 2024
@sherlock-admin3 sherlock-admin3 added the Escalation Resolved This issue's escalations have been approved/rejected label Apr 15, 2024
@Evert0x Evert0x added the Medium A valid Medium severity issue label Apr 20, 2024
@sherlock-admin4 sherlock-admin4 added Reward A payout will be made for this issue and removed Non-Reward This issue will not receive a payout labels Apr 20, 2024
@sherlock-admin2 sherlock-admin2 added the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label Apr 21, 2024
@sherlock-admin2
Copy link
Author

The Lead Senior Watson signed off on the fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed
Projects
None yet
Development

No branches or pull requests

9 participants