개발 공부

18.07.14 알기 쉬운 코어 이더리움 _ 2. 이더리움의 작동원리 본문

교육

18.07.14 알기 쉬운 코어 이더리움 _ 2. 이더리움의 작동원리

아이셩짱셩 2018. 7. 18. 15:35

알기 쉬운 코어 이더리움


- 일시 : 2018.07.14(토) 10시~ 13시
- 장소 : 동성빌딩 11층 (본사건물)
- 주제 : 알기쉬운 코어 이더리움 
- 강사 : 박재현소장님(두나무 람다 256 블록체인 연구소 소장)


1. 암호화폐와 블럭체인

2. 이더리움 플랫폼 작동 원리

3. 블록체인 이코노미

4. 기업에서 블록체인 활용

5. 이더리움의 현재와 미래




2. 이더리움의 작동원리

* 이더리움

-플랫폼 - 컨트랙 / 비중앙화앱 / 네트워크 배포 / 전용 브라우져


* 플랫폼 참조모델



-공통

-동의(census)

-실행

-데이터

-응용


#데이터 계층
* Single State transition Model
* Account
-Bit coin
-EOA(Externally Owned Account) <-> EOA

-Ethereum                            전자서명 불필요
-EOA -> Contract Account -------------------> CA
//소스 위치 : package state 
type Account struct { 
Nonce uint64                         //외부 트랜잭션의 갯수를 의미하며 0으로 시작,
//각 거래가 오직 한 번 만 처리되게 하는 일종의 카운터
Balance *big.Int                     //어카운트의 이더 잔고
Root common.Hash // merkle root of the storage trie     //trie 저장소의 루트
CodeHash []byte                     //스마트 컨트랙 코드가 저장 공간
}

*status
//소스 위치 : package state 
type stateObject struct { 
address common.Address // 어드레스 
addrHash common.Hash // 어카운트 주소의 Keccak256Hash hash of ethereum address of the account 
data Account // 이더리움 어카운트 
db *StateDB // 상태를 저장할 DBMS에 대한 포인터 

// Write caches. 
trie Trie // Trie 저장소 
code Code // 컨트렉의 바이트 코드 ……. 
}

*transaction
-Minor가 실행할 때 gas비를 태움
-Minor 보상 / Ddos 공격, civil attack 방지
type Transaction struct { 
data txdata 
// caches 
hash atomic.Value 
Size atomic.Value 
from atomic.Value 
}

type txdata struct { 
AccountNonce uint64     `json:"nonce" gencodec:"required"`        //외부 트랜잭션의 갯수를 의미하며 0으로 시작
Price *big.Int                 `json:"gasPrice" gencodec:"required"`     //계산 단계마다 발신처가 지불하는 수수료
GasLimit *big.Int            `json:"gas" gencodec:"required"`           //거래가 실행 시 수행되도록 허용된 최대 트랜젝션 수행 횟수
Recipient *common.Address    `json:"to" rlp:"nil"` // nil means contract creation    //거래를 받을 수신처
Amount *big.Int             `json:"value" gencodec:"required"`         //발신처가 수신처로 보내는 이더의 양
Payload []byte               `json:"input" gencodec:"required"` // This is only used when marshaling to JSON. 
    //옵션으로 임의의 메세지, 함수호출, 계약 생성코드
Hash *common.Hash       `json:"hash" rlp:"-"` 
}

*Receipt
//소스 위치 : package types 
type Receipt struct { 
// Consensus fields 
PostState []byte `json:"root"` 
Failed bool `json:"failed"` 
CumulativeGasUsed *big.Int `json:"cumulativeGasUsed" gencodec:"required"` 
Bloom Bloom `json:"logsBloom" gencodec:"required"` 
Logs []*Log `json:"logs" gencodec:"required"` 

// Implementation fields (don't reorder!) 
TxHash common.Hash `json:"transactionHash" gencodec:"required"` 
ContractAddress common.Address `json:"contractAddress"` 
GasUsed *big.Int `json:"gasUsed" gencodec:"required"` 
}

*블록 (70~100개의 transation)
type Block struct { 
header *Header 
uncles []*Header 
transactions Transactions 
td *big.Int // total difficulty 
}

type Header struct {     ParentHash         common.Hash         `json:"parentHash" gencodec:"required"`    //부모블럭     UncleHash         common.Hash         `json:"sha3Uncles" gencodec:"required"`     //엉클블록     Coinbase         common.Address         `json:"miner" gencodec:"required"`        //마이너     Root         common.Hash         `json:"stateRoot" gencodec:"required"`            //머클트리루트     TxHash         common.Hash         `json:"transactionsRoot" gencodec:"required"`    //트랜젝션들     ReceiptHash         common.Hash         `json:"receiptsRoot" gencodec:"required"`    //리시트     Bloom Bloom         `json:"logsBloom" gencodec:"required"`                    //256 bit 블품필터     Difficulty *big.Int         `json:"difficulty" gencodec:"required"`            //난이도     Number *big.Int         `json:"number" gencodec:"required"`                    //블록 현재 높이     GasLimit *big.Int         `json:"gasLimit" gencodec:"required"`                //gas limit 

    GasUsed *big.Int         `json:"gasUsed" gencodec:"required"`                   //gas used     Time *big.Int         `json:"timestamp" gencodec:"required"`                         Extra []byte         `json:"extraData" gencodec:"required"`                //extra data     MixDigest         common.Hash         `json:"mixHash" gencodec:"required"`        Nonce BlockNonce         `json:"nonce" gencodec:"required"`         //nonce

}


*머클트리(binery tree)

-rehash

-log2n


*머클 페트리시아 트리

* 이더

* gas



#합의계층

*작업증명

- 이전 블록헤더의 해쉬값

- 넌스

- 머클트리의 루트

-목표값 nunce <= 2^256 / 난이도


*이대시(Ethash)

-PoW의 문제점

-CPU intension -> 비용 증가

-6 confirm


*체인의 분기

-소프트 포크

-하드 포크

-레귤러 포크


*엉클블록 / 코스트 프로토콜


(?) 임의의 수보다 작게되는 nonce를 구하는 거라면 작은수부터 시작하면 안되나?

(?) 분기가 일어났을 때 그 뒤에 나온 minor가 어디 붙을지 고를 수 있나?



#실행계층

-컨트랙트 vs. 스마트 컨트랙

-IFTTT Logic

-solidity

-decentralized app


#공통계층

-P2P네트워크

-Node Discovery Protocol

-RLPx(Reculsive Lenth Prefix) - 디스커버리 프로토콜

-데이터 저장



#응용계층

-스마트 컨트렉트 - 주소 + ABI* - nonce**

-Javascript Web3.js


Comments