BLK 02Technology Β· πŸ”΅ technical Β· β‰ˆ6 h Β· 7 lessons + lab

Smart contracts & Ethereum

A smart contract is a program whose execution the whole network verifies β€” which makes it the first credible way to automate money-moving agreements like insurance payouts without an operator in the middle. Here you learn the machine, the language, and the eight ways it bites.

LO2 Β· write & deploy a Solidity contractLO2 Β· explain gas, accounts, oracles

L1The EVM: a world computer with a meter

Ethereum is one giant, replicated state machine. Every node executes every transaction through the Ethereum Virtual Machine (EVM) and must arrive at the identical result β€” that redundancy is what makes the outcome trustworthy, and what makes computation expensive.

Wallet (EOA)signs tx with private key Mempoolpending txs, fee market Validatororders txs into a block EVMevery node executes Statebalances +contract storage broadcastpick+orderexecutecommit Events emitted during execution are written to logs β€” the cheap, indexed way contracts talk to the outside (your backend subscribes to them, exactly like Galileo services consume Kafka). Finality on Ethereum PoS: ~2 epochs (β‰ˆ13 min) for full economic finality; L2s and enterprise chains differ (Modules 03 & 10).
Fig 2.1 Life of a transaction: sign β†’ broadcast β†’ order β†’ execute everywhere β†’ commit. Note where events fit β€” they're your integration surface.

L2Solidity anatomy β€” HelloPolicy, line by line

Solidity is the dominant contract language: statically typed, compiled to EVM bytecode. Here is a deliberately small but honest insurance contract β€” one product, one insured, fixed sums. You will deploy it in the lab below.

HelloPolicy.sol Β· Solidity ^0.8.24
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// Minimal fixed-benefit cover β€” learning scaffold, not production.
contract HelloPolicy {
    address public insurer;                       // deployer = the carrier
    uint256 public constant PREMIUM = 0.01 ether;
    uint256 public constant PAYOUT  = 0.05 ether;

    struct Policy { address holder; uint64 expiry; bool paid; bool claimed; }
    mapping(address => Policy) public policies;   // on-chain "policy admin table"

    event PolicyIssued(address indexed holder, uint64 expiry);
    event ClaimPaid(address indexed holder, uint256 amount);

    error NotInsurer();
    error NoActivePolicy();
    error AlreadyClaimed();

    modifier onlyInsurer() { if (msg.sender != insurer) revert NotInsurer(); _; }

    constructor() payable { insurer = msg.sender; }  // fund it on deploy: claims reserve

    /// Customer pays exactly the premium; cover runs 30 days.
    function buyPolicy() external payable {
        require(msg.value == PREMIUM, "premium is 0.01 ETH");
        uint64 expiry = uint64(block.timestamp + 30 days);
        policies[msg.sender] = Policy(msg.sender, expiry, true, false);
        emit PolicyIssued(msg.sender, expiry);
    }

    /// Insurer approves a claim β†’ contract itself pays out. Checks-Effects-Interactions.
    function approveClaim(address holder) external onlyInsurer {
        Policy storage p = policies[holder];
        if (!p.paid || block.timestamp > p.expiry) revert NoActivePolicy();
        if (p.claimed) revert AlreadyClaimed();
        p.claimed = true;                                // EFFECT first…
        (bool ok, ) = holder.call{value: PAYOUT}(""); // …INTERACTION last
        require(ok, "transfer failed");
        emit ClaimPaid(holder, PAYOUT);
    }
}

Read it as an insurance engineer:

L3Tokens in one lesson

ERC-20 Β· fungible

Interchangeable units

The standard interface (transfer, approve, balanceOf) behind stablecoins β€” which is exactly what Aon used to settle premiums in 2026 β€” and tokenized deposits (Module 09). If your product touches money movement, ERC-20 is the plumbing.

ERC-721 Β· non-fungible

Unique items

One token = one unique asset. Insurance readings: a policy as an NFT (transferable proof of cover β€” Etherisc does this), or a cat-bond note as a token (Module 10's ILS tokenization).

L4Oracles β€” the bridge that decides parametric claims

Contracts cannot call APIs; the chain only trusts what's already on it. An oracle brings external facts (wind speed, flight status, an official index) on-chain β€” and instantly becomes the most attackable part of any parametric design. Chainlink, the dominant network, answers with decentralised oracle committees: many independent nodes fetch, aggregate, sign.

TyphoonCoversmart contract (M06 lab) Oracle networkindependent nodes fetch,aggregate & sign the answernodenodenode Data sourcesweather API Β· flight statusPAGASA Β· indices requestfetchcallback β†’ payout logic Design questions every parametric product must answer: Who runs the nodes? What if sources disagree? What if the feed halts mid-typhoon? (M06 handles all three.)
Fig 2.2 The oracle request/callback pattern. In parametric insurance the oracle is the claims adjuster β€” govern it accordingly.

L5Security β€” the eight classic wounds

#VulnerabilityOne-line mechanicsInsurance flavour of the risk
1ReentrancyExternal call re-enters before state updates ("The DAO", 2016)Claim paid twice before "claimed" flag set β€” CEI ordering / guards
2Access controlMissing/wrong onlyRole checksAnyone can approve claims or change premiums
3Oracle manipulationFeed spoofed, stale, or thin-market price pushedFake weather = fake payouts; use multi-source, signed, time-bounded feeds
4Integer edge casesOverflow (pre-0.8), rounding, unit slips (wei vs ether)Premium/payout math off by 10¹⁸
5Front-running / MEVPublic mempool lets others reorder around your txRacing a trigger to buy cover just before a known payout
6Denial of serviceUnbounded loops; a reverting receiver blocks everyonePayout loop over all holders bricks the book β€” use pull payments
7Bad randomnessBlock variables are predictableAny lottery-like selection needs VRF, not block.timestamp
8Upgrade/admin riskProxy patterns move "immutable" into an admin keyWho can change the terms of in-force cover? Governance, timelocks, multisig
βœ– The meta-lesson

Contract code is public, immutable-ish, and adversarially probed with real money on the line. Treat deployment like releasing firmware for a pacemaker: reviews, tests, audits, and the smallest possible surface. In 2016 The DAO lost ~$60 M to wound #1 and forced Ethereum's fork β€” the industry's founding security story.

L6Lab β€” deploy HelloPolicy in 15 minutes

βš—

Lab 2.1 Β· Remix, zero install

browser only
  1. Open Remix

    Go to remix.ethereum.org. In File Explorer create HelloPolicy.sol and paste the contract from L2 (copy button above).

  2. Compile

    Solidity Compiler tab β†’ version 0.8.24+ β†’ Compile. Green check = bytecode ready.

  3. Deploy funded

    Deploy & Run tab β†’ environment Remix VM. Set VALUE = 1 ether (the claims reserve!) then Deploy. You are now the insurer.

  4. Buy cover as a customer

    Switch the ACCOUNT dropdown to a second address. Set VALUE = 0.01 ether (10000000 gwei Γ· 1000 β†’ easier: choose "ether" unit, type 0.01) and click buyPolicy. Read policies(yourAddress) β€” there's your record.

  5. Approve a claim as the insurer

    Switch back to account #1, call approveClaim(customerAddress). Watch the customer's balance jump by 0.05 ETH and find the ClaimPaid event in the transaction log.

  6. Now break it (the real lesson)

    Try: buying with 0.02 ether (revert message?), approving twice (which custom error?), approving from the customer account (which error?). Reverts-with-reasons are your friend.

Optional stretch: redeploy on the Sepolia testnet via MetaMask (M00 safety rules apply) β€” the exact flow is in Lab M06 where it matters. Prefer local tooling? The Foundry appendix lives in M06 too.

◐ Galileo lens

Map the vocabulary: Galileo's /command APIs β‰ˆ state-changing contract functions; its /query APIs β‰ˆ free view reads; ledger-then-Kafka β‰ˆ transaction-then-events; DB-updater workers β‰ˆ your event-subscribed backend. Same architecture instincts β€” different trust boundary. What the EVM adds is enforced shared execution: no single party (not even the insurer) can skip the rules once deployed. What it costs is privacy and gas.

β–ΆWatch / go deeper

Sources: Antonopoulos & Wood, Mastering Ethereum (EVM, wallets, security); Mastering Solidity (supplementary); Chainlink docs for the oracle pattern. DAO figures: contemporaneous reporting, 2016.