info@cyberlawacademy.com | +91-XXXXXXXXXX
Part 1 of 7

Smart Contract Fundamentals

Understand the architecture of self-executing agreements, the critical role of oracles, and the complex legal questions surrounding code-based contract enforceability.

[T] ~90 minutes [S] 5 Sections [D] 2 Diagrams

1.1 What is a Smart Contract?

A smart contract is a self-executing program stored on a blockchain that automatically enforces the terms of an agreement when predetermined conditions are met. Unlike traditional contracts, smart contracts eliminate the need for intermediaries and execute deterministically based on code.

Smart Contract (Technical Definition)
A computer program deployed on a distributed ledger that reads and writes data to that ledger, executing predefined logic in response to transactions or messages, with execution verified by network consensus.

Historical Context: Nick Szabo's Vision

The term "smart contract" was coined by cryptographer Nick Szabo in 1994, predating blockchain technology by over a decade. Szabo envisioned embedding contractual clauses into hardware and software to make breach of contract expensive.

"A smart contract is a set of promises, specified in digital form, including protocols within which the parties perform on these promises." Nick Szabo, "Smart Contracts: Building Blocks for Digital Markets" (1996)

Key Characteristics

  • Self-Executing: Automatically performs actions when conditions are met without human intervention
  • Deterministic: Same inputs always produce the same outputs across all nodes
  • Immutable: Once deployed, code cannot be changed (with limited exceptions)
  • Transparent: Code is publicly visible and verifiable on-chain
  • Trustless: Parties don't need to trust each other, only the code
  • Atomic: Transactions either complete fully or revert entirely
[!]Code is Law - But Not Really

The "code is law" mantra suggests smart contract execution is the final arbiter. However, traditional legal systems still apply. A smart contract may execute perfectly yet still violate laws, be based on fraud, or require external legal remedies.

Smart Contract Architecture

Smart Contract Execution Flow
User/DApp
Initiates Transaction
-->
Network
Validates & Broadcasts
-->
EVM
Executes Code
-->
Blockchain
Records State Change

1.2 How Smart Contracts Work

The Ethereum Virtual Machine (EVM)

Most smart contracts run on the Ethereum Virtual Machine (EVM), a sandboxed runtime environment that executes bytecode. The EVM is:

  • Turing-Complete: Can perform any computation given sufficient resources
  • Stack-Based: Uses a last-in-first-out stack for operations
  • Deterministic: Same bytecode produces identical results everywhere
  • Isolated: Contracts cannot directly access external systems

Contract Lifecycle

  1. Development: Code written in Solidity (or Vyper, etc.)
  2. Compilation: Source code compiled to EVM bytecode
  3. Deployment: Bytecode sent to blockchain via transaction
  4. Initialization: Constructor function executes once
  5. Interaction: Users call contract functions via transactions
  6. Execution: EVM processes bytecode, updates state
  7. Finality: State changes recorded permanently

Gas: The Execution Cost Model

Gas
A unit measuring the computational effort required to execute operations on Ethereum. Users pay gas fees (in ETH) to compensate validators for processing transactions.
OperationGas CostPractical Implication
Simple Transfer21,000Base cost for any transaction
Storage Write (new)20,000Most expensive operation
Storage Write (existing)5,000Updating cheaper than creating
Storage Read200Reading is cheap
Memory Expansion3+ per wordScales quadratically
[L]Legal Due Diligence Point

When reviewing smart contracts, gas costs matter legally. A contract designed to be prohibitively expensive to use may constitute a technical barrier to users exercising their rights. Review gas estimations for key functions.

1.3 The Oracle Problem

Smart contracts are deterministic and isolated - they cannot access external data. Oracles bridge this gap, but introduce trust assumptions that can undermine the trustless nature of blockchain systems.

Why Oracles Are Necessary

Blockchains are intentionally isolated from the outside world to maintain consensus. All nodes must agree on state, which requires deterministic inputs. External data sources (APIs, websites, sensors) are non-deterministic and could return different values to different nodes.

The Oracle Problem
Real World
Price, Weather, Events
-->
Oracle
Trust Assumption
-->
Smart Contract
Executes Based on Data

Types of Oracles

Oracle TypeDescriptionTrust ModelExamples
CentralizedSingle data providerHigh trust in one entitySingle API feed
DecentralizedMultiple independent nodesTrust distributedChainlink, Band Protocol
ComputePerforms off-chain computationVerifiable executionChainlink Functions
HumanHuman judgment/arbitrationReputation-basedKleros, Aragon Court

Oracle Attack Vectors

[!]Critical Vulnerability

Oracle manipulation has caused over $1 billion in DeFi losses. Attackers can manipulate price feeds through flash loans, causing contracts to execute based on artificial prices. Example: Mango Markets ($114M exploit, 2022).

  • Data Source Manipulation: Compromising the original data source
  • Flash Loan Attacks: Manipulating spot prices temporarily
  • Front-Running: Seeing oracle updates before they're processed
  • Stale Data: Using outdated prices during high volatility
  • Centralization Risk: Single point of failure in centralized oracles

1.5 Ricardian Contracts: Bridging Code and Law

Ricardian Contract
A document that is simultaneously human-readable (natural language), machine-readable (parseable markup), and cryptographically signed, creating a binding connection between legal prose and executable code.

Ricardian contracts, developed by Ian Grigg in 1996, offer a solution to the code-law divide by creating a single document that serves both legal and technical purposes.

Structure of a Ricardian Contract

  • Legal Prose: Natural language terms that courts can interpret
  • Machine-Readable Tags: Structured data (XML/JSON) for automated parsing
  • Cryptographic Hash: Links the document to on-chain code
  • Digital Signatures: Proves party agreement to specific terms
// Example: Ricardian Contract Reference in Solidity
contract TokenSale {
    // IPFS hash of Ricardian contract document
    string public constant TERMS_HASH =
        "QmXyz...abc123";

    mapping(address => bool) public agreedToTerms;

    function agreeToTerms(bytes32 _termsHash) external {
        require(
            keccak256(abi.encodePacked(TERMS_HASH)) == _termsHash,
            "Invalid terms hash"
        );
        agreedToTerms[msg.sender] = true;
    }
}
[+]Best Practice

For legally robust smart contracts, always pair on-chain code with off-chain Ricardian documentation. Store the legal document on IPFS and reference its hash on-chain, creating an immutable link between code and legal terms.

Key Takeaways

  • Smart contracts are self-executing programs, not complete legal agreements
  • The oracle problem is a critical trust assumption in any real-world smart contract application
  • Legal enforceability depends on satisfying traditional contract formation requirements
  • "Code is law" is a technical philosophy, not a legal reality - traditional courts still apply
  • Ricardian contracts bridge code and law by linking human-readable terms to machine-executable code
  • Jurisdiction, identity, and remedies remain significant challenges for smart contract disputes