SlideShare a Scribd company logo
1 of 16
Distributed and Cloud Computing Lab.
Cyrptokitties
Je-Ho Song
<oidwin@sogang.ac.kr>
Dept. of Computer Science and Engineering
Sogang University, Seoul, Korea
1
Distributed and Cloud Computing Lab.
ERC-721 Token
 ERC – 721 이란 non-fungible 한 이더리움 블록체인 토큰의 open standard를 말한다.
 Non-fungible은 대체 불가능하고 분할할 수 없는 unique한 특성으로, 기존의 ERC – 20의 identical
하고 분할 가능한 토큰과 다르게 전자적 수집품에 더 걸맞는 토큰의 특성이다.
Use case of ERC-721
Kitty란 무엇인가?
2
그림 1] ERC-721 기반의 각종 Dapp
Distributed and Cloud Computing Lab.
Kitty의 구조체
Kitty란 무엇인가?
3
Distributed and Cloud Computing Lab.
주요 기능
각 Contract 설명 - KittyBreeding
4
그림 1] 교배할 두 Kitty를 보여주는 화면
Distributed and Cloud Computing Lab.
fucntion setGeneScienceAddress
 유전자 생성에 관련된 contract의 주소를 지정하는 함수, onlyCEO라는 modifier로
CEO만 호출할 수 있다.
 geneScience contract는 giveBirth() 라는 고양이를 생성하는 함수에서 유전자를 결정
할 때 사용된다.
각 Contract 설명 - KittyBreeding
5
Distributed and Cloud Computing Lab.
fucntion breedWithAuto
각 Contract 설명 - KittyBreeding
6
• 교배가 가능한지 각종 유효성 검사
를 거친 뒤, _breedWith 라는 실질적
으로 교배를 수행하는 함수를 호출
한다.
• 유효성 검사에는 임신 여부,
cooldown 시간이 지났는지, 교배권
이 유효한지, 그리고 Kitty를 소유하
고 있는지 여부가 포함된다.
Distributed and Cloud Computing Lab.
fucntion for validation check
각 Contract 설명 - KittyBreeding
7
Distributed and Cloud Computing Lab.
fucntion _breedWith
각 Contract 설명 - KittyBreeding
8
Distributed and Cloud Computing Lab.
fucntion giveBirth
 임신한 고양이가 새끼를 낳을 때 호출하는 함수로, 자식의 속성이 결정된다.
각 Contract 설명 - KittyBreeding
9
Distributed and Cloud Computing Lab.
fucntion giveBirth
 자식의 유전 형질이 결정되고, Kitty instance 생성
각 Contract 설명 - KittyBreeding
10
Distributed and Cloud Computing Lab.
fucntion giveBirth
 자식의 유전 형질이 결정되고, Kitty instance 생성
각 Contract 설명 - KittyBreeding
11
Distributed and Cloud Computing Lab.
geneScience.mixGenes()
각 Contract 설명 - KittyBreeding
12
그림 2] geneScience 컨트랙트의 mixGenes의 바이트 코드를 분석한 글
Distributed and Cloud Computing Lab.
Auction for sale, and siring
각 Contract 설명 - KittyAuction
13
• 경매는 크게 Kitty 자체를 거
래하는 경매와, 교배권을 거
래하는 경매로 나뉜다.
• 인기있는 고양이의 교배권
은 인기가 없는 고양이의 몸
값보다 비싸다.
그림 2] Cryptokitties 경매장 모습
Distributed and Cloud Computing Lab.
fucntion setSaleAcutionAddress/SiringAuctionAddress
각 Contract 설명 - KittyAuction
14
Distributed and Cloud Computing Lab.
fucntion createSaleAuction / createSiringAuction
 각각 고양이의 소유권과 교배권 경매를 생성하는 함수
각 Contract 설명 - KittyAuction
15
Distributed and Cloud Computing Lab. 16
Q & A

More Related Content

More from 제호 송

Blockchain sharding
Blockchain shardingBlockchain sharding
Blockchain sharding제호 송
 
Multisig and segwit
Multisig and segwitMultisig and segwit
Multisig and segwit제호 송
 
Mastering ethereum(oracle)
Mastering ethereum(oracle)Mastering ethereum(oracle)
Mastering ethereum(oracle)제호 송
 
Mastering ethereum(smart contract)
Mastering ethereum(smart contract)Mastering ethereum(smart contract)
Mastering ethereum(smart contract)제호 송
 
Mastering bitcoin chap7
Mastering bitcoin chap7Mastering bitcoin chap7
Mastering bitcoin chap7제호 송
 
Mastering bitocin chap5
Mastering bitocin chap5Mastering bitocin chap5
Mastering bitocin chap5제호 송
 
Mastering bitcoin chap6
Mastering bitcoin chap6Mastering bitcoin chap6
Mastering bitcoin chap6제호 송
 
Mastering bitcoin chap1
Mastering bitcoin chap1Mastering bitcoin chap1
Mastering bitcoin chap1제호 송
 
Mastering bitcoin chap8
Mastering bitcoin chap8Mastering bitcoin chap8
Mastering bitcoin chap8제호 송
 

More from 제호 송 (10)

Blockchain sharding
Blockchain shardingBlockchain sharding
Blockchain sharding
 
Multisig and segwit
Multisig and segwitMultisig and segwit
Multisig and segwit
 
About dapp
About dappAbout dapp
About dapp
 
Mastering ethereum(oracle)
Mastering ethereum(oracle)Mastering ethereum(oracle)
Mastering ethereum(oracle)
 
Mastering ethereum(smart contract)
Mastering ethereum(smart contract)Mastering ethereum(smart contract)
Mastering ethereum(smart contract)
 
Mastering bitcoin chap7
Mastering bitcoin chap7Mastering bitcoin chap7
Mastering bitcoin chap7
 
Mastering bitocin chap5
Mastering bitocin chap5Mastering bitocin chap5
Mastering bitocin chap5
 
Mastering bitcoin chap6
Mastering bitcoin chap6Mastering bitcoin chap6
Mastering bitcoin chap6
 
Mastering bitcoin chap1
Mastering bitcoin chap1Mastering bitcoin chap1
Mastering bitcoin chap1
 
Mastering bitcoin chap8
Mastering bitcoin chap8Mastering bitcoin chap8
Mastering bitcoin chap8
 

Cryptokitties Code Review

  • 1. Distributed and Cloud Computing Lab. Cyrptokitties Je-Ho Song <oidwin@sogang.ac.kr> Dept. of Computer Science and Engineering Sogang University, Seoul, Korea 1
  • 2. Distributed and Cloud Computing Lab. ERC-721 Token  ERC – 721 이란 non-fungible 한 이더리움 블록체인 토큰의 open standard를 말한다.  Non-fungible은 대체 불가능하고 분할할 수 없는 unique한 특성으로, 기존의 ERC – 20의 identical 하고 분할 가능한 토큰과 다르게 전자적 수집품에 더 걸맞는 토큰의 특성이다. Use case of ERC-721 Kitty란 무엇인가? 2 그림 1] ERC-721 기반의 각종 Dapp
  • 3. Distributed and Cloud Computing Lab. Kitty의 구조체 Kitty란 무엇인가? 3
  • 4. Distributed and Cloud Computing Lab. 주요 기능 각 Contract 설명 - KittyBreeding 4 그림 1] 교배할 두 Kitty를 보여주는 화면
  • 5. Distributed and Cloud Computing Lab. fucntion setGeneScienceAddress  유전자 생성에 관련된 contract의 주소를 지정하는 함수, onlyCEO라는 modifier로 CEO만 호출할 수 있다.  geneScience contract는 giveBirth() 라는 고양이를 생성하는 함수에서 유전자를 결정 할 때 사용된다. 각 Contract 설명 - KittyBreeding 5
  • 6. Distributed and Cloud Computing Lab. fucntion breedWithAuto 각 Contract 설명 - KittyBreeding 6 • 교배가 가능한지 각종 유효성 검사 를 거친 뒤, _breedWith 라는 실질적 으로 교배를 수행하는 함수를 호출 한다. • 유효성 검사에는 임신 여부, cooldown 시간이 지났는지, 교배권 이 유효한지, 그리고 Kitty를 소유하 고 있는지 여부가 포함된다.
  • 7. Distributed and Cloud Computing Lab. fucntion for validation check 각 Contract 설명 - KittyBreeding 7
  • 8. Distributed and Cloud Computing Lab. fucntion _breedWith 각 Contract 설명 - KittyBreeding 8
  • 9. Distributed and Cloud Computing Lab. fucntion giveBirth  임신한 고양이가 새끼를 낳을 때 호출하는 함수로, 자식의 속성이 결정된다. 각 Contract 설명 - KittyBreeding 9
  • 10. Distributed and Cloud Computing Lab. fucntion giveBirth  자식의 유전 형질이 결정되고, Kitty instance 생성 각 Contract 설명 - KittyBreeding 10
  • 11. Distributed and Cloud Computing Lab. fucntion giveBirth  자식의 유전 형질이 결정되고, Kitty instance 생성 각 Contract 설명 - KittyBreeding 11
  • 12. Distributed and Cloud Computing Lab. geneScience.mixGenes() 각 Contract 설명 - KittyBreeding 12 그림 2] geneScience 컨트랙트의 mixGenes의 바이트 코드를 분석한 글
  • 13. Distributed and Cloud Computing Lab. Auction for sale, and siring 각 Contract 설명 - KittyAuction 13 • 경매는 크게 Kitty 자체를 거 래하는 경매와, 교배권을 거 래하는 경매로 나뉜다. • 인기있는 고양이의 교배권 은 인기가 없는 고양이의 몸 값보다 비싸다. 그림 2] Cryptokitties 경매장 모습
  • 14. Distributed and Cloud Computing Lab. fucntion setSaleAcutionAddress/SiringAuctionAddress 각 Contract 설명 - KittyAuction 14
  • 15. Distributed and Cloud Computing Lab. fucntion createSaleAuction / createSiringAuction  각각 고양이의 소유권과 교배권 경매를 생성하는 함수 각 Contract 설명 - KittyAuction 15
  • 16. Distributed and Cloud Computing Lab. 16 Q & A

Editor's Notes

  1. 그림 1 좌 상단] 강아지를 키우고 거래하는 cryptopuppy 그림 1 좌 하단] 다양한 펑크 헤어 스타일의 캐릭터를 사고파는 cryptopunks 그림 1 우측] 원하는 pet을 키우는 cryptopet
  2. genes : Kitty의 유전형질 코드를 나타내는 256 bit의 정수로, 고양이의 외형을 결정한다 birthTime : 고양이가 태어난 블록의 timestamp cooldownEndBlock : 다음 번식까지 기다려야하는 최소한의 시간 matronId / sireId : 엄마와 아빠의 각 ID siringWithId : 임신한 경우에는 아이 아빠의 ID, 그 외에는 0 (즉, 수컷은 항상 0) cooldownIndex : 번식 이후에 cool down이 얼마나 지속됐는지 나타내는 시간(cooldownEndBlock – cooldownIndex = 다음 번식까지 남은 시간) Generation : 세대를 나타내는 정수형 data(0세대로부터 몇 번째 후손인지)
  3. KittyBreeding contract의 주요 기능은 바로 교배할 두 고양이를 선택하는것과 자식을 낳는 것이다. 함수들을 굳이 나누자면 위의 주요한 두 기능과, 두 기능을 실행하는데 유효성을 검사하는 함수 이렇게 두 종류로 나눌 수 있다.
  4. GeneSciece 라는 자식의 유전자 형질을 결정하는 함수가 존재하는데, 함수의 내용을 공개하지 않기 위해서 KittyBreeding contract 내부에 정의하지 않고 외부 contract의 함수를 호출하는 방식으로 사용하는데, 이 함수는 그 외부 contract의 주소를 설정하는 함수
  5. _는 internal utility function, 즉 사용자가 아닌 내부에서 호출하는 함수 아빠와 엄마가 결정되었을 때, 임신을 위한 initialize 과정 첫번째 문단은 reference를 지정해주는 부분 엄마의 siringWithID, 즉 아이 아빠를 지정해주는 부분 다음 교배까지 대기시간을 나타내는 Cooldown 설정 sireAllowedToAddress란, 고양이를 교배 할 수 있도록 허락한 주소를 나타내는 고양이id => 허락된 사람의 주소 mapping 교배를 하기 전에 미리 permission을 지운다. 임신한 고양이의 춧 Event emit
  6. 교배 전에 미리 확인해야 할 사항들 Cooldown 이미 임신한 상태인가?
  7. _는 internal utility function, 즉 사용자가 아닌 내부에서 호출하는 함수 아빠와 엄마가 결정되었을 때, 임신을 위한 initialize 과정 첫번째 문단은 reference를 지정해주는 부분 엄마의 siringWithID, 즉 아이 아빠를 지정해주는 부분 다음 교배까지 대기시간을 나타내는 Cooldown 설정 sireAllowedToAddress란, 고양이를 교배 할 수 있도록 허락한 주소를 나타내는 고양이id => 허락된 사람의 주소 mapping 교배를 하기 전에 미리 permission을 지운다. 임신한 고양이의 춧 Event emit
  8. 각 부모에 대한 reference 지금 낳을 수 있는지 확인(시간, 임신 여부) 각종 자식의 속성 초기화(세대)
  9. 4. mixGenes로 유전형질이 결정된다 5. Kitty instance 생성 참고: mixGenes는 black box로, 공개되지 않는다.
  10. giveBirth를 수행하는데 최소한의 금액을 납부(autobirthFee)
  11. 실제로 유전 형질을 결정하는 함수를 crack해보는 시도도 있다.
  12. 이 contract는 고양이를 경매하고 입찰하는데 사용되는 함수가 정의되어 있습니다. 이 함수는 판매와 중매를 담당하는 자식 컨트랙트에 의해 수행됩니다. 자식 컨트랙트로 굳이 분리한 이유는 다른 기능보다 로직이 복잡해서 버그의 가능성이 더 높기 때문에 상황에 따른 bug 수정을 위해서 분리하였다. setGeneScienceAddress 함수와 마찬가지로 두 자식 컨트랙트인 SaleAuction과 SiringAuction의 address를 지정하는 함수
  13. 고양이를 경매에 넘기기 위해서 require를 통해 소유권과 임신 여부를 체크하고(임신한 고양이의 경우 자식의 소유권까지 넘어갈 경우가 생길 수 있어서 제한한다) 경매 instance를 생성한다. 마찬가지로 오른쪽은 소유권과 임신이 가능한지 여부를 체크하고 auction을 생성한다.