Tribler / tribler

Privacy enhanced BitTorrent client with P2P content discovery
https://www.tribler.org
GNU General Public License v3.0
4.86k stars 451 forks source link

Blockchain Engineering 2023 - Offline Token Money II #7308

Closed synctext closed 3 months ago

synctext commented 1 year ago

Team issue for 10 weeks of blockchain engineering course at Delft University of Technology

Offline token money. Your task is to create easy payments using tokens, without Internet. Giving and receiving tokens should be easy and effortless. Special requirement is that it should also work in an emergency: when the Internet is down. Probably you need to use QR-codes scanning to move Tiktok Tokens between devices. The hard scientific task is to address the double spending risk. Required background reading from Delft: Double spending prevention of digital Euros using a web-of-trust.

Ne184 commented 1 year ago

The team went through the double spending paper and noticed that it should be the receiver the one who needs to get the warning message and the trust-score of the sender, since he is the one who is expecting to receive money.

Everyone also looked at the Trustchain paper to get acquaint how Trustchain is working and be able to reason about the double spending issue in an offline scenario.

QR scanner was developed, but need to be integrated with DetToks. QR code was also successfully produced

synctext commented 1 year ago

Great find! Receiver is taking the risk :police_officer: did not notice this problem earlier. The flow does not match typical trading situations! Figure 3. Screen capture of a transaction showing a trust score of the offline Euro paper shows the Send Money screen with scores. Please propose a better flow. Could just be clarification at the receiver side. For instance, a clear 3 x warning beep when scanning low-trust QR codes. A very loooong beep for QR code owner who got caught double spending and refusal to process the QR code. Idea of a collateral is also great to explore. Related (crypto) work from China: https://link.springer.com/chapter/10.1007/978-3-031-17551-0_30 Key concept: Post-incident accountability.

Limiting the scope, can't be solved in the general case. scenario: pay for water at the local supermarket you visit every week in an emergency. {nobody has any money. avoid the disaster after the disaster} quote: people leaving their phone numbers and promising to come back and settle their debts once the situation stabilises.

{repeating from first meeting} First sprint goal: Create unique coin EURO 000001, signed by yourself, Show QR code, scan QR code (all this is already operational inside Superapp), copy inside trustchain data structure.

At week 5: good to have running code of some mechanism.

julio1998 commented 1 year ago

We discussed that our main focus should be on improving the trustscore by including more factors than just the number of transactions. Furthermore, we came up with a mechanism that could possibly detect double spending. What will be included in the final product is still open to discussion but it’s good to think these scenario’s out.

Improving score: the score should be dependent on the trustscore (number of transactions), the number of detected double spendings and the time you have been online for the last time. The last dependency is included to detect double spending (as described in next section).

Detecting double sending: detect double spending by reducing the comparisons of chains to a subset of parties a user has pre-defined before going offline. The idea is that if a user wants to pay offline he/she must first add the parties it wants to spend its money to to a list. The parties that receive the token only need to compare its chain with the chains that were part of the list. When you come online you compare your chain only to the users that were pre-defined in the list.

"It is not trivial for two random strangers to detect that they were defrauded by the same person. The proposed solution tries to reduce the number of people to compare a users chain to so that two random strangers can indeed detect fraud in a feasible amount of time."

For example, user A wants to spend money at company B, C and D. User A spends his offline token at company B. Company B now only needs to compare its chain with companies C and D to be sure there was no double spending. This reduces the comparison of chains to a reasonable subset instead of a large amount of total users in the network.

Verify tokens: a token is verified if the transaction of the token has been compared to the chains of the parties in the list of the sender. This reduces the risk of double spending. A token can only be spend after it has been verified (i.e. a token that has been received offline can not be respend before the user has been online).

Other ideas:

  1. Block an account after double spending has been detected. The user may use his account after a fine has been paid.
  2. Block an account for a finite amount of time.
  3. Synchronize transactions with connected people so your chain can be accessed even if you are offline again.

Progress so far:

  1. Choose amount and generate request
  2. Encode requested amount and public key and QR
  3. Scan QR code and add transaction to block

Link to branch

synctext commented 1 year ago
julio1998 commented 1 year ago

Based on the meeting of last week we revised our flow and reduced the task to a viable MVP.

Score: the score should be dependent on the size of the EuroToken. The more transactions in the token, the larger the token. This is because by a change of owners a block is added to the token.

Verification: two ideas 1) Verify each user in the chain of owners, checking that they had the token and checking with every user in their "address book". 2) Add transaction to TrustChain. The transaction will be between the initiator and final owner of the EuroToken. If the transaction is added, it is considered valid. Double spending should be detected by comparison of chains in the TrustChain network. We will focus on the last one.

Our MVP can be divided in the following tasks:

Each task has its corresponding UI.

What we've done since the last meeting:

synctext commented 1 year ago
julio1998 commented 1 year ago

We finalised our final product to the following:

Our application will now also include a special admin page that mimics the central authority. The admin page will be able to verify the token and re stamp it with a new timestamp.

synctext commented 1 year ago
julio1998 commented 1 year ago

We have been working on creating a working APK. Unfortunately we have run into some issues that slowed down our progress. Up until this point we have a working QR code scanner and are able to add and retrieve the wallet of the user. We are not able to display this in the app. We also experienced issues with generating a proper APK.

TODO's:

Current branch: branch

Screenshots:

Admin screen

Token List
synctext commented 1 year ago
VyshnaviMN commented 1 year ago

Updated README.md

We also prevent the same coin from being scanned by two people, hence preventing double spending of the same coin

GIF - https://drive.google.com/file/d/1Om2BhDseR2K3bHnyacP2KV7krysMa7cg/view?usp=sharing

APK - https://drive.google.com/file/d/1MH3qiH1NXBtPdBbfjCnsNqvs3r8FT5Wg/view?usp=sharing

Ne184 commented 1 year ago

Decentralised TikTok skeleton app for the CS4160 Blockchain Engineering (2022/23) course.

Detoks - Offline Token 2 An easy payment application that makes sending and receiving tokens easy. A user can choose the amount to be received and create a request which can be paid by a preadded contact. The payment can then be done by scanning the generated QR code and a transaction is then made. A Eurotoken is minted and verified by a central authority.

GIF - https://drive.google.com/file/d/1Om2BhDseR2K3bHnyacP2KV7krysMa7cg/view?usp=sharing

APK - https://drive.google.com/file/d/1MH3qiH1NXBtPdBbfjCnsNqvs3r8FT5Wg/view?usp=sharing

Use case The application can be used for the following use cases:

Create and store EuroToken (add screenshot) Encode and create QR for EuroToken (screenshot) Send and receive EuroToken between contacts Add new contact Double spending To mitigate double spending, contacts are to be added before users can send or receive EuroTokens. This makes it easier for admins to track double-spend EuroToken and give users warnings when trying to add malicious users. Another important concept is used to make sure that the detection of double spending is relatively on time. After receiving a new token, the token is valid for a limited amount of time (a month). After that month a token must be verified before being able to re-spend it. The token will be restamped with a new timestamp which makes it a valid euro token.

Future work To detect the double spending, two ideas were discussed which can be implemented in the future:

Using the verifivation mechanism, double spending can be easily detected when two users try to verify the same token. The authority will be able to direcly detect the double spender. To prevent double spending in offline transactions, a given precentage of the user tokens is preserved and cannot be used to make payments until the user comes online.

synctext commented 1 year ago
VyshnaviMN commented 1 year ago

Public key

Ne184 commented 1 year ago

Token to Vyshnavi, only Vyshnavi can receive it

Ne184 commented 1 year ago
VyshnaviMN commented 1 year ago

Sending token to Prof

VyshnaviMN commented 1 year ago
  1. Updated README.MD https://github.com/Ne184/trustchain-superapp/blob/master/README.md#detoks---offline-token-2

  2. Latest APK: https://drive.google.com/file/d/1r2p7AvBQ-pumPTApD-cKcR0m7v0g8q1D/view?usp=share_link

  3. Added Standard Euro Denominations (.5 Euro, .05 Euro, 1 Euro, 2 Euro, 5 Euro)

    • Supports fraction sums
    • Can send more than 1 coin at a time
  4. Made Draft Pull Request: https://github.com/Tribler/trustchain-superapp/pull/158

  5. For Demo:

Add public keys for a smooth transaction process:

  1. Code Link - https://github.com/Ne184/trustchain-superapp/

  2. Sending Token to Professor:

synctext commented 1 year ago