lnbits / boltcards

Bolt Cards (NXP NTAG424) - LNbits extension
MIT License
14 stars 10 forks source link

[BUG] Counter acts up #30

Closed arbadacarbaYK closed 4 months ago

arbadacarbaYK commented 4 months ago

photo_2024-04-04_14-14-11

iWarpBTC commented 4 months ago

What's the issue?

arbadacarbaYK commented 4 months ago

What's the issue?

Its counting weird, isnt it ? :D Shouldnt after one come 2 not 27 ? After 27 i expected 28 and so on :) Tal didnt know also so pls explain how it works if that is supposed to be right :)

iWarpBTC commented 4 months ago

Each time a card is scanned by any device, the card increases its internal counter, which it keeps (until reset).

When a card is added to lnbits, default initial counter we save to our db is 1. So any scanned card's link containing a counter param higher then 1 is valid for us from start.

In this case the first card's link presented to lnbits contained counter param of 27. Somebody scanned this card 26 times before some app (wallet/pos) finally presented scanned link to the lnbits server. That is valid for us, 27 is higher then 1 so we save this new counter to our db. From now on, any older link with lower counter is invalid for us (it would mean replay attack). We are now ready to pay but payment request never came back for some reason so the amount remained 0 for this hit. No sats moved.

The second hit (card's link presented to lnbits) contained the counter param of 29. One link was scanned and thrown away (not presented to lnbits) for some reason between the first and the second hit. We don't mind as long as we're getting higher then the last time. The third hit we got the very subsequent scanned card's link. The fourth time one there was again one futile scan of the card.

Let me know if this is any clearer now or if there is anything I could explain better.

arbadacarbaYK commented 4 months ago

I am not sure if i understood that tbh Does it only increase / create an entry here when its presented to pay on the same instance ?? On successful payments ?

iWarpBTC commented 4 months ago

Does this help to understand? obrazek

arbadacarbaYK commented 4 months ago

It made the confusion smaller, yes :P Have a look @talvasconcelos

Whats the scenario where no entry is made for a counter increase ? When the reader doesnt do anything like no wallet on the phone or smth ?

iWarpBTC commented 4 months ago

The counter will increase as soon as the card is powered up by nfc field. Many things can happen for this particular counter number doesn’t make it to the lnbits. Just off the top of my head:

etc.

arbadacarbaYK commented 4 months ago

The counter will increase as soon as the card is powered up by nfc field. Many things can happen for this particular counter number doesn’t make it to the lnbits. Just off the top of my head:

* the reader may not read the link properly (the card is approached only very briefly)

* the reader doesn’t know the link so it doesn’t follow it (maybe it is just s generic nfc reader that only shows it on screen)

* the card is unintentionally read by a system reader before read again by a POS app

etc.

Thank you !!

iWarpBTC commented 4 months ago

You're welcome!