Skip to content

fix(keystore): throw on address mismatch instead of silently warning#2

Open
amathxbt wants to merge 1 commit into
canopy-network:mainfrom
amathxbt:fix/keystore-address-mismatch-silent
Open

fix(keystore): throw on address mismatch instead of silently warning#2
amathxbt wants to merge 1 commit into
canopy-network:mainfrom
amathxbt:fix/keystore-address-mismatch-silent

Conversation

@amathxbt

Copy link
Copy Markdown

Bug

importFromGoKeystore() verifies that the address derived from the public key matches entry.keyAddress, but responds to a mismatch with only a console.warn. The mismatched entry is then silently returned to the caller using the stored (wrong) address.

Impact: A corrupted or tampered keystore entry is accepted without error. Subsequent transactions are built with an address that does not match the signing key, so they are either rejected by the network or—if the stored address belongs to a different key—send funds to an uncontrolled account.

Fix

Replace console.warn with a thrown Error that identifies both addresses. Callers that handle keystore entries should catch this to surface integrity failures before any funds are at risk.

// Before
console.warn(`Address mismatch: expected ${entry.keyAddress}, derived ${derivedAddress}`);

// After
throw new Error(
  `Keystore integrity check failed: stored address ${entry.keyAddress} does not match ` +
  `address derived from public key ${derivedAddress}. The keystore entry may be corrupted or tampered.`
);

importFromGoKeystore() compared the stored keyAddress against the address
derived from the public key, but only issued a console.warn on mismatch
and then silently returned the stored (wrong) address.

A corrupted or tampered keystore entry would be accepted without error,
causing outgoing transactions to be signed with a key that does not match
the on-chain address — resulting in fund loss or permanently rejected txs.

Fix: throw an Error with a clear message so callers can detect and reject
integrity failures before any funds are at risk.
@andrewnguyen22 andrewnguyen22 requested a review from ezeike June 27, 2026 19:28
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