Skip to content

fix(wallet): decrypt the private balance with the SDK's own eERC key#96

Open
hitakshiA wants to merge 1 commit into
mainfrom
fix/eerc-private-balance-decryption-key
Open

fix(wallet): decrypt the private balance with the SDK's own eERC key#96
hitakshiA wants to merge 1 commit into
mainfrom
fix/eerc-private-balance-decryption-key

Conversation

@hitakshiA

@hitakshiA hitakshiA commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Every shielded balance rendered $0.00 on the Home screen even though the deposit landed on-chain (activity showed +$1.00).

Root cause

The eERC SDK's register() ignores the decryptionKey passed to the EERC constructor and derives its own key from a deterministic wallet signature (generateDecryptionKey), binding the on-chain public key + ElGamal-encrypted balance to that key. Our read path built a fresh EERC with account.eercDecryptionKey and never called generateDecryptionKey, so calculateTotalBalance decrypted with the wrong key, failed its eGCT verify, and returned 0.

Fix

createEerc now calls await eerc.generateDecryptionKey() up front, so reads/transfers/deposits use the same key registration used. The signature is local (self-custody key) and deterministic, so it is stable across sessions and retroactively fixes already-registered wallets.

Verification

  • Proven on-chain: a fresh wallet's 0.04 USDC deposit now decrypts to 40000 (was 0).
  • Driven headless on live Fuji: create, shield ($1.00 shows), send (recipient received $1), cash out — all green.
  • 217 tests, typecheck, lint, build pass.

Summary by CodeRabbit

  • Bug Fixes
    • Wallet setup now automatically generates and installs the required decryption key for chain-related operations.
    • Improved reliability when initializing encrypted wallet functionality.

Greptile Summary

This PR updates the wallet eERC setup to use the SDK-derived key.

  • Calls generateDecryptionKey() when creating an EERC instance.
  • Keeps the SDK key aligned with registered shielded balances.
  • Adds the new SDK method to the shield test mock.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/wallet/src/lib/eerc.ts Creates the EERC instance, derives the SDK decryption key, and returns the initialized instance.
apps/wallet/src/lib/eerc.shield.test.ts Adds generateDecryptionKey to the hoisted mock used by shield tests.

Reviews (1): Last reviewed commit: "fix(wallet): decrypt the private balance..." | Re-trigger Greptile

The eERC SDK's register() ignores the decryptionKey passed to the EERC
constructor and derives its own from a deterministic wallet signature
(generateDecryptionKey), binding the on-chain public key and the
ElGamal-encrypted balance to THAT key. Our read path constructed a fresh
EERC with account.eercDecryptionKey and never called generateDecryptionKey,
so calculateTotalBalance decrypted with the wrong key, failed its eGCT
verify, and every shielded balance rendered $0.00 even though the deposit
was on-chain (activity showed it correctly).

Have createEerc install the SDK's own key up front. The signature is local
(self-custody key) and deterministic, so it is stable across sessions and
matches whatever key registration used. Verified end-to-end on Fuji: a
fresh wallet that deposited 0.04 USDC now decrypts to 40000 (was 0).
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

createEerc now generates a decryption key before returning the EERC instance. The EERC test mock is updated to expose the new asynchronous method.

Changes

EERC key initialization

Layer / File(s) Summary
Generate and mock the decryption key
apps/wallet/src/lib/eerc.ts, apps/wallet/src/lib/eerc.shield.test.ts
createEerc awaits generateDecryptionKey() after constructing EERC, and the test mock now provides the method.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately captures the main fix: using the SDK's own eERC key to decrypt private balances.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/eerc-private-balance-decryption-key

Comment @coderabbitai help to get the list of available commands.

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.

1 participant