1/63
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Characteristics of Bitcoin Script
stack-based, simple isntruction set, non-Turing complete, deterministic
Pay-to-Public-Key-Hash (P2PKH)
single signature spending requiring a private key
Multi-signature (Multisig)
Requires M out of N signatures for shared custody/governance
Pay-to-Script-Hash (P2SH)
Complex conditions through referencing a script hash
Zero-Knowledge proofs
verifies transaction without revealing underlying data
Proof of work
get reward through computing valid nonce value
Halving of block reward
Starting in 2008, starts at 50 btc, divides by half every 4 years. Currently at 3.125
Difficulty Adjustment Alg
every 2016 blocks (2 weeks at 10-minute intervals), maximum 4x change per adjustment
UTXO Model
stateless, new address for each transaction, high parallelization, limited scripting, simple
Account Model
maintains account balances, reused addresses for transactions, limited parallelization, full programmability, complex
Externally Owned Accounts (EOAs)
controlled by private keys, initiates transactions, no code execution capabilities, used by human users and wallets, has nonce and balance
Contract Accounts
controlled by smart contract code, cannot initiate transactions, only responds to calls, contains executable bytecodes, has storage for persistent data
Nonce
for EOA, transaction counter preventing replay attacks
for contracts, number of contracts created
Balance
amount of Ether (in wei) owned by account, contracts can hold Ether
CodeHash
hash of the account’s code, points to executable bytecode, only for contracts
StorageRoot
root hash of the account’s storage trie, contains persistent data for smart contracts
Transfer Ether
sends ETH from one account to another
Call Contract Functions
executes code in existing smart contracts
Deploy Contracts
create new smart contracts on the network
to (transaction field)
Destination address or recipient
value (transaction field)
amount of ether to transfer
data (transaction field)
contract bytecode or function call data
gasLimit (transaction field)
maximum gas willing to spend
maxFeePerGas (transaction field)
maximum total fee per gas unit
maxPriorityFeePerGas (transaction field)
tip to minors for priority inclusion
Simple Transfer
to: recipient address
value: ETH amount
data: empty
Contract Call
to: contract address
value: ETH (optional)
data: function call
Contract Deployment
to: empty (null)
value: ETH (optional)
data: bytecode
Upfront payment of gas
gasLimit * maxFeePerGas
Common gas costs
basic operations (add, mul, etc.): 3-5 gas
memory operations: 3-200 gas
storage write: 20000 gas
contract creation: 32000 gas
Total Fee
GasUsed * (BaseFee + PriorityFee)
Base Fee
burned by admin to reduce ETH supply and prevent inflation
Priority Fee (Tip)
user-set tip to incentivize minors/validators to include the transaction quickly
Stack
LIFO with maximum of 1024 items, each item is max 256-bits
Memory
temporary byte-addressed storage that expands dynamically during execution, cleared after each call completes
Calldata
read-only input bytes passed to contract during transaction or call, contains function identifiers and encoded parameters, must be loaded onto stack for processing
Storage
persistent key value map from 256 bit keys to 256 bit values, survives after the call finishes, all slots initially zero
PUSH(1-16)
adds value to ith spot
DUP(1-16)
duplicates ith value to top
SWAP(1-16)
swaps top value with ith value after it
POP
removes top item
Arithmetic OPcodes (add, sub, mul, div, mod, addmod, mulmod)
256-bit modular arithmetic operations wraps at 2^256 on top two values of stack
Comparison opcodes (LT, GT, EQ, ISZERO)
compares top two values and produces boolean results
Control Flow OPcodes (JUMP, JUMPI, JUMPDEST, REVERT, STOP)
implements conditional and unconditional branching, JUMPDEST marks valid targets
Return OPcodes (RETURN, REVERT)
halts execution and return data (RETURN) or revert state changes (REVERT)
memory, storage, calldata opcodes (mload, mstore, mstore8, sload, sstore, calldataload, calldatasize, calldatacopy)
read and writes to top of stack, store expects key at top, value at 2nd, copy expects destoffset, offset, length
PUSH, DUP, SWAP cost
3 gas
POP cost
2 gas
ADD, SUB, MUL cost
3-5 gas
DIV, MOD cost
5 gas
LT, GT, EQ cost
3 gas
MLOAD, MSTORE cost
3 gas + expansion
SLOAD (warm) cost
100 gas
SLOAD (cold) cost
2100 gas
SSTORE (warm) cost
2900 gas
SSTORE (cold, new) cost
22100 gas
JUMP, JUMPI cost
8 gas
CALL cost
100+ gas (base)
Cold Access
first time accessing a storage slot in a transaction, first time calling a contract address, very high costs, compensates for loading data from disk
Warm Access
subsequent access to same slot/address, data already cached in memory, lower gas costs (than cold access), rewards batching operations
Read Batching
batch multiple reads from the same storage slot to reduce gas cost by turning cold reads into warm reads
Write Batching
accumulate changes in memory, commit once to storage, minimizes number of SSTORE operations
Cold to warm cost ratio
7.6x