RemNote Community
Community

Smart contract - Fundamentals and Architecture

Understand smart contract fundamentals, deployment architecture, and security considerations.
Summary
Read Summary
Flashcards
Save Flashcards
Quiz
Take Quiz

Quick Practice

What is the general definition of a smart contract?
1 of 12

Summary

Smart Contracts: Definition, Development, and Technical Foundations What Is a Smart Contract? A smart contract is a computer program that automatically executes the terms of an agreement without requiring human intervention or a trusted intermediary. Think of it as a digital agreement written in code: when certain conditions are met, the contract automatically performs the agreed-upon actions. The key innovation is automation. Instead of relying on lawyers, judges, or other intermediaries to enforce a contract, the blockchain network itself enforces it through code. This addresses three major problems with traditional contracts: Reduction of intermediaries: You don't need a bank, lawyer, or escrow service to ensure both parties follow through Lower costs: Removing middlemen reduces fees and arbitration expenses Decreased fraud: The code executes exactly as written, minimizing accidental exceptions and malicious behavior Distinguishing Smart Contracts from Smart Legal Contracts It's important to clarify a common source of confusion. A smart legal contract is different from a smart contract. A smart legal contract is a traditional written agreement (in natural language like English) where certain key terms are also encoded in machine-readable code. It's still fundamentally a legal document, just with some parts digitized. A true smart contract, by contrast, is entirely code-based and executes automatically on a blockchain. Historical Context: How Smart Contracts Emerged The term "smart contract" wasn't invented with blockchain. In 1996, computer scientist Nick Szabo proposed the concept of contracts enforced by hardware or software rather than law. However, the technology didn't exist to implement this vision at scale until blockchain arrived. When Vitalik Buterin proposed Ethereum in his 2014 white paper, he recognized that the Bitcoin protocol was a limited version of Szabo's idea. Bitcoin could execute simple transactions, but Ethereum's innovation was to make smart contracts truly powerful by using a programming language called Solidity that is Turing complete—meaning it could express any computation. Since Ethereum, many other blockchains have added their own smart contract capabilities with various programming languages. How Smart Contracts Work: Technical Deployment To understand how smart contracts function on a blockchain, it helps to know what happens when one is deployed. The Deployment Process: When you want to create a smart contract on the Ethereum blockchain, you send a special transaction from your wallet. This transaction contains: The compiled smart contract code (translated from Solidity into low-level bytecode) A special receiver address indicating this is a contract deployment Once this deployment transaction is included in a blockchain block, something crucial happens: the smart contract's code becomes immutable. The contract executes to set up its initial state, and from that point forward, the code cannot be changed or deleted. This permanence is a double-edged sword—it ensures security but also means any bugs are permanent. What the Contract Can Do: Once deployed, a smart contract can: Store state: It maintains data (like account balances, ownership records, or game scores) Perform computations: It executes logic based on inputs Interact: End users send transactions to the contract, triggering functions that may change its state or transfer tokens between accounts Call other contracts: One contract can invoke functions in another contract, enabling complex ecosystems Determinism: The Foundation of Blockchain Smart Contracts Here's a critical concept that often confuses students: all processes on a blockchain must be deterministic. Deterministic means the same input always produces the same output. If you run a smart contract function twice with identical data, it must produce identical results. This requirement exists because every node in the blockchain network must execute the same transactions and reach the same conclusion about the current state. Otherwise, the network would disagree and split apart. Why this matters for security: Byzantine fault tolerance algorithms (the consensus mechanisms that secure blockchains) rely on this determinism. If different nodes produced different results from the same transaction, the network couldn't reach consensus, and the blockchain would break. <extrainfo> The Randomness Problem This deterministic requirement creates an interesting problem: some applications genuinely need randomness. A lottery smart contract can't fairly select winners if the selection is deterministic—users could predict the outcome. Similarly, games and casinos need unpredictability. This tension between the need for determinism (for consensus) and the need for randomness (for fair applications) is an active area of blockchain research. Solutions exist but are beyond the scope of basic smart contract understanding. </extrainfo> Programming Languages: Solidity and Beyond The most common smart contract language is Solidity, used on Ethereum. Smart contracts written in Solidity are compiled into bytecode that runs on the Ethereum Virtual Machine (EVM)—essentially a computer program that exists on every Ethereum node and executes the contract code identically everywhere. The Turing Completeness Double-Edged Sword Solidity is Turing complete, which means it can theoretically compute anything. This power comes with a critical risk: the halting problem. In simple terms, there's no way to know in advance whether a program will finish executing or run forever. On a blockchain, if a contract runs forever, it would waste resources and never complete its transaction. This risk exists purely because of Turing completeness. A non-Turing-complete language can't express all possible computations, but it can guarantee that every program finishes. <extrainfo> Alternative Programming Languages Because of these risks, several alternative languages have been designed: Vyper: A simpler language that makes certain unsafe patterns harder to write Simplicity: Designed from the ground up to be non-Turing complete Scilla: A language that separates contract logic into safe and potentially-unsafe components Asset-oriented languages like Scrypto: These treat digital assets as native data types (instead of just data) and enforce safety rules automatically at compile time, preventing entire classes of bugs These alternatives represent different approaches to the fundamental trade-off: more power (Turing completeness) versus more safety (restricted languages). </extrainfo> Association with Cryptocurrencies and Decentralized Applications While smart contracts can theoretically run on any blockchain, they're most commonly discussed in relation to cryptocurrency platforms, especially Ethereum. This is because Ethereum was purpose-built to be a "world computer" for smart contracts. Smart contracts serve as the foundation for: Decentralized Finance (DeFi): Automated lending, trading, and financial services without banks Non-Fungible Tokens (NFTs): Contracts that represent unique digital assets Decentralized Autonomous Organizations (DAOs): Organizations governed entirely by code and token-holder votes The ability to create these applications is what makes smart contracts genuinely revolutionary compared to traditional software.
Flashcards
What is the general definition of a smart contract?
A computer program or transaction protocol that automatically executes, controls, or documents events and actions according to the terms of a contract or agreement.
Which blockchain is most commonly associated with the introduction and popularization of smart contracts?
The Ethereum blockchain.
How does a smart contract differ from a "smart legal contract"?
A smart legal contract is a traditional natural-language agreement with selected terms expressed in code, whereas a smart contract is a pure computer program/protocol.
Who originally coined the term "smart contract" in 1996 to describe contracts enforced by hardware or software?
Nick Szabo.
How did the 2014 Ethereum white paper, authored by Vitalik Buterin, describe the Bitcoin protocol in relation to Nick Szabo’s concept?
As a weak version of Szabo’s smart contract concept.
What is the technical process for deploying a smart contract on a blockchain?
Sending a transaction from a wallet containing the compiled contract code and a special receiver address.
What happens to a smart contract's code once the deployment transaction is included in a block?
It executes to establish its initial state and becomes immutable (it cannot be updated thereafter).
How do end users typically interact with an existing smart contract on the blockchain?
By sending transactions to it.
Into what form is Solidity code compiled before it runs on the Ethereum Virtual Machine (EVM)?
Low‑level bytecode.
What specific theoretical problem and risk is inherited by smart contract languages that are Turing complete, such as Solidity?
The halting problem, which can lead to insecure contracts.
How do asset-oriented domain specific languages like Scrypto handle digital assets?
They treat digital assets as native data types and enforce finiteness and safety rules at compile time.
What is a major challenge for blockchain applications like lotteries and casinos due to the deterministic nature of blockchain execution?
The need for secure randomness.

Quiz

Who first used the term “smart contract” and what was its intended enforcement mechanism?
1 of 14
Key Concepts
Smart Contracts and Blockchain
Smart contract
Ethereum
Solidity
Ethereum Virtual Machine (EVM)
Turing completeness
Decentralized Applications
Decentralized finance (DeFi)
Non‑fungible token (NFT)
Smart legal contract
Foundational Concepts
Nick Szabo
Byzantine fault tolerance