Blockchain, cloud and IoT security
Security for blockchain, cloud and IoT covers how distributed ledgers, cloud services and constrained devices are attacked and defended, and the protocols, hardware roots of trust and engineering practices used to reduce risk.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two or three sentences: where an engineer uses this.
Blockchain, cloud and IoT technologies are widely used in finance, supply chains, industrial control and consumer products. An engineer uses these security ideas when designing systems that must protect keys and data across untrusted networks, when choosing consensus and deployment models for ledgers, and when building or integrating IoT devices with cloud back-ends so they remain safe throughout their lifecycle.
Key ideas
Explain plainly and define before use. Bold each term when defined.
Blockchain: A blockchain is a distributed, append-only ledger in which data is grouped into ordered blocks, each block contains a cryptographic link (hash) to the previous block, and copies of the ledger are held by multiple participants. Assumptions: at least some participants follow the protocol; network may be Byzantine (nodes may be faulty or malicious).
- Exact property often required in exam answers: the blockchain provides tamper-evidence: changing any historical block changes its hash and breaks the chain unless an attacker recomputes subsequent blocks and convinces peers to accept them.
- Diagram to draw: a horizontal chain of boxes labelled Block 0 (genesis), Block 1, Block 2,... For each block draw inside header fields: PrevHash, MerkleRoot, Timestamp, Nonce; below each block list its transactions. Draw arrows from each block's PrevHash to previous block.
Distributed ledger: a database replicated across nodes where agreement about ordering of updates is achieved by a consensus algorithm.
Consensus algorithm: a protocol that lets nodes agree on the single history of transactions. Two common types:
- Proof of Work (PoW): nodes solve costly puzzles (hashing) to propose blocks. Security assumption: honest nodes control majority of total computational power. Exact statement used in exams: if an attacker controls >50% of mining power then they can, with overwhelming probability over time, create and maintain the longest chain and perform double-spend attacks (the 51% attack). If attacker has fraction q < 0.5, probability of successful long reorganization falls exponentially with number of confirmations (Nakamoto argument).
- Proof of Stake (PoS): block-proposers are chosen in proportion to stake (ownership) in the system. Security assumption: honest stakeholders control a majority of stake; Sybil resistance comes from economic cost, not CPU cost.
- BFT consensus (PBFT/Tendermint): used in many permissioned or delegated systems; tolerates up to f Byzantine faults if N ≥ 3f+1; provides immediate (deterministic) finality when assumptions hold; safety holds with at most f faulty nodes, liveness under partial synchrony.
Merkle tree and Merkle root: a binary tree of transaction hashes. Exact definition: leaf nodes are hashes of transactions; internal nodes are hash(concat(left_child, right_child)); the root is the Merkle root. Diagram: draw a binary tree with leaf hashes H(T1), H(T2), compute parents H(H(T1)||H(T2)) etc, ending at MerkleRoot, and label concatenation order.
Smart contract: code stored on blockchain that runs when transactions call it. Security issues: reentrancy, integer overflow, improper access control. Exams commonly ask to trace a reentrancy exploit.
Shared responsibility model (cloud): security responsibilities are split between cloud provider and tenant. Exact, short statement students should be able to write: cloud provider secures physical infrastructure, hypervisor, and host networking; tenant is responsible for guest OS, applications, data, and identity and access management (depends on IaaS/PaaS/SaaS level).
IaaS, PaaS, SaaS: define each briefly: IaaS provides virtual machines and storage; PaaS provides platforms (runtime) for apps; SaaS provides complete applications. Security boundary moves from provider to customer as you go from SaaS to IaaS.
Virtualization and multi-tenancy risks: multi-tenancy means multiple tenants share the same physical hardware. Primary risks: VM escape, side-channels, noisy-neighbour denial of service, and improper isolation of metadata or storage snapshots.
Hardware root of trust: a hardware module (e.g., TPM or HSM) that securely stores keys and performs cryptographic operations. Exact properties: secure key storage and protected crypto; TPMs provide measured/secure boot and remote attestation of device state, while HSMs focus on key custody and cryptographic operations. Use for secure/verified boot, key protection and signing firmware/attestation tokens.
IoT device security: IoT devices are often resource-constrained. Key terms: device identity (unique cryptographic identity), OTA updates (over-the-air firmware updates), device lifecycle (manufacture, provisioning, operation, decommission). Design assumptions: devices may be physically accessible to attackers, so secrets can be extracted unless hardware protections used.
Common attacks and exact descriptions:
- 51% attack: attacker controlling >50% of consensus resource (hash power or stake) can extend a private chain faster than the public chain and double-spend.
- Sybil attack: attacker creates many identities to gain disproportionate influence in voting-based consensus.
- Double spending: spending same coin twice by creating a conflicting transaction later accepted by the ledger.
- Reentrancy: smart contract vulnerability where an external call allows control to re-enter and manipulate contract state before it's updated.
- Replay attack: re-sending a valid signed message on the same or another network to produce unintended effects.
- Firmware supply-chain compromise: attacker inserts malicious code during manufacturing or update distribution.
Defenses (exact statements):
- Use mutual authentication (device and server both authenticate using certificates or pre-shared keys). Refer to Public key infrastructure (PKIX) from other topics for certificate management.
- Use TLS/DTLS to protect transport; use application-layer signatures for non-repudiation where needed, and include nonces/timestamps or sequence numbers (anti-replay) and chain IDs where applicable.
- Use hardware-backed keys (TPM/HSM) for key storage and signing to resist extraction.
- Use rate-limiting, transaction confirmations, and economic penalties in consensus design to mitigate double-spend and selfish mining.
- Use formal verification and secure coding to reduce smart contract bugs; use multisig or time-locks to reduce single-key risk.
Formulas
Each formula on its own line, symbol meaning, SI unit and when it applies.
E[T] = 1 / (H · p) — E[T]: expected time to find a block (s); H: hash attempts per second (hashes·s⁻¹); p: probability that a single hash is a valid solution (dimensionless). Applies to PoW block finding when each hash is an independent trial with success probability p.
p = Target / 2^n — p: probability per hash (dimensionless); Target: numeric target threshold (dimensionless); n: number of output bits of hash function (bits). Applies where hash outputs are uniformly distributed over 0..2^n−1.
Risk = Threat · Vulnerability · Impact — conceptual, not SI: Threat: frequency or likelihood dimensionless; Vulnerability: probability dimensionless; Impact: expected loss in currency units (e.g., INR). Use for qualitative risk estimation.
MAC = HMAC_k(M) — MAC: message authentication code (bitstring); HMAC_k: HMAC with key k; M: message (bytes). Units: bits/bytes. Applies to computing integrity and authenticity tags for messages.
C = Enc_k(P) — C: ciphertext; Enc_k: encryption under key k; P: plaintext. Units: bytes. Applies to symmetric encryption.
Worked examples
Two examples of university-exam standard.
- PoW expected block time (numerical, simplified small-bit example)
Given: a toy PoW uses a 32-bit hash output (n = 32) and the target value is 2^24. A miner has H = 1×10^6 hash/sec. Compute expected time to find a valid block.
Step 1: Compute p = Target / 2^n = 2^24 / 2^32 = 1 / 2^8 = 1/256.
Formula: E[T] = 1 / (H · p).
Calculate: H·p = 1×10^6 · (1/256) = 1,000,000 / 256 = 3906.25 s⁻¹.
E[T] = 1 / 3906.25 = 0.000256 s.
Answer: Expected time = 0.000256 s (toy example; real blockchains use much larger n — this small n is for classroom calculation).
- Smart contract reentrancy (algorithm trace)
Vulnerable contract pseudocode:
function withdraw(uint amount) { if (balances[msg.sender] >= amount) { // external call before state update (vulnerability) msg.sender.call{value: amount}(); balances[msg.sender] -= amount; } }
Trace with attacker contract that on receiving funds re-calls withdraw:
Step 1: Attacker's balance = 10. Attacker calls withdraw(10). Step 2: Contract sees balance >= 10, makes external call to attacker to transfer 10, but does not yet reduce balance. Step 3: Attacker's fallback executes and calls withdraw(10) again before balances[msg.sender] is decremented. Step 4: Second invocation passes the balance check again (still 10), triggers another external call, and so on until gas limit or drained funds.
Mitigation: update state before external calls (balances[msg.sender] -= amount; then external call), use reentrancy guard (mutex), or use pull payments.
Common mistakes
- Treating TLS alone as sufficient for device identity — TLS secures transport, but device provisioning, key protection (hardware) and revocation must be handled.
- Believing PoS has no centralization risks — stake can concentrate and create oligopoly; Sybil resistance is different from PoW.
- In smart contract questions, forgetting to update state before external calls or not describing gas/limits when relevant.
For your exam
Kinds of questions and what full-marks answers include.
- Definitions: short, precise definitions of blockchain, Merkle tree, PoW/PoS, TPM, IaaS/PaaS/SaaS.
- Short notes: architecture diagram (draw and label), shared responsibility model, hardware root of trust, IoT lifecycle risks. Include a small diagram and label trust boundaries.
- Derivations: expected block time from hash rate and target; explain security assumption behind 51% attack and why q>0.5 breaks safety.
- Numericals: compute expected time to find block (use E[T] formula and show units), compute p from target and hash-bit size.
- Programs/traces: trace a smart-contract reentrancy exploit step-by-step and show fix (update state then external call or reentrancy guard).
- Diagrams: chain of blocks (headers with PrevHash, MerkleRoot, Nonce, Timestamp), cloud tenant architecture, IoT device—gateway—cloud with protocol labels (MQTT/TLS or CoAP/DTLS).
Full-marks answers: explicit definitions, clear assumptions, labelled diagram if required, formulas with units, stepwise working for numericals, and mitigations for attacks with precise mechanisms (e.g., mutual TLS + hardware-backed keys + OTA signing).
Quick check
Three short questions.
- What is a Merkle root?
- State one concrete mitigation for smart-contract reentrancy.
- In shared responsibility model, who is responsible for guest OS security in IaaS?
Answers: A Merkle root is the top hash of a binary Merkle tree computed by hashing and concatenating child node hashes (it commits to all transactions); update state before external calls or use reentrancy guard (mutex) to mitigate reentrancy; the tenant (customer) is responsible for guest OS security in IaaS.
Notes for reviewer: I have avoided deep crypto proofs and complex Nakamoto probability sums but stated the key exam results and assumptions. I used a toy numeric example for PoW with small n to keep arithmetic simple—real systems use much larger hash sizes.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?