fix: subscribe() was sending tokens out instead of collecting them#13
Open
PragyaTripathi990 wants to merge 1 commit into
Open
fix: subscribe() was sending tokens out instead of collecting them#13PragyaTripathi990 wants to merge 1 commit into
PragyaTripathi990 wants to merge 1 commit into
Conversation
The original subscribe() called pptToken.transfer(msg.sender, SUBSCRIPTION_AMOUNT) which sent tokens TO the subscriber for free instead of charging them. Changed to pptToken.transferFrom(msg.sender, address(this), SUBSCRIPTION_AMOUNT) so the contract correctly pulls the subscription fee from the caller. Added an explicit allowance check with a clear error message so callers know to approve the contract before subscribing. Added TokensWithdrawn event to withdrawTokens() for on-chain auditability. Closes seetadev#1
0ea0c17 to
0a4752c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Critical logic bug:
subscribe()calledpptToken.transfer(msg.sender, SUBSCRIPTION_AMOUNT)which sent 10 PPT tokens to the subscriber for free instead of charging them. Anyone could callsubscribe()and drain the contract's token balance.Fixed by changing to
pptToken.transferFrom(msg.sender, address(this), SUBSCRIPTION_AMOUNT)— the correct pull-payment pattern where the subscriber pays the fee.Also added:
allowancecheck with a human-readable error message so callers understand they need toapprove()the contract before subscribing.TokensWithdrawnevent onwithdrawTokens()for on-chain auditability.Before / After
Test plan
subscribe()without approving → reverts with allowance errorsubscribe()afterapprove(contract, 10e18)→ succeeds, deducts 10 PPT from callersubscribe()twice → reverts with "Already subscribed"Closes #1
🤖 Generated with Claude Code