What is blockchain?
An interactive learning platform on Smart Contracts – From beginners to hands-on developers
Start learning now
Vending machineBạn bỏ 10k → chọn trà sữa → máy nhả đồ. Không cần nhân viên kiểm tra.
// Logic đời thường
if (coin == 10k && choice == "trà sữa") {
dispenseDrink();
}
Chính xác là Smart Contract: if-then tự động, không trung gian.
It's actually a Smart Contract: an automatic if-then contract, with no intermediaries.
Escrowif (documentSigned) {
releaseFunds(seller);
} else {
refund(buyer);
}
Smart Contract thay thế bên thứ 3: minh bạch, bất biến, chạy đúng điều kiện.
The deployed code cannot be modifiedBITCOIN WHITE PAPER
Bitcoin is proposed as a peer-to-peer electronic cash system that allows online payments to be sent directly from one party to another without going through a financial institution. Transactions are timestamped by hashing them into a continuous chain of proof-of-work, forming a record that cannot be altered.
Traditional commerce relies almost entirely on financial institutions as trusted third parties to process payments. While this works for most transactions, it suffers from the weaknesses of the trust-based model. Bitcoin solves the double-spending problem by using a peer-to-peer distributed timestamp server. Transactions that are computationally impractical to reverse protect both buyers and sellers.
An electronic coin is a chain of digital signatures. Each owner transfers the coin by signing a hash of the previous transaction and the public key of the next owner. To prevent double-spending, all transactions must be publicly announced, and nodes collectively agree on the order by working on the longest proof-of-work chain.
Proof-of-work is implemented by incrementing a nonce until a hash is found with the required number of leading zeros. Once a block is created, it cannot be changed without redoing the proof-of-work for that block and all subsequent blocks. Nodes always consider the longest chain to be the valid one. If two blocks are broadcast simultaneously, the tie is broken when the next proof-of-work is found.
The first transaction in a block creates new coins, providing an incentive for nodes to support the network. This is analogous to gold miners expending resources to mine gold. The incentive encourages honesty, since an attacker with more CPU power than the honest network must choose between defrauding others or generating new coins.
The probability of a slower attacker catching up with the honest chain decreases exponentially as more blocks are added. The race between the honest chain and the attacker chain is modeled as a Binomial Random Walk, showing that the attacker’s chances of success become vanishingly small unless he gets lucky early on.
Bitcoin also addresses privacy: public keys keep transactions anonymous, but if a key is revealed, linked transactions may expose the owner. To prevent this, a new key pair should be used for each transaction.
💎DEFI
💎SIMPLESTORAGEStore and Read data
The most basic contract on Ethereum. Allows writing an integer to the blockchain and reading it back at any time.
SimpleStorage is the most basic Solidity contract and is often the first example to start learning Ethereum.
public is visibility modifier that allows access from anywhere
In Solidity, a view is not a variable, but a modifier for a function. It tells the compiler and EVM that the function only reads data from the blockchain and does not change the contract's state.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
// Biến lưu trữ trên blockchain
uint256 public storedData;
// Hàm ghi dữ liệu (tốn gas)
function set(uint256 _value) public {
storedData = _value;
}
// Hàm đọc dữ liệu (miễn phí khi gọi off-chain)
function get() public view returns (uint256) {
return storedData;
}
}
Smart contract chạy đúng code, nhưng nếu code có lỗi → tiền bay. Dưới đây là các bài học xương máu.
Smart contracts run with the correct code, but if the code is flawed, your money is gone. Here are some painful lessons learned
Hacker khai thác lỗ hổng gọi đệ quy khi rút tiền, rút lặp lại trước khi số dư cập nhật.
The loss amounted to 3.6 million ETH (approximately $50 million at that time).
Reentrancy not Access ControlParity wallet is wallet software/wallet system, powered by Parity Technologies
The initWallet function in the Parity multi-signature wallet contract was not properly restricted, allowing an attacker to reinitialize the contract, assign themselves as the owner, and drain approximately $30M worth of ETH.
A critical flaw in the shared library contract allowed a user to reinitialize it via the initWallet function, gain ownership, and trigger selfdestruct.
This permanently disabled the library, causing over $300M worth of ETH in dependent multi-signature wallets to be locked forever.
Smart Contract bug on Ethereum
The bZx lending protocol suffered a critical exploit when attackers manipulated its price oracle by using flash loans to distort the reported value of assets. This allowed them to borrow against artificially inflated collateral and drain funds. The incident led to losses of approximately $630K in the first attack and further exploits soon after, highlighting the dangers of relying on single-source or manipulable oracles in DeFi.
Oracle Flash Loan Financial ExploitOne of the classic vulnerabilities in Solidity prior to version 0.8.0
`uint8` max 255. Nếu cộng thêm 1 → về 0. Hacker exploit batch transfer, mint token vô hạn. Solidity 0.8+ đã fix mặc định.
Math Error Compiler VersionChoose the correct answer. The system will score your answer and provide an explanation immediately.