[๋ธ”๋ก์ฒด์ธ] ZKP · DeFi · Solidity ๊ธฐ๋ง๊ณ ์‚ฌ ์ •๋ฆฌ

2026. 1. 26. 19:36ใ†ComputerScience

 

 

 

1. ETH Advanced  

* Trillema – 1. Security - The ability of the blockchain system to operate as expected, defend itself from attacks, bugs, and other unforeseen issues : ๋ณด์•ˆ  

2. Scalability - The ability for a blockchain system to handle an increasingly growing amount of transactions : ํ™•์žฅ์„ฑ   

3. Decentralization - Creating a blockchain system that does not rely on a central point of control  

 

- ์ด๋”๋ฆฌ์›€์€ ๋ณด์•ˆ์€ ํฌ๊ธฐํ•˜๊ธฐ ์–ด๋ ค์›€, ๋‚จ์€ ๋‘˜ ์ค‘ ํƒˆ์ค‘์•™์„ฑ์„ ์ฒซ๋ฒˆ์งธ๋กœ ์„ ํƒ  

+ ์ด๋”๋ฆฌ์›€ ์œ„์—์„œ ๋กค์—… ์ฒด์ธ๋“ค์ด ํ™•์žฅ์„ฑ์„ ๊ฐ€์ ธ๊ฐ€๋„๋ก ์„ค๊ณ„  

- ๋‹ค๋ฅธ ์ฒด์ธ๋“ค, ์†”๋ผ๋‚˜ -> ํƒˆ์ค‘์•™์„ฑ ํฌ๊ธฐ, ํ™•์žฅ์„ฑ ์„ ํƒ : ์‹ค์ œ๋กœ ์‚ฌ๋žŒ๋“ค์ด ์“ธ๋งŒํ•˜๋„๋ก ๋งŒ๋“ค์ž  

- ๋น„ํŠธ์ฝ”์ธ (BTH)   = ์นœ๊ตฌํ•œํ…Œ ๋ˆ๋ณด๋‚ด๋Š”๋ฐ 10๋ถ„์”ฉ ๊ฑธ๋ฆฌ๋Š” ๊ฒƒ  

 

- How to solve scalability? - 10๊ฐœ๋ฅผ 1์ดˆ์— ์ฒ˜๋ฆฌ vs 100๊ฐœ๋ฅผ 10์ดˆ์— ์ฒ˜๋ฆฌ -> ๋‘˜์€ ๋‹ค๋ฆ„   

- Bandwidth = throughput (๋‘˜ ๋‹ค 10์œผ๋กœ ๋™์ผ)   

- Latency = ๊ฐœ์ธ์˜ ์ž…์žฅ์—์„œ 10์ดˆ, 1์ดˆ๋งˆ๋‹ค ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์€ ๋‹ค๋ฆ„  

 

* Layer 1 (ETH) - Data availability layer / Security layer   

* Layer 2 - Faster confirmation / Lower transaction cost / Customization  

+ 2์˜ ๋ชจ๋“  ๋‚ด์šฉ layer 1์— ์“ฐ์ž„ -> shut-down ๋˜๋”๋ผ๋„, 1์—์„œ ๋ฐ์ดํ„ฐ(๋ˆ) ํšŒ์ˆ˜ ๊ฐ€๋Šฅ  

= Layer 2์˜ ๋ชจ๋“  tx๋“ค์ด layer 1์—๋„ ์žˆ๋‹ค + ๊ฒ€์ฆ์ด ๊ฐ€๋Šฅํ•˜๋‹ค (security ์ธก๋ฉด)  

 

 

- Layer 1๊ณผ 2 ์—ฐ๊ฒฐํ•˜๋Š” smart contract  

- ์ฒด์ธ ์žฌ๋‹จ์—์„œ ์šด์˜ํ•˜๋Š” sequencer  : tx๋“ค์„ ๋ธ”๋Ÿญ์— ๋„ฃ๋Š”๋‹ค (ํƒˆ์ค‘์•™ํ™” ์ด์Šˆ O)    

- transaction order ์ •์˜ํ•จ - MEV : Maximal Extractable Value  : ์ตœ๋Œ€์ถ”์ถœ ๊ฐ€๋Šฅ๊ฐ€์น˜ ๋ฌธ์ œ O     

- Layer 2 tx๋“ค์ด ์Œ“์ธ ๋ธ”๋Ÿญ์ด 1์˜ tx ํ•˜๋‚˜์— ๋“ค์–ด๊ฐ -> ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๋ฉด ํ•ด๋‹น tx๋ฅผ 1์ด ์‹คํ–‰ ๊ฐ€๋Šฅ   

- Layer 3๋Š” Layer 2์— ๊ธฐ๋ก๋จ (Layer1์— security์— ๊ธฐ๋Œ€๊ณ  ์žˆ๋Š”๊ฐ€๋Š” ์˜๋ฌธ)  

- ์‹ค์ œ computation (balance ๋ณ€ํ™”, coin swap ๋“ฑ)์€ layer 2์—์„œ ๋น ๋ฅด๊ฒŒ ์ฒ˜๋ฆฌ, User์—๊ฒŒ ์ œ๊ณต     

 

 

 

 

* Types of Rollups   

1. Optimistic Rollup - Assume that blocks are generated in a valid way

If there is a single honest validator at least, we can find out invalid blocks in a certain amount of time (๊ฒ€์ฆ ์ผ์ฃผ์ผ ๊ฑธ๋ฆผ)  

- ํŠธ๋žœ์ ์…˜์ด ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ์‹คํ–‰, ํ•˜๋‚˜๋ผ๋„ ์ •์งํ•œ validator๊ฐ€ ์žˆ๋‹ค๋ฉด, ๋ฌธ์ œ ๋ฐœ๊ฒฌ, ์ œ๋ณด O  

- Layer 1์— ์ „๋ถ€ ์˜ฌ๋ ค์„œ ์‹คํ–‰ -> TPS ๋‚ฎ์Œ / ๋ฐ์ดํ„ฐ ๋ชจ๋‘ ์˜ฌ๋ ค์•ผ ํ•˜๋‹ˆ๊น, Privacy ๊ตฌ์„ฑ ์–ด๋ ต๊ณ  ๋น„์Œˆ   

- EVM ๊ฑฐ์˜ ๊ทธ๋Œ€๋กœ ์˜ฌ๋ฆด ์ˆ˜ ์žˆ๋‹ค    

 

2. Zero-Knowledge Rollup

- The validity of a block can be proven by zero knowledge  

- No need to check validity by the nodes / But generating proof is computationally heavy  

- ์˜์ง€์‹ ๊ธฐ์ˆ  – tx ๋ชจ๋‘ ์‹คํ–‰ํ•˜์ง€ ์•Š์•„๋„, ํŠธ๋žœ์žญ์…˜์˜ ์œ ํšจ์„ฑ ๊ฒ€์ฆ ๊ฐ€๋Šฅ   

- ์ˆ˜ํ•™์  ๊ฒ€์ฆ : ์ฆ๋ช…์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด computation ๋งŽ๋‹ค / ๋Œ€์‹  ๋งค์šฐ ๋น ๋ฅด๋‹ค.   

- Layer 1์— ๋ชจ๋‘ ์˜ฌ๋ฆด ํ•„์š”X -> ๋†’์€ TPS / ์˜์ง€์‹ ์ฆ๋ช…์ด ๊ฐ€๋Šฅํ•œ ํ˜•ํƒœ ๋ณ€ํ˜•, ๋ชจ๋“  ์†”๋ฆฌ๋””ํ‹ฐ์ฝ”๋“œ๋Š” X  

- Layer 2์—์„œ Proof ๋งŒ๋“ค ๋•Œ๋งˆ๋‹ค ์—ฐ์‚ฐ ๋งŽ์ด ํ•„์š” / ์ฆ๋ช…ํ•  ๋•Œ ์˜์ง€์‹์œผ๋กœ ๋”์šฑ trust ๊ฐ€๋Šฅ           

 

- ETH๋Š” ์›๋ž˜ monolithic -> roll up์ด ๋˜๋ฉด์„œ, exec๋Š” L2, ๋‚˜๋จธ์ง€ ๋‘˜์€ L1์œผ๋กœ ๊ฐ€๊ฒŒ ๋จ  

- Sui, Aptos : monolithic / ์ด๋”๋ฆฌ์›€ ์ง„์˜์—์„œ ํŒŒ์ƒ๋˜๋Š” ๋งŽ์€ ๋ ˆ์ด์–ด๋“ค -> Modular  - celestia : cosmos ๋ณ„๋„์˜ ์ฒด์ธ           

 

 

 

2. ZKP Zero Knowledge Proof  

- A protocol in which one party can convince another party    

- some given statement is true / without conveying to the verifier any information   

- beyond the mere fact of the statement’s truth  (์›๋ณธ๋ฐ์ดํ„ฐ ๋…ธ์ถœ ์—†์ด, ์ƒ๋Œ€๋ฅผ ๊ฒ€์ฆ ๊ฐ€๋Šฅ)  

 

- Prover vs Validator : The Ali Baba Cave  

– P๊ฐ€ B๋กœ ๊ฐ€๋Š” ๊ธธ์„ ํƒํ•จ -> V๊ฐ€ A๋กœ ๋‚˜์˜ค๋ผ ํ•จ -> P๊ฐ€ ๋น„๋ฒˆ์„ ์•Œ์•„์•ผ๋งŒ ๊ฐ€๋Šฅ  1

. Completeness : ์™„์ „์„ฑ - Peggy ์ง„์งœ๋ผ๋ฉด ํ…Œ์ŠคํŠธ๋ฅผ ๊ณ„์† ํ†ต๊ณผ  

2. Soundness : ๊ฑด์ „์„ฑ - Peggy๊ฐ€ ๊ฑฐ์ง“๋ง์Ÿ์ด๋ผ๋ฉด ํ™•๋ฅ ์ ์œผ๋กœ ๋“คํ†ต๋‚จ  

3. Zero-Knowledge :์˜์ง€์‹์„ฑ - Victor๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋„, ๋ฌธ ์—ฌ๋Š” ์›๋ฆฌ๋„ ๋ชจ๋ฆ„   

- P์˜ ์ง€์‹์„ ์ฆ๋ช… ๋ฐ›์•˜์„ ๋ฟ, ๊ทธ ์ง€์‹ ์ž์ฒด๋Š” ๋ชจ๋ฆ„  

 

- Peggy proved that she knows the password of the gate without revealing the password.  

* Efficiently Verifiable Proofs (NP-proofs)  

- Claim ์ฆ๋ช…ํ•˜๊ณ ์ž ํ•˜๋Š” ๋ช…์ œ / P: ์ฆ๋ช…ํ•˜๋ ค๋Š” ์‚ฌ๋žŒ / V: ๊ฒ€์ฆํ•˜๋ ค๋Š” ์‚ฌ๋žŒ   

- Prover : ์‹œ๊ฐ„ ์ œํ•œ X  - Verifier : ๋‹คํ•ญ์‹œ๊ฐ„: O(n), O(n²), O(n³) ๋“ฑ  

* NP ๋ฌธ์ œ = V ๋งค์šฐ ๋น ๋ฆ„, P๋Š” ์˜ค๋ž˜ ๊ณ„์‚ฐ๋„ ok  - ๊ฒ€์ฆ์ด ๋„ˆ๋ฌด ๋А๋ฆฌ๋ฉด ํ”„๋กœํ† ์ฝœ ์˜๋ฏธ X  

- NP: ๋‹ต ๊ฒ€์ฆํ•˜๊ธฐ๋Š” ์‰ฌ์šฐ๋‚˜, ๋‹ต ์ฐพ๊ธฐ๋Š” ์–ด๋ ค์›€        

 

 

- P๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ์ƒ‰ ์ฃผ์žฅ / V๋Š” ์ƒ‰๋งน = ๋‹ค๋ฅธ ์ƒ‰์ธ์ง€ ์ง์ ‘ ๋ณผ ์ˆ˜ X, but ๊ฑฐ์ง“๋ง์„ ์žก์•„๋‚ผ ๋ฐฉ๋ฒ•์€ O  

- ๊ฒ€์ฆ์ž ๋ฌด์ž‘์œ„ ๋’ค์ง‘๊ธฐ -> ์ฆ๋ช…์ž๊ฐ€ ์„ ํƒ์„ ๋”ฐ๋ผ์˜ฌ ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธ -> ๋‘ ์ƒ‰ ๋‹ค๋ฆ„์„ ZKP ์ฆ๋ช…   

- ๊ฒ€์ฆ์ž ๋˜์กŒ๋˜ ๋™์ „ A์˜ ๊ฒฐ๊ณผ == ์ฆ๋ช…์ž ์ถ”์ธก -> accept, ๋‹ค๋ฅด๋ฉด reject (P ๊ฑฐ์ง“์ด๋ฉด 1/2 ์ฐ๊ธฐ ing)  

 

- Def: L is an NP-language (or NP-decision problem), if there is a poly (|x|) time verifier V where  

- Completeness = True claims have (short) proofs  

- Soundness = False theorems have no proofs  

 

 

 

 

 

* Why do we need random bit b?   

- If we only use b = 0, soundness cannot be satisfied. (50% ํ™•๋ฅ ๋กœ๋Š” ๋งž์ถœ ์ˆ˜ ์žˆ์Œ)  

- z^2 = s * y mod N / we can find s even if we don’t know x (s = z^2 / y mod N)  

- Cheating prover can provide the same s repeatedly, but there is no way to verify.  

- b๊ฐ€ random์ด์–ด์•ผ, ์ ˆ๋ฐ˜ ํ™•๋ฅ ๋กœ ๋ฐ˜๋ณตํ–ˆ์„ ๋•Œ ์‚ฌ๊ธฐ๊พผ์ด ๊ฑธ๋ฆผ (soundness ์ถฉ์กฑ๋จ)  

+ ZCash (zk-SNARK) – ZKP ์‚ฌ์šฉ, ์†Œ์œ ์ž ๊ฐ„ ๊ฐœ์ธ์ •๋ณด ๋…ธ์ถœ ์—†์ด, ์ƒํ˜ธ ์ฝ”์ธ ์ „์†ก ๊ฐ€๋Šฅ    

 

 

 

3. Decentralized Finance  

- DeFi = Decentralized Finance   

- Decentralized : ์ค‘์•™ ๊ธฐ๊ด€์ด ์†Œ์œ ๊ถŒ์„ ๊ฐ–์ง€ X / ์ž์‚ฐ์„ ์†Œ์œ ํ•œ ์‚ฌ๋žŒ๋งŒ์ด ์ž์‚ฐ์„ ์ด๋™์‹œํ‚ด  

- Finance : ๊ธˆ์œต ์„œ๋น„์Šค (์˜ˆ๊ธˆ, ๋Œ€์ถœ, ์ž์‚ฐ ๊ฑฐ๋ž˜ ๋“ฑ)  

- KYC = ๊ณ ๊ฐ ํ™•์ธ : Know Your Customer   

- AML = ์ž๊ธˆ์„ธํƒ๋ฐฉ์ง€ : Anti-Money Laundering              

 

 

 

 

* Landscape of DeFi Protocols            

- ํ”„๋กœํ† ์ฝœ ์‹ค ์‚ฌ๋ก€ : staking, lending, DEX, Advanced  

 

 

 

3-1. Staking   

- ํ† ํฐ์„ ์˜ˆ์น˜ํ•˜๋ฉด ์ด์ž ์ง€๊ธ‰ / ์ด์ž์˜ ์›์ฒœ = ํ”„๋กœํ† ์ฝœ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ธํ”Œ๋ ˆ์ด์…˜์„ ์ด์ž๋กœ ์ง€๊ธ‰   

- PoS(Proof of Stake) ํ•ฉ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋งŽ์ด ์‚ฌ์šฉ 

 * ETH Consensus - The Merge ์ดํ›„ PoS ์ฒด์ธ ์ „ํ™˜ / ๋…ธ๋“œ ๊ฒ€์ฆ์ž ๋˜๋ ค๋ฉด 32 ETH ํ•„์š”  

- ๊ฒ€์ฆ์ž๋Š” ๋ธ”๋ก ์ œ์•ˆ + ์ œ์•ˆ๋œ ๋ธ”๋ก์˜ ์œ ํšจ์„ฑ ๊ฒ€์ฆ / ์ œ์•ˆ · ๊ฒ€์ฆ ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ๋ฆฌ์›Œ๋“œ ์ˆ˜์ทจ     

 

* ETH Staking (1, 2 = 32 ETH need vs 3, 4 = ๊ผญ 32๊ฐœ ์—†์–ด๋„ ๋จ)   

1. Solo Staking = ๋ณธ์ธ์ด ์ง์ ‘ ๋…ธ๋“œ ์šด์˜ํ•˜๋ฉฐ, ๋ธ”๋ก์„ ๊ฒ€์ฆํ•˜๊ณ , ๊ทธ์— ๋งž๋Š” ์ธ์„ผํ‹ฐ๋ธŒ๋ฅผ ์ˆ˜์ทจ  

2. Staking as a Service = ํด๋ผ์šฐ๋“œ ์„œ๋น„์Šค ๋“ฑ ํ•˜๋“œ์›จ์–ด ์ธํ”„๋ผ๋ฅผ ์ œ๊ณตํ•˜๋Š” ์„œ๋น„์Šค  

+ ์ง์ ‘ ๋…ธ๋“œ๋ฅผ ์šด์˜ํ•˜๋“ฏ 32 ETH ์˜ˆ์น˜ํ•ด์•ผ ํ•˜๋ฉฐ, ์ˆ˜์ต ๋ชจ๋‘ ๊ฐ€์ ธ๊ฐˆ ์ˆ˜ ์žˆ์Œ but ๋…ธ๋“œ ์šด์˜๋น„ ์ง€์ถœ  

3. Pool Staking = 32 ETH๋ณด๋‹ค ์ ์€ ์–‘(์†Œ์•ก)์œผ๋กœ ๋‹ค๋ฅธ ์„œ๋น„์Šค๋ฅผ ํ†ตํ•ด ์˜ˆ์น˜, ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ ๋ชจ์•„์„œ ์šด์˜  

4. CEX Staking = ์ค‘์•™ํ™” ๊ฑฐ๋ž˜์†Œ์— ํ† ํฐ์„ ์ž…๊ธˆํ•˜๊ณ  ์ž…๊ธˆ๋œ ์–‘์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์Šคํ…Œ์ดํ‚น ๋ฆฌ์›Œ๋“œ ์ง€๊ธ‰  

- ์ž…์ถœ๊ธˆ ๋นˆ๋ฒˆ, staking to unstaking 1์ฃผ์ผ ์ •๋„ ๊ฑธ๋ฆผ, 100๊ฐœ ์ค‘ 50๊ฐœ ์ •๋„๋งŒ ์˜ˆ์น˜ ๊ฐ€๋Šฅ   

 

* Liquid Staking Token, Liquid Staking Derivatives  

- ๋‹จ์ˆœํžˆ ์Šคํ…Œ์ดํ‚น ๊ธฐ๋Šฅ์„ ์ œ๊ณต X, ์Šคํ…Œ์ดํ‚นํ•˜๋ฉด ๋ณ„๋„์˜ ํ† ํฐ์„ ์ง€๊ธ‰ (10 ETH -> 10 stETH)  

- Utility of LST = ETH-stETH ํ†ตํ•ด ์ฆ‰์‹œ unstake = stETH ์‹œ์žฅ์—์„œ ๋ฐ”๋กœ ํŒ”๋ฉด ์ฆ‰์‹œ ETH ์ „ํ™˜ ๊ฐ€๋Šฅ  

- stETH ๋งก๊ธฐ๊ณ  ๋‹ค๋ฅธ ํ† ํฐ ๋Œ€์ถœ (ETH, USDT, etc) -> looping, ๋ ˆ๋ฒ„๋ฆฌ์ง€ (10 -> 15, 20 ๊ฐ€๋Šฅ)   

- wstETH(wrapped) ํ†ตํ•ด compounding ๊ฐ€์น˜ ํ‘œํ˜„ํ•˜๋Š” ํ† ํฐ์œผ๋กœ ์ „ํ™˜ํ•˜์—ฌ DeFi ์ด์šฉ (์นœํ™”์ )   

 

- ETH : stETH = 1:1 ๊ฑฐ์˜ ๋น„์œจ ๊ณ ์ •, but ์ด์ž ์ปดํŒŒ์šด๋”ฉ X, ์ˆ˜๋Ÿ‰ ์ฆ๊ฐ€ (rebase)   

- wstETH = ์ˆ˜๋Ÿ‰ ๊ณ ์ •, ํ† ํฐ์˜ ๊ฐ€์น˜๊ฐ€ ์•Œ์•„์„œ ์˜ฌ๋ผ๊ฐ, ์ด์ž ์ปดํŒŒ์šด๋”ฉ O  

- Liquid = ์œ ๋™์„ฑ, ์Šคํ…Œ์ดํ‚น์„ ํ–ˆ์Œ์—๋„, ์ž๊ธˆ์ด ๋ฌถ์ด์ง€ ์•Š๊ณ  ๊ณ„์† ์“ธ ์ˆ˜ ์žˆ๋‹ค๋Š” ์˜๋ฏธ   

 

* Kaia Consensus - PoS + PBFT ์ปจ์„ผ์„œ์Šค ํ™œ์šฉ / ์นด์นด์˜ค์—์„œ ๊ฐœ๋ฐœ  

- ๋…ธ๋“œ ๊ฒ€์ฆ์ž๊ฐ€ ๋˜๊ธฐ ์œ„ํ•ด์„œ๋Š” 5M KLAY ํ•„์š” / ๊ฒ€์ฆ์ž๋Š” ๋ธ”๋ก์„ ์ œ์•ˆ or ์ œ์•ˆ๋œ ๋ธ”๋ก ์œ ํšจ์„ฑ ๊ฒ€์ฆ  

- ๋งค epoch๋งˆ๋‹ค round-robin ๋ฐฉ์‹์œผ๋กœ proposer ์„ ์ •  

- Block reward = Validator 50% + Klaytn Community Fund 30% + Klaytn Foundation Fund 20%        

 

3-2. Lending   

- Lending · DEX = Protocol ์ฝ”์ธ๋“ค๊ณผ ์—ฐ๊ด€์„ฑ์ด ๊นŠ์ง€๋Š” ์•Š์Œ, ๋ณ„๋„์˜ ์„œ๋น„์Šค   

- ํŠน์ • ํ† ํฐ์„ ์˜ˆ์น˜(Deposit)ํ•˜๋ฉด ๋‹ค๋ฅธ ํ† ํฐ์„ ๋นŒ๋ฆด(Borrow)์ˆ˜ ์žˆ์Œ like ์€ํ–‰  

- 10 ETH ์˜ˆ์น˜ํ•˜๊ณ  1000 USDC ๋นŒ๋ฆผ / Deposit์— ๋Œ€ํ•œ ์ด์ž๋Š” ์–ผ๋งˆ๋‚˜ ๋งŽ์ด ๋นŒ๋ ค๊ฐ”๋Š”์ง€์— ๋”ฐ๋ผ ๋ณ€๋™  

 

* AAVE – borrow ์ด์ž์œจ๊ณผ supply ์ด์ž์œจ์˜ ์ฐจ์ด๊ฐ€ ์•„๋ฒ ์˜ ์ˆ˜์ต๋ฅ ์ด ๋จ (์€ํ–‰ ๊ฐœ๋…)   

- ๊ณผ๋‹ด๋ณด๋Œ€์ถœ (Overcollateralization)  

- ๋Œ€์ถœ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋Œ€์ถœ๋ฐ›์„ ๊ฐ€์น˜๋ณด๋‹ค ๋” ๋†’์€ ๊ฐ€์น˜์˜ ์˜ˆ์น˜(Deposit)ํ•ด์•ผ ํ•จ (๋‹ด๋ณด๋ณด๋‹ค ์ ์€ ๋ˆ)  

- $100๊ฐ€์น˜์˜ ETH ์˜ˆ์น˜ -> $70์˜ USDT ๋นŒ๋ฆผ๊ฐ€๋Šฅ / ๋Œ€์ถœ๋ฐ›์€ ๊ฐ€์น˜ > ์˜ˆ์น˜๊ฐ€์น˜ ํ•˜๋ฝ -> ์ฒญ์‚ฐ๋ฐœ์ƒ   

- $100๊ฐ€์น˜์˜ ETH๊ฐ€ ํ† ํฐ ๊ฐ€๊ฒฉ ํ•˜๋ฝ์— ์˜ํ•ด $70 ๊ฐ€์น˜๊ฐ€ ๋˜๋ฉด ์ฒญ์‚ฐ์ด ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋‹ค. (์กฐ์ž‘ ๊ฐ€๋Šฅ)  

 

- ํ”Œ๋ž˜์‹œ ๋ก (Flash Loan)  

- ๋‹ด๋ณด ์—†์ด ๋Œ€์ถœ์„ ์‹คํ–‰ํ•˜๋˜, ํ•œ ํŠธ๋žœ์žญ์…˜ ๋‚ด์—์„œ ๋Œ€์ถœ์ƒํ™˜์ด ์™„๋ฃŒ๋˜์–ด์•ผ ํ•จ  

- ํ”Œ๋ž˜์‹œ ๋ก  ๊ณต๊ฒฉ์— ์˜ํ•œ ํ•ดํ‚น ์‚ฌ๋ก€ ์ฃผ์˜ ํ•„์š”   

 

* Compound (like AAVE)   

- cToken - ๋‹ด๋ณด ํ† ํฐ๋ณ„๋กœ ์ƒ์„ฑ๋˜๋Š” ์ปจํŠธ๋ž™ํŠธ / ๋‹ด๋ณด ํ† ํฐ์„ ์˜ˆ์น˜ํ•˜๋ฉด ๋น„์œจ์— ๋งž๊ฒŒ cToken ๋ฐœํ–‰  

- mint/redeem/borrow/repay/liquidate / ERC-20 ๊ธฐ๋ฐ˜ ํ† ํฐ ํ‘œ์ค€ ์‚ฌ์šฉ, ๋‹ค๋ฅธ DeFi์„œ ๋‹ค์‹œ ์ด์šฉ ๊ฐ€๋Šฅ  

- ๊ณผ๋‹ด๋ณด๋Œ€์ถœ - cToken์˜ ๊ณ„์ขŒ ์œ ๋™์„ฑ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋Œ€์ถœ ๊ฐ€๋Šฅํ•œ ์ž์‚ฐ์„ ํ™•์ธ  

- ๋ฏธ๋ฆฌ ์„ค์ •๋œ ๋Œ€์ถœํ•œ๋„๋ณด๋‹ค ์ž‘์„ ๊ฒฝ์šฐ์—๋งŒ ๋Œ€์ถœ ์‹คํ–‰  

 

* MakerDAO  

- DAI – MakerDAO์—์„œ ๋ฐœํ–‰ํ•˜๋Š” 1๋‹ฌ๋Ÿฌ์˜ ๊ฐ€์น˜๋ฅผ ์œ ์ง€ํ•˜๋Š” ํ† ํฐ   

- ETH๋‚˜ ๋‹ค๋ฅธ ํ† ํฐ๋“ค์„ ๋‹ด๋ณด๋กœ ๋ฐœํ–‰๋จ / ๋‹ด๋ณด์˜ ๊ฐ€์น˜๊ฐ€ ๋ถ€์กฑํ•ด์งˆ ๊ฒฝ์šฐ ์ฒญ์‚ฐ๋จ   

- MKR - ๊ฑฐ๋ฒ„๋„Œ์Šค ํ† ํฐ   

- ์–ด๋–ค ๋‹ด๋ณด๋ฌผ๋“ค์„ ์ธ์ •ํ•  ์ง€, ๋‹ด๋ณด ๋น„์œจ ๋“ฑ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ ์กฐ์ ˆ์— ์‚ฌ์šฉ / ์ˆ˜์ˆ˜๋ฃŒ์™€ ๋ฒŒ๊ธˆ์— ์‚ฌ์šฉ    

 

3-3. DEX  

- ๊ฑฐ๋ž˜์†Œ: CEX (like upbit) vs DEX (ํƒˆ์ค‘์•™ ๊ฑฐ๋ž˜์†Œ)   

- Decentralized Exchanges   

- ์˜ค๋” ๋ถ์„ ์ฑ„์šธ ๋•Œ๋งˆ๋‹ค ํŠธ๋žœ์žญ์…˜์„ ๋งŒ๋“ค๊ธฐ ํž˜๋“ฆ : ํŠธ๋žœ์žญ์…˜ ์ˆ˜์ˆ˜๋ฃŒ, ํŠธ๋žœ์žญ์…˜ ์‹คํ–‰์‹œ๊ฐ„  

- ํƒˆ์ค‘์•™ํ™” ๊ฑฐ๋ž˜์†Œ๋Š” ๋‹ค๋ฅธ ํ˜•ํƒœ์˜ ๊ตฌํ˜„์ด ํ•„์š” / DB๊ฐ€ ๋ธ”๋ก์ฒด์ธ์ด๊ธฐ ๋•Œ๋ฌธ์—!  

 

* Uniswap V2              

* IL = ๋น„์˜๊ตฌ์  ์†์‹ค / ํ† ํฐ ๋ณด์œ  ๋Œ€๋น„ ์†์‹ค = LP(์œ ๋™์„ฑ ํ’€์— ๋ˆ์„ ๋„ฃ์€ ์‚ฌ๋žŒ)๊ฐ€ ์ž…๋Š” ์†ํ•ด   

* Uniswap (DEX) : CEX ์˜ค๋”๋ถ ๋Œ€์‹ , Liquidity Pool์— ์ฝ”์ธ์„ ๋„ฃ์–ด๋‘๊ณ , ์ˆ˜ํ•™ ๊ณต์‹ ์ž๋™ ๊ฐ€๊ฒฉ ๊ฒฐ์ •   

- ์œ ๋™์„ฑ K๋Š” ์ผ์ •, ์œ ๋™์„ฑ ํ’€์— ๋„ฃ์—ˆ๋‹ค = ๋งค์ˆ˜/๋งค๋„ ๋ฐœ์ƒ  

- V2 : ๋ชจ๋“  ๊ฐ€๊ฒฉ ๊ตฌ๊ฐ„์— ์–‡๊ฒŒ ์œ ๋™์„ฑ ์ œ๊ณต, LP ์ž์‚ฐ์ด ๊ฑฐ์˜ ์•ˆ ์“ฐ์ด๋Š” ๊ฐ€๊ฒฉ ๊ตฌ๊ฐ„์— ๋ฌถ์ž„  

- V3 : ํ•„์š”ํ•œ ๊ตฌ๊ฐ„๋งŒ ์œ ๋™์„ฑ ์ง‘์ค‘, ํšจ์œจ ์ฆ๊ฐ€, ์ˆ˜์ต ์ฆ๊ฐ€, ๊ฐ€๊ฒฉ์ด ๋ฒ”์œ„๋ฅผ ๋„˜์–ด๊ฐ€๋ฉด ๋น„ํ™œ์„ฑํ™” (์ˆ˜์ต 0)   

 

Uniswap V2

 

 

 

Uniswap V3

 

 

 

+ Slippage : ํ’€์— ๋ˆ(์œ ๋™์„ฑ)์ด ์ ์œผ๋ฉด, ์กฐ๊ธˆ๋งŒ ๋ฐ”๋€Œ์–ด๋„ ๊ฐ€๊ฒฉ ๋ณ€๋™ ์‹ฌํ•ด์„œ ์†ํ•ด ๋ฐœ์ƒ, ๊ฑฐ๋ž˜ ๋ถˆ์•ˆ์ •  

- V3: ํŠน์ • ๊ตฌ๊ฐ„์—๋งŒ ๋ˆ์„ ๋ชฐ์•„ ๋„ฃ์œผ๋ฉด, ํ•ด๋‹น ๊ตฌ์—ญ์˜ ์œ ๋™์„ฑ ์ปค์ง -> slippage ๊ฐœ์„   

- but IL ์ฆ๊ฐ€ ๊ฐ€๋Šฅ : LP ๊ตฌ๊ฐ„์„ ๋‚˜๊ฐ€๋ฉด, (ETH 2000 ๋„๋‹ฌ -> USDT๋งŒ ๊ฐ–๊ฒŒ ๋จ, ๋” ์˜ฌ๋ผ๋„ ๊ณ„์† ๋†“์นจ)   

- V2์— ๋‚˜์˜จ ํ”„๋กœํ† ์ฝœ, V3์—์„œ๋Š” ํฐ ์˜๋ฏธ X  : ์ข์€ ๊ณต๊ฐ„์— ์œ ๋™์„ฑ์„ ๊น”๋ฉด ๋˜๋‹ˆ๊น   

- Curve : ์Šคํ…Œ์ด๋ธ”์ฝ”์ธ ๊ฐ„ ์Šค์™‘ ์‹œ, ์Šฌ๋ฆฌํ”ผ์ง€ ๊ฑฐ์˜ X  

- 3๊ฐœ์˜ component ์„œ๋กœ ์ƒํ˜ธ๋ณด์™„์   : Staking, Lending, DEX   

 

3-4. Advanced  

* DEX Aggregator = ์—ฌ๋Ÿฌ DEX์— ๋‚˜๋ˆ ์„œ swap์š”์ฒญ ๋ณด๋‚ด๋ฉด slippage ์ตœ์†Œํ™” ๊ฐ€๋Šฅ  

- ์—ฌ๋Ÿฌ DEX์—์„œ ์Šค์™‘ ๊ฐ€๋Šฅํ•œ ํ† ํฐ์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋ฅผ ๋ชจ์•„์„œ ํ•œ ๊ตฐ๋ฐ์„œ ์Šค์™‘ ๊ฐ€๋Šฅ  

- ํ•˜๋‚˜์˜ DEX๋งŒ ์‚ฌ์šฉํ•˜๋”๋ผ๋„ routing(pool)์„ ์—ฌ๋Ÿฌ ๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด slippage ์ตœ์†Œํ™” ๊ฐ€๋Šฅ  

- ์ตœ๊ทผ์—๋Š” ์—ฌ๋Ÿฌ ์ฒด์ธ์„ ๊ฑฐ์น˜๋Š” cross-chain aggregator๋„ ์กด์žฌ  

 

* Pandle – Yield Tokenization : ์ „ํ†ต ๊ธˆ์œต์ด ๋ธ”๋ก์ฒด์ธ De-fi ์˜ฌ๋ผ์˜ค๋ ค๊ณ  ํ•จ  

- ์ด์ž ํ† ํฐ๊ณผ ์›๊ธˆ ํ† ํฐ์œผ๋กœ ๋ถ„๋ฆฌ (Principal Token ์›๊ธˆ + Yield Token ์ด์ž)  

- ETH → stETH (์ด์ž + ์›๊ธˆ) → SY-stETH → PT-stETH (์›๊ธˆ) + YT-stETH (์ด์ž)   

 

* Summary   

1. Staking : ๋„คํŠธ์›Œํฌ์˜ ๋ณด์•ˆ์— ๊ธฐ์—ฌ / ์ด์ž๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ์Œ / ์ค‘์š” ์˜์‚ฌ๊ฒฐ์ •์— ํˆฌํ‘œํ•  ์ˆ˜ ์žˆ์Œ  

- LST๋ฅผ ํ†ตํ•ด ๋‹ค์‹œ DeFi๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Œ  

2. Lending : DeFi์˜ ์€ํ–‰ / ์˜ˆ๊ธˆ · ๋Œ€์ถœ์„ ํ†ตํ•œ ๋ ˆ๋ฒ„๋ฆฌ์ง€ / ๊ณผ๋‹ด๋ณด๋Œ€์ถœ / ํ”Œ๋ž˜์‹œ๋ก   

3. DEX : Uniswap V2 - CPMM, ์Šฌ๋ฆฌํ”ผ์ง€(Slippage), ๋น„์˜๊ตฌ์  ์†์‹ค(Impermanent Loss)  

- Uniswap V3 - ์ง‘์ค‘ํ™”๋œ ์œ ๋™์„ฑ(Concentrated Liquidity)   

- Curve StableSwap - ๊ฐ€์น˜๋ณ€๋™์„ฑ์ด ์ ์€ ํ† ํฐ์˜ slippage ์ตœ์ ํ™”   

4. Advanced : DEX aggregator ํ†ตํ•œ swap ๋น„์šฉ ์ตœ์ ํ™”   

: ํ•˜๋‚˜๋งŒ ์‚ฌ์šฉํ•˜๋ฉด slippage ์ฆ๊ฐ€ ๊ฐ€๋Šฅ, ๋ชจ๋“  ๊ฑฐ๋ž˜๊ฐ€ ํ•œ ๊ณณ์— ๋ชฐ๋ฆฌ์ง€ X (DEX ๋ณ„ ํ† ํฐ ์œ ๋™์„ฑ ๋‹ค๋ฆ„)  

- Bridge-DEX aggregator ํ†ตํ•œ multichain swap ๋น„์šฉ ์ตœ์ ํ™”   

- Pendle - ์ด์ž์™€ ์›๊ธˆ์„ ๋ถ„๋ฆฌํ•˜์—ฌ ๋ณ„๋„์˜ ํ† ํฐ์œผ๋กœ DeFi ์ด์šฉ    

 

 

 

4. Blockchain Service Development  

- Web 1.0 : ๋‹จ๋ฐฉํ–ฅ, ์ง‘์— ์žˆ๋Š” PC(HW)  

- Web 2.0 : ์–‘๋ฐฉํ–ฅ, ํŽ˜์ด์Šค๋ถ(SNS),  ๊ฐœ์ธํ™”๋œ ์ปจํ…์ธ  ํ™˜๊ฒฝ, ์‹ค์‹œ๊ฐ„ ์ •๋ณด ๊ตํ™˜  

- Web 3.0 : ๋‚ด ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์ฃผ๊ถŒ,   ๋ธ”๋ก์ฒด์ธ, ์ •๋ณด๋ฅผ ๋„˜์–ด์„  ๊ฐ€์น˜ ๊ตํ™˜ 

 + 2.0์— ์ถ”๊ฐ€๋œ features -> 3.0    

 

Web3.0

 

- Web 2.0 = ํ”„๋ก ํŠธ + ๋ฐฑ์—”๋“œ ๋‚˜๋‰จ - ํฐ ํ‹€์—์„œ ๊ฐ„๋‹จํ•œ components   

- Web 3.0 = ๋ธ”๋ก์ฒด์ธ์€ ๋” ํ•„์š” O  = Smart Contract / Wallet   + Endpoint Node / Indexer / Oracle  

+ ๋ธ”๋ก์ฒด์ธ ๋„คํŠธ์›Œํฌ ์ž์ฒด๊ฐ€ ๋ฐ”๋กœ ์ œ๊ณตํ•  ์ˆ˜ ์—†๋Š” ๋ฐ์ดํ„ฐ๋“ค = indexer    

 

1. Frontend   

- Development process is similar to normal Web2 (HTML5/css/javascript/react/vue /flutter)  

- The differences : (์–ด๋–ป๊ฒŒ ๋ธ”๋ก์ฒด์ธ ๊ธฐ์ˆ ๋“ค๊ณผ ์ƒํ˜ธ์ž‘์šฉ ํ•  ์ง€ ๊ณ ๋ฏผ ํ•„์š”)     

- Wallet / Web3 SDK / RPC request to Blockchain nodes / Blockchain Indexed data   

 

2. Backend  

- When designing API/DB schema, need to consider how to interact with blockchain data   

- Sometimes, need to listen to the changes of blockchain data / Then, put the changes into DB   

 

3. Smart Contract   

- A program deployed on a blockchain network   

- This program can be executed only via submitting a transaction   

- Anyone can see the change / The change cannot be rolled back (immutable ํŠน์„ฑ)  

 

4. Oracle   

- Data outside of the chain can be brought into blockchain   

- Typical data = Price feed / Verifiable Random Function to verify lottery-like games   

: ์˜จ์ฒด์ธ ๋ฐ์ดํ„ฐ ์กฐ์ž‘์€ ์ƒ๋Œ€์ ์œผ๋กœ ์‰ฌ์›€, ๋ฐ”์ด๋‚ธ์Šค(CEX, ์™ธ๋ถ€ ๊ฐ€๊ฒฉ์„ ์˜๋ฏธ)๋Š” ๊ฐ€๊ฒฉ ์กฐ์ž‘ ๊ฑฐ์˜ ๋ถˆ๊ฐ€๋Šฅ   

 

5. Wallet   

- One of the important components in Web3 industry (like ์ธํ„ฐ๋„ท ๋ธŒ๋ผ์šฐ์ € ์—ญํ• )  

- Tx is signed by the wallet   

1. Custodial wallet - Private key is owned by the service   

- Service can manage the funds of the users / Needs to be regulated  

2. non-custodial wallet - Private key is owned by the user (์‚ฌ์šฉ์ž ์ž์‹ ์ด ํ‚ค ๊ฐ€์ง, ๋ณต๊ตฌ๋ถˆ๊ฐ€)   

- Service cannot manage the funds of the users / Irrecoverable if the user lost his private key  

 

6. Endpoint Node  

- Full node of a blockchain network / entrypoint to read/write the blockchain data  

- The node can be managed by : Each service / Endpoint node service providers   

- Some of the service names (Ankr, pokt.network, All that node, Quicknode, etc.)  

 

7. Indexer   

- Blockchain node itself is insufficient to provide data to the service  

- It is inefficient for a node to produce an output of :    

the transaction history of an account / events generated by a contract  

- For this, indexer is needed (KAS, Etherscan API, Moralis, Alchemy, Covalent, Tatum, The graph)  

+ ๋ธ”๋ก์ฒด์ธ ๋…ธ๋“œ๋งŒ์˜ ์ •๋ณด๋กœ๋Š” ๋ถˆ์ถฉ๋ถ„, ๊ฑฐ๋ž˜ ๋‚ด์—ญ ์ถ”์  ๋“ฑ ์„œ๋น„์Šค๋ฅผ ์œ„ํ•œ ๋ณ„๋„์˜ indexer protocols       

 

 

 

5. Solidity  

- Smart Contract Language for Ethereum   

- Why new language? -> To make language constructs reflecting the blockchain system  

- Language for EVM (Ethereum Virtual Machine)        

 

 

 

- ์ผ๋ฐ˜ ์–ธ์–ด: ํ”„๋กœ๊ทธ๋žจ ์ž‘์„ฑ ์‹œ, CPU – MEM ๊ณ ๋ ค, ๊ธฐํƒ€ ์ฃผ๋ณ€ ๊ธฐ๊ธฐ – ์–ธ์–ด์—์„œ ํ™•์žฅ๋œ library ํ™œ์šฉ  

- ๋ธ”๋ก์ฒด์ธ – storage ํŠน์„ฑ๊นŒ์ง€ ์–ธ์–ด๊ฐ€ ๊ณ ๋ ค (์—ฌ๋Ÿฌ ๋Œ€์˜ ์žฅ๋น„๊ฐ€ ๋ชจ๋‘ ๋™์ผํ•œ ๊ตฌ์กฐ, ๊ทธ ์œ„์—์„œ ์ฝ”๋”ฉ)   

+ ํœ˜๋ฐœ์„ฑ X, A to B ์†ก๊ธˆ ๊ธฐ๋ก์ด ์‚ฌ๋ผ์ง€๋ฉด ์•ˆ๋˜๊ณ , ์ €์žฅ๋˜์–ด์•ผ ํ•จ -> ์Šคํ† ๋ฆฌ์ง€ ๊ณ ๋ ค ํ•„์š”   

 

- ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ or ํ‚ค๋ณด๋“œ ๋“ฑ ์ฃผ๋ณ€ ์žฅ์น˜ ์—ฐ๊ฒฐ control = ๋ธ”๋ก์ฒด์ธ์—์„œ๋Š” ๋ถˆ๊ฐ€๋Šฅํ•จ  

- f(x) = y / ๋ธ”๋ก์ฒด์ธ์—์„œ๋Š” old state ๋งŒ x์— ๋“ค์–ด๊ฐ. Input(N, K) ์ด๋Ÿฐ ๊ฑด ๋ชป ๋“ค์–ด๊ฐ   

 

* Blockchain Programming Environment   

- Smart Contract ์—ฌ๋Ÿฌ ์ปดํ“จํ„ฐ ์œ„์— ๊ฐ™์ด ์˜ฌ๋ผ๊ฐ€์„œ ๋™์ž‘ํ•ด์•ผ ํ•œ๋‹ค.  

- tx๋ฅผ ์–ด๋–ค ์ปดํ“จํ„ฐ์—์„œ ์‹คํ–‰ํ•˜๋“ , ์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” ๋™์ผํ•ด์•ผ ํ•จ -> ๊ทธ๋ž˜์•ผ consensus ํ•ฉ์˜ ๊ฐ€๋Šฅ  

- old state์— ์ƒˆ๋กœ์šด ์ธํ’‹ ๋“ค์–ด์˜ฌ ๋•Œ, new state๋Š” ์–ด๋–ค ์ปดํ“จํ„ฐ์—์„œ ์‹คํ–‰ํ•˜๋“  Tx ๊ฒฐ๊ณผ ๋™์ผํ•ด์•ผ ํ•จ  

 

- Outside of Blockchain data can’t be accessible -> ์™ธ๋ถ€์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋Š” ์ ‘๊ทผ X   

- ๋ฐ์ดํ„ฐ ์กฐ์ž‘์€ transaction์˜ ํ˜•ํƒœ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ์•ผ ํ•œ๋‹ค.   

 

 

 

 

* EVM : Ethereum Virtual Machine   

- ์‹คํ–‰ ํ™˜๊ฒฝ = computation <-> data   

- stack-based VM (๊ฐ€์ƒ๋จธ์‹ ์€ ๋Œ€๋ถ€๋ถ„ ์Šคํƒ ๊ธฐ๋ฐ˜) vs register-based (์ผ๋ฐ˜ HW, processor)      

 

- EVM : Stack-based VM / Word size: 256 bits = 32 B (x86 = 32, 64bit ๊ตฌ์กฐ๊ฐ€ ๋‹ค๋ฆ„)  

- Precompiled contracts: special & complicated instructions (ecrecover, SHA2-256, RIPEMD-160)  

- Gas is measured to pay the transaction fee / gas is calculated based on opcode and operand  

: ์—ฐ์‚ฐ๋งˆ๋‹ค gas ์‚ฌ์šฉ์ด ์ฆ๊ฐ€ํ•จ (gas table)  

 

* Data Types = Value Types / Reference Types / Mapping Types  

1. Value Type – ํ•˜๋‚˜์˜ ๊ฐ’์„ ๊ฐ–๊ณ  ๊ฐ€๋Š” ๊ฒƒ (word 1 size = copy ๊ฐ€๋Šฅ)   

* integer (= int 256, **EXP) + overflow, underflow (์ž”๊ณ  ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ ๋˜๋ฉด, 10์–ต ์ด์ƒ ๋‚ ์•„๊ฐ)  

: ์›๋ž˜๋Š” just wraps, safe math ๋“ฑ์„ ์‚ฌ์šฉ -> solidity 0.8.0๋ถ€ํ„ฐ tx revert ๋จ   

- floating point ์‚ฌ์šฉ X / Fixed point number -> int + decimal ์ด๋ ‡๊ฒŒ ํ‘œํ˜„ํ•จ   

 

* Address (20 byte) / Address Payable (์‹ค์งˆ์ ์œผ๋กœ ๋ˆ์„ ๋ณด๋‚ด๋Š” ์ฃผ์†Œ)   

- payable -> address : implicit conversion is allowed   

- address -> payable : To convert, payable(<address>) is required  

- other types -> address : Explicitly convertible from uint160, integer literals, bytes20, contract  

- other types -> payable : only address and contract are allowed  

 

- Members  

- balance (ETH ์ž”๊ณ , read native coin balance of the account)  

- transfer : revert if (not enough balance, rejected from the recipient account)   

ex) x.transfer(10) -> x์— ์ž”๊ณ ๊ฐ€ 10๋งŒํผ ์—†๋‹ค๋ฉด -> ํŠธ๋žœ์žญ์…˜ ์‹คํŒจ   

+ Tansfer๋Š” ์‹คํŒจํ•˜๋ฉด Revert, send๋Š” ์‹คํŒจํ•˜๋”๋ผ๋„ false return (๋‹ค๋ฅธ ๋™์ž‘ ๊ตฌํ˜„ ๊ฐ€๋Šฅ)  

 

- Send : low level counterpart of transfer  

- returns false if the execution fails   

- call, delegatecall, staticcall : low level interface, interact with other contracts   

- input parameter should be encoded by using abi.encodeWithSignature   

- gas and value can be manually set   <- call์— ๋ณด๋‚ผ ๊ฐ€์Šค๋ž‘ ์ด๋”๋ฅผ ์ •์˜   

 

- storage ๋ณ€๊ฒฝ ๊ถŒํ•œ call, delegate ๋‘˜ ๋‹ค ๊ฐ€๋Šฅํ•œ๋ฐ ์ฃผ์ฒด๊ฐ€ ๋‹ค๋ฆ„ (B์—์„œ A( )์˜ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ ์‹œํ‚ด)  

- call (B read/write), static(B read only), delegate (A read/write – A์˜ ์Šคํ† ๋ฆฌ์ง€๋ฅผ ๋ณ€๊ฒฝํ•จ)  

- ๋‚˜๋จธ์ง€ ๋‘˜์€ ํ˜ธ์ถœํ•œ ์• ๊ฐ€ A / delegate = B์— ์žˆ๋Š” ์ฝ”๋“œ๋กœ A์˜ ์Šคํ† ๋ฆฌ์ง€์— ์ ‘๊ทผํ•œ ๊ฒƒ   

 

- contract ๋ฐฐํฌํ•˜๋ฉด ์ˆ˜์ • ๋ถˆ๊ฐ€๋Šฅ -> upgradable ๊ฐœ๋… (by delegate call)   

- context๋Š” A(์›๋ณธ๋ฐ์ดํ„ฐ, storage)๋ฅผ ์‚ฌ์šฉ, implementation์€ ๊ณ„์† ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๊ฒŒ (B -> C -> D ๋“ฑ)  

- ์‹ค์ œ๋กœ A์—์„œ B๋กœ ๋ˆ์„ ๋ณด๋‚ผ ์ˆœ X (delegate: value X) – ๋ชจ๋“  state์— ๋Œ€ํ•œ context ๋Š” A์— ์žˆ์Œ   

 

- code : get the code of a contract  

- codehash : get the code hash of a contract (To check whether the address is contract or not)  

: contract๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด, hash ๊ฐ’์ด nil์ด ๋‚˜์˜ค๊ฒŒ ๋จ (์ฃผ์†Œ๊ฐ€ contract or EOA์ธ์ง€ ์•Œ ์ˆ˜ ์žˆ์Œ)    

 

* Contract   

- User-defined type / Represents a deployed smart contract / Can deploy a contract runtime  

- Explicitly converted from address / Accessible members (Functions/variables declared as public)  

 

* User-defined Value Types (type C is V)   

- C is a new user-defined type / V has to be a built-in value type  

- C.wrap() and C.unwrap() are the only operators defined implicitly   

-> stateMath ๊ตฌํ˜„ ๊ฐ€๋Šฅ (์˜ค๋ฒ„ํ”Œ๋กœ์šฐ ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ฒดํฌ)  

 

* Function Types   

- function (<parameter types>) {internal|external} [pure|view|payable] [returns <return types>)]

- conversion between functype A and B allowed if and only if   

: parameter types are identical / return types are identical / internal/external property is identical  

 

- state mutability of A is more restrictive than B   

: pure => view and non-payable / view => non-payable / payable => non-payable  

- Pure๋Š” ํ•จ์ˆ˜ ๋‚ด member ๋ณ€์ˆ˜ ์ ‘๊ทผ X, only params๋งŒ ์‚ฌ์šฉ  

- View๋Š” ๋ฉค๋ฒ„ ์ ‘๊ทผ O, read only / pure view๋„ ์•„๋‹Œ ์ผ๋ฐ˜ ํ•จ์ˆ˜๋Š” ๋ฉค๋ฒ„ ์ ‘๊ทผ O, ์ˆ˜์ •๋„ ๊ฐ€๋Šฅ  

 

- Member   

- .address : the address of the contract of the function  

- .selector : ABI function selector (func์ด๋ฆ„ + parameter ์ „์ฒด๋ฅผ string์œผ๋กœ hash, 32B ์ค‘ ์•ž์˜ 4B)     

 

2. Reference Type – copy ํ•˜๊ธฐ์— ํฐ ๊ฐ’๋“ค, ref ์ง€์นญ (structs, arrays, and mappings Data Location)  

1. memory : stored in memory / lifetime is limited to a function call   

2. storage : stored in the contract storage / lifetime is limited to the lifetime of the contract  

3. calldata : special data location for function call / read-only, non-persistent (ํœ˜๋ฐœ์„ฑ)  

- lifetime is limited to a function call   

+ ๋‚ด๊ฐ€ pointing ํ•˜๋Š”๊ฒŒ ๋ฉ”๋ชจ๋ฆฌ๋ฉด ๋ฐ”๋กœ ์“ฐ๋Š”๋ฐ, ์Šคํ† ๋ฆฌ์ง€๋ฉด ๋ถˆ๋Ÿฌ์™€์•ผ ํ•จ, ๋‘ ๊ณต๊ฐ„ ๋ถ„๋ฆฌ   

- ์Šคํ† ๋ฆฌ์ง€์™€ ๋ฉ”๋ชจ๋ฆฌ ๊ฐ„ ์ด๋™ = gas ์†Œ๋ชจ, ์ข‹์€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์•„๋‹˜   

 

- Assignment between storage and memory = always create an independent copy  

- Assignment from memory to memory = only create references, changes will be visible in both  

- Assignment from storage to a local storage variable = create a reference  

- Other assignments to storage = always copy   

 

- func ๋ฐ”๊นฅ์— ์žˆ๋‹ค๋ฉด? = Storage, ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋ฐ”๊นฅ์— ์ •์˜๋œ ๋ณ€์ˆ˜ x์— ํ• ๋‹นํ•˜๋ ค๋ฉด, ์ „๋ถ€ copy ํ•ด์•ผํ•จ  

- ๋ฉ”๋ชจ๋ฆฌ์ธ๊ฐ€ ์Šคํ† ๋ฆฌ์ง€์ธ๊ฐ€์— ๋”ฐ๋ผ, ๋ณต์‚ฌ๊ฐ€ ๋  ์ง€, ref๋งŒ ๊ฐ€์ ธ๊ฐˆ ์ง€๊ฐ€ ๊ฒฐ์ •๋จ  

- dynamic size์˜ storage array๋Š” push๋กœ ๊ณ„์† ๋Š˜๋ ค๋‚˜๊ฐˆ ์ˆ˜ ์žˆ๋Š”๋ฐ, memory array๋Š” ๋Š˜๋ฆด ์ˆ˜ X    

 

* Array  

- Compile-time fixed size (uint[5])  or runtime dynamic size (uint[])   

- .push() : initialized with zero and returns the reference   

- .push(value) : appends ‘value’ to the end of array   

- bytes.concat and string.concat   : concatenation of bytes or strings  

 

* Allocating memory arrays   

- using new   

- Unlike storage arrays, .push() is not allowed. impossible to resize  

 

- Members - length : number of elements / push() : Allowed for dynamic storage arrays   

- Append zero-initialized element to the end / Returns the reference / e.g., x.push() = 2;   

- push(x) :  append x to the end / e.g., x.push(2);  

- pop() remove the last element / returns nothing (push ์—ฐ์ด์–ด ํ˜ธ์ถœ X)  

 

* Structure   - User-defined types / Cannot contain itself  

- struct { uint8, uint, uint8 }  vs  struct { uint8, uint8, uint } = packing ์ฐจ์ด  

- ์ฒซ๋ฒˆ์งธ๋Š” ์›Œ๋“œ 1๊ฐœ 1๊ฐœ 1๊ฐœ, ์ด 3๊ฐœ (32B * 3) / ๋‘๋ฒˆ์งธ๋Š” ์•ž์˜ ๋‘˜์„ ์›Œ๋“œ 1๊ฐœ, ์›Œ๋“œ 1๊ฐœ (32B * 2)     

 

3. Mapping Type   

- KeyType = any built-in value type, bytes, string, contract, or enum   

- ValueType = any type   - KeyName, ValueName = optional     

* key data is not stored, keccak256(key) is used for lookup : ๋งคํ•‘์˜ ์ „์ฒด ๊ธธ์ด ์ด๋Ÿฐ๊ฑฐ ๋ถˆ๊ฐ€๋Šฅ     

 

* Layout of a Solidity Source File   

- SPDX License Identifier : SPDX (System Package Data Exchange) / MIT, GPL-3.0, Apache-2.0   

- pragma: ์–ด๋–ค ์ปดํŒŒ์ผ๋Ÿฌ ๋ฒ„์ „ ์ด์ƒ๋ถ€ํ„ฐ, ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ œ๋Œ€๋กœ ๋Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค๋Š” ๋ช…์‹œ   

+ ABI Coder (Application Binary Interface) = v1 or v2  

 

- Importing other files : import “filename”; // ๋‹ค๋ฅธ smart contract import ํ•ด์˜ฌ ์ˆ˜ ์žˆ์Œ   

- import "@klaytn/contracts/KIP/token/KIP7/KIP7.sol";  

 

* Constructor ๋ถˆ๋ฆฌ๋Š” ์‹œ์  = ๋ธ”๋ก์ฒด์ธ์˜ ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ๊ฐ€ ๋ฐฐํฌ๋˜๋Š” ์‹œ์    

- ์›๋ž˜ class์˜ constructor๋Š” object instantiation (๊ทธ๋•Œ ์ƒ์„ฑ์ž๊ฐ€ ๋ถˆ๋ฆผ)  

- ๋ธ”๋ก์ฒด์ธ์—์„œ๋Š” ์ฝ”๋“œ๊ฐ€ ์‹ค์ œ๋กœ deploy๊ฐ€ ๋˜์—ˆ์„ ๋•Œ, ๋ธ”๋ก์ฒด์ธ ์ƒ์— ์˜ฌ๋ผ์˜ฌ ๋•Œ, Constructor๊ฐ€ ๋ถˆ๋ฆผ  

- Only one constructor is allowed /Constructor arguments should be passed when deploying  

 

* State Variable Visibility   

1. public : Automatically generates getter functions for public variables

- The value is accessible via getter function   

2. internal : Can only be accessed within the contract / Default visibility level   

- inaccessible to derived contracts   

3. private : same as internal / Not visible in derived contracts        

 

- pure๋Š” params ๋ฐ›์€ ๊ฒƒ๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅ / ๋ฉค๋ฒ„๋ณ€์ˆ˜ ์ ‘๊ทผํ•˜์ง€ ์•Š๋Š” ํ•จ์ˆ˜ = ์ปดํŒŒ์ผ๋Ÿฌ ์ตœ์ ํ™” ๊ฐ€๋Šฅ  

- E๊ฐ€ C๋ฅผ ์ƒ์† -> compute ์ ‘๊ทผ ๊ฐ€๋Šฅ   

 

* Function Modifiers   

- Mostly used to check conditions prior to execution of a function : ํ•จ์ˆ˜ ์‹คํ–‰ ์ „, ์ฒดํฌ์— ํ™œ์šฉ  

- Can be overridden if it has virtual   

- Multiple modifiers = whitespace-separated list  = ์—ฌ๋Ÿฌ ๊ฐœ ํ˜ธ์ถœ ์‹œ ๋นˆ ์นธ์œผ๋กœ ๋ถ„๋ฆฌ   

- ‘_’ placeholder = used to denote where the function should be inserted   

=  _ ์ด ์œ„์น˜์—์„œ ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋จ  

 

* Function Modifiers   

- if ๊ตฌ๋ฌธ ์ถฉ์กฑํ•  ๋•Œ์—๋งŒ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•จ, _ ์—†์œผ๋ฉด function ์‹คํ–‰ ์•ˆ๋  ์ˆ˜ ์žˆ์Œ  

modifier checkSomething() { = ํ•จ์ˆ˜ ํ˜ธ์ถœ ์ „/ํ›„์— ์ถ”๊ฐ€ ๋กœ์ง์„ ์‹คํ–‰ํ•˜๋„๋ก ํ•˜๋Š” ๋ฌธ๋ฒ• (๋ฏธ๋“ค์›จ์–ด)      

    // ํ•จ์ˆ˜ ์‹คํ–‰ ์ „์— ์‹คํ–‰๋  ์ฝ”๋“œ      

    doCheck();     

    _ ;  // ← ์—ฌ๊ธฐ์„œ ์›๋ž˜ ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋จ = modifier ๋‚ด๋ถ€์—์„œ ์—ฌ๊ธฐ ์›๋ž˜ ํ•จ์ˆ˜ ์‹คํ–‰ํ•ด๋ผ๋Š” ์œ„์น˜ ํ‘œ์‹œ      

    // ํ•จ์ˆ˜ ์‹คํ–‰ ํ›„์— ์‹คํ–‰๋  ์ฝ”๋“œ      

    doAfter();

}          

 

- constant = ๊ณ ์ • ๊ฐ’ (์ปดํŒŒ์ผ ํƒ€์ž„)  

- immutable = ์ƒ์„ฑ์ž ์•ˆ์—์„œ๋งŒ(์ดˆ๊ธฐ ๋ฐฐํฌ) ์—…๋ฐ์ดํŠธ ๊ฐ€๋Šฅ, ๋‹ค๋ฅธ ๊ณณ์€ read๋งŒ ๊ฐ€๋Šฅ   

- ์‹ค์ œ contract ๊ฐ€ ๋ธ”๋ก์ฒด์ธ ์ƒ์— ๋ฐฐํฌ๊ฐ€ ๋  ๋•Œ ๊ฒฐ์ •๋˜๋Š” ๊ฐ’ ์˜๋ฏธ    

 

* receive  

- External = ์™ธ๋ถ€์—์„œ ํ˜ธ์ถœ ๊ฐ€๋Šฅํ•œ ํ•จ์ˆ˜ / payable = ์ด ์ปจํŠธ๋ž™ํŠธ๊ฐ€ ETH๋ฅผ ์ด ํ•จ์ˆ˜ ํ†ตํ•ด ๋ฐ›์„ ๊ฑฐ์•ผ.   

- ๋ˆ„๊ฐ€ ๋‚˜์—๊ฒŒ ๋ณด๋ƒˆ๋‹ˆ? Or ์–ผ๋งˆ๋งŒํผ ๋ณด๋ƒˆ๋‹ˆ?   

 

* fallback   

- ์˜ˆ์ƒํ•˜์ง€ ๋ชปํ•œ ํ˜ธ์ถœ์„ ๋ฐ›์„ ๋•Œ, ์‹คํ–‰๋˜๋Š” ์˜ˆ๋น„ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜

-> ์…‹ ๋‹ค ๋งž์ง€ ์•Š์•„ -> fallback ํ˜ธ์ถœ     

 

* Events   

- Logging functionality of contracts   

- Applications can subscribe and listen events   

- Add the attributed indexed : up to three parameters  : shown as “topics” of the events  

 

- ์ง€๊ฐ‘์ด ๊ณ„์† ๋ชจ๋“  ์ฃผ์†Œ์— ๋Œ€ํ•ด call ํ˜ธ์ถœ X -> ๋ณ€๊ฒฝ ์‹œ์ ์— ์„œ๋น„์Šค๋กœ ์ •๋ณด ๋˜์ ธ์ค€๋‹ค๋ฉด ์ข‹์Œ         

- block explorer = ๊ทธ๋ƒฅ ์„œ๋ฒ„์—์„œ DB๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ (์‚ฌ์šฉ์ž๊ฐ€ ๋ณด๊ธฐ ์‰ฝ๊ฒŒ) : etherscan, tx ์ •๋ณด ํ™•์ธ  

 

* Inheritance : ์ƒ์†      

- base 1 or 2?   * Units and Globally Available Variables   

- Ether unit = ์ œ์ผ ์ž‘์€ ๋‹จ์œ„๊ฐ€ wei (1)   

- ๋น„ํŠธ์ฝ”์ธ = ์‚ฌํ† ์‹œ / 1 ether ๋กœ ์จ์•ผํ•จ