fix(globe-wallet): use case-insensitive matching for native XLM checks (closes #86) - #112
Open
rupesh-kumar-sah wants to merge 1 commit into
Conversation
closes Orbit-Wal#86) - Align is_native check in add_asset with duplicate detection via codes_match_case_insensitive - Reject any case-variant of XLM that specifies an issuer with InvalidAssetInfo - Prevent malicious or accidental pre-squatting of case-variant 'xlm' from blocking native XLM registration - Add test proving lowercase/mixed-case 'xlm' with issuer is rejected and real native XLM registration succeeds
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.
Issue
Closes #86
Root cause
In
GlobeWallet::add_asset(contracts/globe-wallet/src/lib.rs), asset code duplicate detection was historically updated to use case-insensitive equality (codes_match_case_insensitive), but the native asset check remained strict case-sensitive equality:Because of this mismatch:
"xlm"with an issuer bypassedis_native(since"xlm" != "XLM"), fell to the non-native branch whereissuer.is_some()was satisfied, and successfully registered as a valid asset.code: "XLM", issuer: None), the duplicate detection loop compared"XLM"against the existing"xlm"case-insensitively, detected a match, and rejected the registration withAssetAlreadyAdded.Decision on case-variants with issuer:
Any case-variant of
"XLM"(e.g."xlm","Xlm","xLm") that provides an issuer is rejected outright withWalletError::InvalidAssetInfo. There is no legitimate use case on Stellar for an issued asset masquerading under any case-variant of the native token symbol, and treating all case-variants consistently ensures that no squatted entry can bypass native checks.What changed and why
Updated the
is_nativecheck inGlobeWallet::add_assetto use the canonical case-insensitive helper:Now, any asset code matching
"XLM"(case-insensitive) that provides an issuer is rejected withWalletError::InvalidAssetInfo. Real native XLM ("XLM"withissuer: None) continues to register cleanly on the happy path.Definition of done — addressed item by item
is_nativecheck uses the same canonicalization as the duplicate-detection loop: Changedasset.code == String::from_str(&env, "XLM")toSelf::codes_match_case_insensitive(&asset.code, &String::from_str(&env, "XLM"))."xlm"(with any issuer) is rejected the same way an uppercase duplicate would be, before the real native XLM is ever registered: Verified intest_case_variant_xlm_with_issuer_rejected_and_cannot_squat_nativethat"xlm"and"Xlm"with an issuer returnErr(Ok(WalletError::InvalidAssetInfo)).test_case_variant_xlm_with_issuer_rejected_and_cannot_squat_nativethat subsequent registration ofAssetInfo { code: "XLM", issuer: None }succeeds withOk(Ok(())).InvalidAssetInfo.cargo test --workspaceoutput pasted: Pasted below under Evidence.Evidence this actually runs
Tests
Added
test_case_variant_xlm_with_issuer_rejected_and_cannot_squat_nativeasserting:add_assetwith lowercase"xlm"andSome(fake_issuer)fails withWalletError::InvalidAssetInfo.add_assetwith mixed-case"Xlm"andSome(fake_issuer)fails withWalletError::InvalidAssetInfo.add_assetwith native XLM (code: "XLM",issuer: None) succeeds withOk(()).Regression check
Existing tests verifying native and issued asset rules (
test_native_code_with_issuer_is_contradictory_and_rejected,test_non_native_code_without_issuer_is_underspecified_and_rejected,test_add_and_get_assets,test_add_asset_case_variant_duplicate_fails) were run and all 87 tests passed without failure.Checklist
console.log/TODO/debug code