Skip to content

Validate token contract exists before group creation#121

Open
WuXieSec wants to merge 1 commit intosorosave-protocol:mainfrom
WuXieSec:feat/add-token-validation
Open

Validate token contract exists before group creation#121
WuXieSec wants to merge 1 commit intosorosave-protocol:mainfrom
WuXieSec:feat/add-token-validation

Conversation

@WuXieSec
Copy link
Copy Markdown

This PR adds validation to ensure the provided token address is a valid Stellar asset contract, as requested in #62.

Changes:

  • Call token contract's symbol() to verify it exists
  • Return InvalidToken error if contract call fails
  • Add InvalidToken variant to ContractError enum
  • Add test coverage for valid and invalid tokens

Why this matters:
Without validation:

  • Groups could be created with invalid token addresses
  • Contributions would fail later with cryptic errors
  • Users would waste gas on broken groups
  • Contract state would be polluted with unusable groups

Implementation:
Uses try_symbol() to safely check if the token contract exists and implements the token interface. If the call fails, group creation is rejected with InvalidToken.

Test coverage:

  • ✅ Valid token contract → group created successfully
  • ❌ Random address (not a contract) → InvalidToken
  • ❌ Non-token contract address → InvalidToken

Closes #62

Changes:
- Call token contract's symbol() to verify it exists
- Return InvalidToken error if contract call fails
- Add InvalidToken variant to ContractError enum
- Add test coverage for valid and invalid tokens

This prevents groups from being created with invalid
or non-existent token contracts.

Closes sorosave-protocol#62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate token contract exists before group creation

1 participant