The crucial logical vulnerability in the provided unregister function lies in the handling of token approvals. When a user chooses to unregister themselves, the function improperly calculates the new allowance, thereby potentially approving a higher amount of tokens than intended.
The line of code:
is problematic. This line directly adds the amount the user had registered with to the existing allowance that the contract (address(this)) has already granted to msg.sender. If not properly controlled or audited, this can allow a user to repeatedly unregister and each time increase their permitted allowance unboundedly.
Initial Setup: Assume a user, Alice, has previously registered some tokens under a specific kind and the contract holds an allowance to dispense these tokens back to Alice when she unregisters.
First Unregister: Alice calls unregister for her token category (kind). By the function's logic, this adds her registered amount back to whatever existing allowance was previously set (typically this would initially be zero before the first unregister).
Before Second Invocation: At this point, the tokens are not transferred back yet. They are only approved for Alice to withdraw. Moreover, the amount used for adding to the allowance does get deleted from the registration mapping, but the faulty token approval remains valid.
Register Again: Alice re-registers the same or a lesser amount under the same kind. Since the safeguard against allowing registration only if the current registration is zero is not explicitly shown in the provided snippet, we consider that registration is possible again.
Second Unregister: Alice proceeds to unregister again. As per the function logic, the same amount now gets added again to the previous allowance which was mistakenly not reset but increased during her first unregister.
This process can be repeated (registering and unregistering) indefinitely, whereby each cycle Alice's allowance from the contract keeps increasing without an actual transfer of tokens back to her, potentially leading to her possessing an erroneously high allowance that she could exploit to withdraw funds beyond her actual holdings.
The absence of resetting or appropriately recalculating allowances upon each unregister operation poses a significant threat. Each cycle of unregister followed by register allows an exploitative increment of the allowance that could lead to malicious withdrawal behaviors undermining the token management system of the contract. This could ultimately lead to faults in accounting integrity, unauthorized access to tokens, or systemic failures in token economics where the contract is employed.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.