EYBlockchain / nightfall_3

a mono-repo containing an optimistic version of nightfall
Creative Commons Zero v1.0 Universal
260 stars 57 forks source link

[Bug?] Client 'incoming-viewing-key' potential issue #1434

Open fullkomnun opened 1 year ago

fullkomnun commented 1 year ago

For nightfall client's 'incoming-viewing-key' request, it stores given 'zkpPrivateKeys' and 'nullifierKeys' in memory, then it tries to use these to sync client commitments using nightfall-client/src/services/commitment-sync.mjs's clientCommitmentSync exported function.

clientCommitmentSync implementation

given a ‘zkpPrivateKey’ and a ‘nullifierKey’ get all transactions, for each transaction:

  1. get all non-zero commitments
  2. conditional: only for ‘transfer’ transaction (identifies by compressedSecrets being not [ZERO,ZERO]) where we have the first non-zero commitment stored
  3. try to decrypt that commitement using the provided ‘zkpPrivateKey’ and ‘nullifierKey’

However, the condition is:

countCommitments([nonZeroCommitments[0]]) === 0

where countCommitments returns a Promise but is comapred to a numeric literal so condition will never be met (supposedly) which means it will not decrypt any commitments already stored prior to the 'incoming-viewing-key' request.

Mitigation