Skip to content

feat: add support for cached wallets in cosmos#69

Merged
swift1337 merged 2 commits into
mainfrom
feat/cosmos-cached-wallets
May 1, 2026
Merged

feat: add support for cached wallets in cosmos#69
swift1337 merged 2 commits into
mainfrom
feat/cosmos-cached-wallets

Conversation

@swift1337
Copy link
Copy Markdown
Collaborator

No description provided.

@swift1337 swift1337 requested a review from a team as a code owner April 28, 2026 20:58
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR adds support for reading pre-cached Ethereum-format wallet files in the Cosmos runner, allowing wallets generated by the Ethereum runner to be reused on EVM-compatible Cosmos chains. The implementation follows the pattern already established in chains/ethereum/wallet/wallet.go.

  • P1 – potential panic in bootstrapped distribution: ReadCachedPrivateKeys silently returns fewer keys than requested when the cache file has fewer entries than spec.NumWallets. If spec.InitialWallets falls between the actual cache count and spec.NumWallets, NewBootstrapped is initialised with fundedWallets > len(wallets), setting ReceiverIndex out of bounds and causing a panic on the first GetNextReceiver() call.

Confidence Score: 3/5

Not safe to merge as-is — a realistic misconfiguration can cause a runtime panic in the bootstrapped wallet distribution.

One P1 finding: when the cache has fewer wallets than spec.NumWallets and spec.InitialWallets is configured between those two values, the bootstrapped distribution receives an out-of-bounds receiver index and panics. This is a present defect on a real code path introduced by this PR.

chains/cosmos/wallet/cache.go — the num > len(cachedKeys) case needs an error return rather than silent truncation.

Important Files Changed

Filename Overview
chains/cosmos/wallet/cache.go New file that reads Ethereum-format cached private keys; silently accepts fewer keys than requested which can cause an out-of-bounds panic in bootstrapped wallet distribution, and contains a broken doc reference.
chains/cosmos/runner/runner.go Adds cache-read branch before mnemonic derivation; logic is clean but inherits the wallet-count shortfall risk from cache.go since it only guards against zero keys, not fewer-than-requested keys.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[NewRunner called] --> B{spec.Cache.ReadWalletsFrom != empty?}
    B -- Yes --> C[wallet.ReadCachedPrivateKeys]
    C --> D{num > 0 && num < len cache?}
    D -- Yes --> E[Truncate to num keys]
    D -- No --> F[Use all cached keys]
    E --> G[privKeys = cachedPKs]
    F --> G
    B -- No --> H{spec.NumWallets > 0?}
    H -- Yes --> I[Derive keys from mnemonic]
    H -- No --> J[len privKeys == 0 error]
    I --> K[privKeys = derived keys]
    G --> L{len privKeys == 0?}
    K --> L
    L -- Yes --> J
    L -- No --> M[Create InteractingWallets]
    M --> N{spec.InitialWallets configured?}
    N -- Yes --> O[NewBootstrapped fundedWallets=spec.InitialWallets]
    O --> P{fundedWallets > len wallets? Cache shortfall!}
    P -- Yes --> Q[Panic: ReceiverIndex out of range]
    P -- No --> R[Runner ready]
    N -- No --> R
Loading

Reviews (1): Last reviewed commit: "Add support for cached wallets in cosmos" | Re-trigger Greptile

Comment thread chains/cosmos/wallet/cache.go
Comment thread chains/cosmos/wallet/cache.go Outdated
@swift1337 swift1337 merged commit 16318cb into main May 1, 2026
3 checks passed
@swift1337 swift1337 deleted the feat/cosmos-cached-wallets branch May 1, 2026 11:35
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.

2 participants