Smart Contracts 101

Polkadot Smart Contracts


About Me

Screenshot 2023-11-01 at 21.21.06.jpeg|300


Blockchain Models

Smart Contracts 101 2025-04-23 15.49.08.png

--

Blockchain Models

Smart Contracts 101 2025-04-23 15.52.40.png

--

Blockchain Models

Smart Contracts 101 2025-04-23 16.00.57.png

Note:

Database is utter BS
State Machine is accurate, but a bit to math-y
Computer is accurate, and one that most people relate to, we will use this one


The Blockchain Computer

--

The Blockchain Computer

Note:

First blockchains were computers with a (almost) fixed code. Bitcoin's code is ONLY how to do transfer of BTC, and therefore the State of the Bitcoin computer was only user balances. Nothing more.

--

The Blockchain Computer

--

Blockchain Computer

--

Blockchain Computer


What Is A Smart Contract

A way to add programs with custom code and memory to the blockchain computer, making it extensible, with the very same security guarantees.


Anatomy Of Smart Contracts

A Smart Contract has:

Note:
this is based on Ethereum/Solidity/EVM contracts
Bringing it all together


How to Write a Contract

Note:

EVM: Ethereum Virtual Machine


How to Execute a Contract

If Ethereum wants to execute a totally untrusted code, what challenges does it have?

--

Extending Memory

What about the fact that a contract can add more data to its own memory, which in turn bloats the overall blockchain memory?


Lifecycle

contracts_compilation.png


Case Studies

--

Case Study

Simple Escrow Contract

--

Case Study

Web3 Roulette


Advance Topics

--

Composability ~ Shared Environment

Note:

Contracts on Ethereum can always call one another

--

Re-Entrancy Attacks

contract EtherStore {
    mapping(address => uint256) public balances;

    function deposit() {
        balances[msg.sender] += msg.value;
    }

    function withdraw() {
        uint256 bal = balances[msg.sender];
        require(bal > 0);

        (bool sent,) = msg.sender.call{value: bal}("");
        require(sent, "Failed to send Ether");

        balances[msg.sender] = 0;
    }
}

--

Re-Entrancy Attacks

contract Attacker {
	// Our interface to EthStore contract
    EtherStore public etherStore;

    receive() external payable {
        etherStore.withdraw();
    }
}

Note:

Cyfrin Code Glossary: Re-entrancy Hack in Solidity


Smart Contracts in Polkadot

polkadot-new-dot-logo.png

Polkadot


Past

Smart Contracts 101 2025-04-23 16.24.44.png

Note:

Both of these initiated in Parity, but are pursued as community projects now.


Now

Smart Contracts 101 2025-04-23 16.24.44 1.png

--

Now


Open Question


Outro


Questions


Show Comments