Skip to content

The mitigation results in KIBToken not supporting users to transfer token to themselves (not ERC20 compliant) #4

Closed
@code423n4

Description

@code423n4

Lines of code

https://github.com/code-423n4/2023-02-kuma/blob/f5c7649ecc9650d2f634584e2712014e804f3bbc/src/kuma-protocol/KIBToken.sol#L273-L275

Vulnerability details

Impact

Users will not be able to transfer KIBToken to themselves after the mitigation.
This is not ERC20 compliant.

Proof of Concept

Function KIBToken._transfer() will revert when to == from:

function _transfer(address from, address to, uint256 amount) internal override {
    ...
    if (to == from) {
        revert Errors.CANNOT_TRANSFER_TO_SELF();
    }
    ...
}

Tools Used

VS Code

Recommended Mitigation Steps

We should allow users to transfer KIBToken to themselves, but not perform incorrect calculations

diff --git a/src/kuma-protocol/KIBToken.sol b/src/kuma-protocol/KIBToken.sol
index d1977a5..b9cae75 100644
--- a/src/kuma-protocol/KIBToken.sol
+++ b/src/kuma-protocol/KIBToken.sol
@@ -270,9 +270,6 @@ contract KIBToken is IKIBToken, ERC20PermitUpgradeable, UUPSUpgradeable {
         if (to == address(0)) {
             revert Errors.ERC20_TRANSER_TO_THE_ZERO_ADDRESS();
         }
-        if (to == from) {
-            revert Errors.CANNOT_TRANSFER_TO_SELF();
-        }
         _refreshCumulativeYield();
         _refreshYield();

@@ -280,6 +277,11 @@ contract KIBToken is IKIBToken, ERC20PermitUpgradeable, UUPSUpgradeable {
         if (startingFromBalance < amount) {
             revert Errors.ERC20_TRANSFER_AMOUNT_EXCEEDS_BALANCE();
         }
+        if (from == to) {
+            emit Transfer(from, to, amount);
+            return;
+        }
+
         uint256 newFromBalance = startingFromBalance - amount;
         uint256 newToBalance = this.balanceOf(to) + amount;

Metadata

Metadata

Assignees

No one assigned

    Labels

    MR-H-01QA (Quality Assurance)Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntaxdowngraded by judgeJudge downgraded the risk level of this issuegrade-cunsatisfactorydoes not satisfy C4 submission criteria; not eligible for awards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions