Docsity

BLOCKCHAIN E SMART CONTRACTS, Appunti di Reti informatiche

Toggle sidebar
bg1
Important rules of our basic blockchain
!Everyone can add an entry to the ledger (Un ledger è un registro in cui vengono registrate le
transazioni)"
!For this example we decide that at the end of the month, settle-up time"
The problem with our current implementation ANYONE CAN ADD AN ENTRY TO THE LEDGER"
Solution -> add signatures -> Only signed transactions are valid"
Greedy Users
What if a users accumulates a huge debt and then refuses to settle-up?"
Nothing is preventing a user from running away"
Solution -> No possibility for overspending"
The Trusted Central Entity Problem
Il problema della Trusted Central Entity (Entità Centrale Fidata) riguarda la necessità di affidarsi a
un’unica autorità per verificare e registrare le transazioni."
!Where is the central ledger stored?"
!Can we really trust the (third) entity that manages the ledger?"
!Do we really want to pay for the ledger administration (fee/commissions)?"
To make sure the system works, every user should receive a notification about the transaction."
Can we Trust Ledgers?
!What if for some reason the notification failed?"
!What if different ledgers receive the transaction in different orders?"
Entrambi i problemi si risolvono con protocolli robusti di consenso e sincronizzazione tra i nodi
della rete. "
Solution:"
!Control that each transaction is correctly registered (e.g., order) on each ledger"
!Avoid contradictory information on different ledgers"
!Trust in the single administrations"
Problems with Multiple Ledgers
%Automatically manage the interaction between different systems, without manual operations."
Quando più registri interagiscono (es. blockchain diverse o database tradizionali), possono
sorgere problemi di coerenza e compatibilità."
Soluzione: Creazione di protocolli standard (come interoperabilità tra blockchain via bridge
o API)."
%Automatic procedures: requires synchronizing different applications, perhaps developed with
different technologies"
Questi sistemi devono essere sincronizzati in modo affidabile e coerente."
Soluzione: Uso di smart contracts cross-chain o middleware per collegare diversi sistemi."
%Trust problems"
Un ledger potrebbe avere dati modificati o essere gestito da un’entità non affidabile."
Soluzione: Tecnologie decentralizzate come blockchain per garantire che i dati siano
verificabili da tutti senza bisogno di un’autorità centrale."
%Auditing is complex"
Conciliare transazioni tra sistemi diversi richiede tempo e risorse."
Soluzione: Creare registri pubblicamente verificabili, dove ogni transazione può essere
tracciata facilmente senza alterazioni."
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Anteprima parziale del testo

Scarica BLOCKCHAIN E SMART CONTRACTS e più Appunti in PDF di Reti informatiche solo su Docsity!

Important rules of our basic blockchain

! Everyone can add an entry to the ledger (Un ledger è un registro in cui vengono registrate le

transazioni)

! For this example we decide that at the end of the month, settle-up time

The problem with our current implementation ANYONE CAN ADD AN ENTRY TO THE LEDGER Solution -> add signatures -> Only signed transactions are valid Greedy Users What if a users accumulates a huge debt and then refuses to settle-up? Nothing is preventing a user from running away Solution -> No possibility for overspending The Trusted Central Entity Problem Il problema della Trusted Central Entity (Entità Centrale Fidata) riguarda la necessità di affidarsi a un’unica autorità per verificare e registrare le transazioni. ! Where is the central ledger stored? ! Can we really trust the (third) entity that manages the ledger? ! Do we really want to pay for the ledger administration (fee/commissions)? To make sure the system works, every user should receive a notification about the transaction. Can we Trust Ledgers? ! What if for some reason the notification failed? ! What if different ledgers receive the transaction in different orders? Entrambi i problemi si risolvono con protocolli robusti di consenso e sincronizzazione tra i nodi della rete. Solution: ! Control that each transaction is correctly registered (e.g., order) on each ledger ! Avoid contradictory information on different ledgers ! Trust in the single administrations Problems with Multiple Ledgers % Automatically manage the interaction between different systems, without manual operations. Quando più registri interagiscono (es. blockchain diverse o database tradizionali), possono sorgere problemi di coerenza e compatibilità. Soluzione: Creazione di protocolli standard (come interoperabilità tra blockchain via bridge o API). % Automatic procedures: requires synchronizing different applications, perhaps developed with different technologies Questi sistemi devono essere sincronizzati in modo affidabile e coerente. Soluzione: Uso di smart contracts cross-chain o middleware per collegare diversi sistemi. % Trust problems Un ledger potrebbe avere dati modificati o essere gestito da un’entità non affidabile. Soluzione: Tecnologie decentralizzate come blockchain per garantire che i dati siano verificabili da tutti senza bisogno di un’autorità centrale. % Auditing is complex Conciliare transazioni tra sistemi diversi richiede tempo e risorse. Soluzione: Creare registri pubblicamente verificabili, dove ogni transazione può essere tracciata facilmente senza alterazioni.

Agreeing on the List ! All transactions are appended to a list ! There are transaction users want to approve ! Any user can send transactions in random orders Consensus Design of a consensus mechanism ! Define what operations can be added (e.g., the consensus can forbidden to add a transaction that spend more money than the available money). ! Define the order Solution -> stabilire quali operazioni sono valide e in che ordine devono essere registrate. ! Il consenso è usato per determinare l’ordine dei blocchi nella blockchain. ! Non riguarda il contenuto delle transazioni, ma solo se un blocco può essere aggiunto alla catena. ! Garantisce che tutti i nodi della rete siano allineati sull’ordine dei blocchi, evitando conflitti o discrepanze.

Distributed Ledger Technology A DLT is a decentralized replicated record of data managed and maintained by multiple untrusted entities without the need of a regulator authority " Un DLT è una tecnologia di registro distribuito che consente a più entità non fidate di gestire e mantenere una copia dei dati in modo decentralizzato. " I DLT sono caratterizzati da trasparenza, sicurezza e resilienza grazie alla replicazione dei dati tra i nodi, e non richiedono un’autorità centrale. " Gli esempi più noti di DLT includono la blockchain e il DAG. Decentralized " Ogni nodo di un DLT mantiene una propria copia del registro. " Non c’è una autorità centrale a cui fare riferimento; la validità delle transazioni e dei blocchi è determinata dal consenso tra i nodi. " Ogni nodo lavora per mantenere e aggiornare il proprio registro seguendo le regole predefinite dal sistema. " La sincronizzazione e la sicurezza sono garantite dal meccanismo di consenso, che assicura che tutti i nodi abbiano la stessa versione del registro. Replicated Record of Data " DLTs are decentralized systems that replicate data across multiple nodes. " Data is organized as a list of records, where each record represents a transaction. " The last record defines the current state of the system. " DLTs are versatile and can store various types of data, such as financial transactions, smart contracts, sensor data, and intellectual property rights.

Managed and Maintained ! Each node has its own copy of the ledger ! Each node works to update its own copy ! Each node works for the benefit of the distributed ledger ! Copies may differ, so the majority hold the truth (if there are malicious user, or a blockchain fork) Untrusted Members ! Nodes do not trust other nodes in the network (every user can send a information that can be malevolus) ! Each node directly communicates with other peer nodes in the network (in general a subset of the network) N.B. a user can propose a modification previous blocks, but other users will refuse the modification, since they will all see a modification to previous blocks. Classification of DLTs ○ Permissionless^ Blockchain (Inherently Public) Every node in the network participate in consensus procedure ○ Permissioned^ Blockchain (Public or Private) Only selected nodes (validators, e.g., Government or trusted nodes) participate in consensus procedure $ Le blockchain permissive sono completamente aperte a chiunque, favorendo la decentralizzazione e la trasparenza ma con sfide come l’efficienza e il consumo energetico. $ Le blockchain permesse sono limitate a nodi selezionati, che possono garantire una maggiore scalabilità, velocità e privacy, ma sacrificano in parte la decentralizzazione. NUMBERS OF TRANSACTION ELABORATED PER SECOND TIME NEEDED TO VALIDATE A TRANSACTION

Blockchain ! Blocks are organized on a chain ! Each block is cryptographically linked to the previous one Only special nodes in the network can create blocks and add them to the blockchain. These nodes are called Miners: ! Everyone can be a miner. ! The miner proposes a block (remember a block is a list of transactions), which should then be confirmed ! Depending on the consensus protocol, miners execute different tasks

! A nonce is a 32-bit number used to generate a unique hash for each block ! The Merkle root contains a single hash that can validate every single transaction hash in the block. A nonce is a random or incremental number that miners change when trying to find a valid block hash in blockchain mining (ad es. ho bisogno di 10 0 al termine dell'hash, o comunque un n. di 0 che cambia sulla base della potenza della rete) N.B. le notifiche di aggiornamento del ledger per i vari nodes, generano una notifica anche ad alcuni miners, che lavorano per trovare il nonce corretto per generare l'hash del block (il block viene diffuso nella rete a tutti e il miner riceve il premio)

Monolithic Applications ! When executing a task (e.g, using social networks) the device need to execute multiple different tasks ! Backend server, messaging service, database… (many services taking care of deciding where to save, effectively storing, adding metadata, etc). ! We say that a system is monolithic when all the devices executing the different tasks are tightly coupled (i.e., on the same machine) Le applicazioni monolitiche sono un’architettura software in cui tutti i componenti e le funzionalità dell’applicazione sono combinati in un’unica unità. Questo significa che l’interfaccia utente, la logica di business e l’accesso ai dati sono tutti contenuti in un’unica base di codice e vengono distribuiti come un’unica applicazione. Problems with Monolithic A possible problem: $ If more and more users start using the system, it gets congested. The machine is not able to simultaneously reply to all users’ requests. $ The system start to consume the request and reply, but the response might take a long time. Solutions: $ One option may be to increase the machine’s power.

Cryptography Primer We have three fundamental topics we need to cover when dealing with blockchain a. Hash functions b. Cryptographic Keys c. Digital signatures Cryptography, or cryptology is the practice and study of techniques for secure communication in the presence of adversarial behavior. Generally, Cryptography is about constructing and analyzing protocols (rules) that prevent third parties or the public from reading private messages. Hash Function We use hash functions to create digital fingerprints s by providing data in input to a cryptographic hash function. U cant never generate the input from the output. Hash means something that is chopped into small pieces or mixed up. The output size is fixed, and depends on the hashing algorithm used. Different inputs provide different hashed outputs. A small change to the input creates a completely different output The length of the output is still the same, 32-byte Allow for integrity check -> garantisce che i dati siano intatti e autentici, proteggendoli da modifiche non autorizzate Properties

  • Small changes = different output (The avalanche effect) -> una piccola modifica nell’input provoca un cambiamento drastico nell’output.
  • The same input will always produce the same hash
  • Slightly different inputs will produce very different hashes
  • The hash is always of the same fixed size

Simplified Model

Requirements

  1. Strong encryption algorithm : no opponent knowing the encryption algorithm and having access to ciphertext should be able to obtain the plaintext of figure out the key
  2. Secure key sharing and storage : if someone knows the key, then communication is readable Symmetric Block Encryption
  • Block Ciphers: process the input in fixed-size blocks and produces ciphertext in fixed- size blocks
  • Most important algorithms are Data Encryption Standard (DES), Triple DES. and Advanced Encryption Standard (AES) -> They use different algorithms and different key lengths Tipo di crittografia in cui i dati di input vengono trattati in blocchi di dimensioni fisse. Ogni blocco di dati viene cifrato separatamente utilizzando una chiave segreta. If two different chunks of data contain the exact same data, the ciphertext could be exactly the same statement or string of characters are repeated throughout a document. Stream Ciphers
  • Process data as it goes along
  • No division into blocks
  • Advantage over block ciphers: are usually faster and require less coding
  • Disadvantage over block ciphers: you cannot reuse key Tipo di crittografia in cui i dati vengono trattati continuamente (bit per bit o byte per byte), invece che essere suddivisi in blocchi fissi come nel caso della crittografia a blocchi. A First Form of Authentication If only the transmitter and receiver have the key, they can use it for different purposes:
  • Hide information from unintended receivers
  • Understand whether the transmitter is a legitimate party However, this might not be sufficient An attacker may reorder blocks -> Need to design a method for authentication that does not rely on encryption Authentication Verifying that users are who they say they are and that each input arriving at the system came from a trusted source Authentication Without Encryption -> L’autenticazione senza cifratura è una soluzione utile in contesti dove la confidenzialità non è la priorità principale ma è necessaria una verifica dell’integrità e dell’autenticità dei messaggi, es. emergenze, allerte tsunami If the received code matches the calculated code:

- the message has not been altered

- the message is from the alleged sender

- the receiver can be assured of the proper sequence

To compute MAC it is typical to use DES

Public Key Encryption Public Key Encryption is Asymmetric: use of two separate keys for encryption and decryption.

  1. Plaintext: readable message input to the algorithm → Il messaggio in chiaro, leggibile, che viene dato in input all’algoritmo di cifratura.
  2. Encryption Algorithm: algorithm that performs transformations over the plaintext → Un algoritmo che trasforma il plaintext in un messaggio cifrato (incomprensibile).
  3. Public and Private Key Couple: couple of encryption and decryption keys
    • La chiave pubblica può essere condivisa liberamente e viene usata per cifrare i dati.
    • La chiave privata è segreta e viene usata per decifrare i dati.
  4. Ciphertext: scrambled message produced as output → Il messaggio cifrato generato come output dall’algoritmo di cifratura.
  5. Decryption Algorithm: retrieve the original plaintext given the correct key → Un algoritmo che, data la chiave privata, permette di recuperare il messaggio originale dal testo cifrato. Private Key
    • Very long randomly generated number
    • Often coded in hexadecimal
    • Deve essere mantenuta segreta perché chiunque la possieda può decifrare i messaggi o firmare digitalmente a nome del proprietario. Public Key The public key is obtained from the private key through a mathematical function Keys relationship
  • Use the private key to create the public one
  • The key derivation function is one-way
  • Like hash function, you cannot go back
  • Cannot recover private from public

Steps 1⃣ Generazione delle Chiavi

  • Ogni utente crea una coppia di chiavi:
  • (^) Chiave privata → Segreta, usata per decifrare i messaggi o firmare digitalmente.
  • (^) Chiave pubblica → Condivisibile con chiunque, usata per cifrare i messaggi o verificare firme. 2⃣ Distribuzione della Chiave Pubblica
  • L’utente inserisce la sua chiave pubblica in un registro pubblico o in un file accessibile agli altri.
  • Così, chiunque può usarla per inviare messaggi cifrati a quell’utente. 3⃣ Cifratura del Messaggio
  • (^) Se Bob vuole inviare un messaggio privato a Alice, usa la chiave pubblica di Alice per cifrarlo.
  • (^) Questo garantisce che solo Alice possa leggerlo. 4⃣ Decifratura del Messaggio
  • Quando Alice riceve il messaggio cifrato, lo decifra con la sua chiave privata.
  • Poiché solo lei possiede la chiave privata corrispondente, solo lei può leggere il messaggio. Encryption -> PUBLIC KEY Decryption -> PRIVATE KEY

Authentication/Data Integrity Vogliamo vedere se il sender è un trusted user e possiamo accettare l'invio Esempio alice vuole solo il messaggio da bob, nel mazzo di chiavi alice ha tutte le public key degli utenti, Bob per mandare il messaggio invia il messaggio come un input al algoritmo di ecncription e tramite la sua private key lo encripta Quindi se io encripto con public key decripto con private key (e viceversa), quindi se bob encripta co la private key e la trasmette con il ciphertext alice dovrà decriptare con la public key che possiede nel mazzo di chiavi e dovrà scegliere quella di bob per decriptarla, se no avrà un output che non corrisponde Spiegato meglio Bob firma il messaggio: Bob calcola un hash del messaggio e cifra l’hash con la sua chiave privata, creando una firma digitale. Alice verifica la firma: Alice riceve il messaggio e la firma, quindi usa la chiave pubblica di Bob per verificare la firma. Se la firma è valida, Alice sa che il messaggio è autentico e proviene effettivamente da Bob. Questo processo garantisce che il messaggio non è stato alterato (integrità) e che proviene effettivamente da Bob (autenticità). Requirements for Public Key

  1. It is easy to generate a couple of keys
  2. It is easy to generate the ciphertext knowing the message and the key
  3. It is easy to recover the original message knowing the key
  4. It is impossible for an opponent knowing the public key to compute the private key
  5. It is impossible for an opponent knowing the ciphertext and the public key to recover the original message Il plaintext (in italiano “testo in chiaro”) è il messaggio originale

Asymmetric Encryption Algorithms

  • (^) RSA : Cifratura a blocchi con una chiave di 1024 bit
  • (^) Diffie-Hellman Key Agreement : fornisce solo un scambio sicuro di chiavi e non crittografia o autenticazione
  • (^) Digital Signature Standard (DSS) :è uno standard per la creazione e la verifica di firme digitali.
  • (^) Elliptic Curve Cryptography (ECC) : riducendo così il carico computazionale rispetto a RSA Problems with Public Keys
    • Public keys must be publicly available.
    • When a user joins or updates their key pair, it is broadcasted to all.
    • Risk: Anyone can create a fake key pair and impersonate another user. Public Key Certificates
    • Solution: Public Key Certificate (PKC).
    • Contains: Public key + User ID, signed by a Certificate Authority (CA).
    • Includes CA details and certificate validity period. Steps to Publish a Key
    1. User creates a key pair.
    2. User prepares an unsigned certificate (public key + ID).
    3. User submits it securely to the CA (email verification, OTP, in person, etc.).
    4. CA:
      • Computes hash of the unsigned certificate.
      • Signs it by encrypting the hash with its private key.
    5. CA returns the signed certificate to the user.
    6. User shares the certificate with others.
    7. Verification process:
      • Compute hash of the certificate.
      • Decrypt CA’s signature using CA’s public key.
      • Compare both values → If they match, the certificate is valid. X.509 is the universal standard for certificates. Problemi con le Chiavi Pubbliche Le chiavi pubbliche devono essere accessibili a tutti. Quando un utente si unisce alla rete o aggiorna la sua coppia di chiavi, questa informazione viene diffusa a tutti. Tuttavia, questo metodo ha un problema: chiunque può creare una nuova coppia di chiavi e fingere di essere un altro utente, ad esempio impersonando Bob e trasmettendo una chiave pubblica falsa a suo nome. Certificati di Chiave Pubblica Per risolvere questo problema, si usano i certificati di chiave pubblica, che associano una chiave pubblica a un ID utente e sono firmati da un’entità di fiducia, chiamata Autorità di Certificazione (CA). Il certificato include anche informazioni sulla CA e il periodo di validità.