HU Yao-Chieh
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 0x1 Academy 共同筆記 ## 重要連結 - Chatroom: https://goo.gl/W9irFn - Title Slides(主投影片): https://goo.gl/jG9KEf - Course Slides(課程投影片): https://goo.gl/Z4YKi1 - 程式碼(歡迎star!):https://github.com/BlockchainEduNet-HK/smart-contract-repo **Medium部落格:(歡迎追蹤!)** Tina: https://medium.com/@tina26919742 Jeff: https://medium.com/@jj1385jeff850527 寶博: https://medium.com/@daaab **Github程式部落格:(歡迎追蹤!)** Tina: https://github.com/tina1998612 Jeff: https://github.com/yhuag 寶博: https://github.com/dAAAb **Facebook:(歡迎追蹤!)** Tina: https://www.facebook.com/lee.ting.ting.tina Jeff: https://www.facebook.com/hu.yao.chieh 寶博: https://www.facebook.com/dAAAb ## 課程補充 - OpenZeppelin模組庫: https://github.com/OpenZeppelin/openzeppelin-solidity - SafeCounter: https://github.com/BlockchainEduNet-HK/smart-contract-repo/blob/master/examples/basic/SafeCounter.sol - 存程式碼到Github的Gist:https://gist.github.com - ## 以下開放共同筆記 :) 區塊 - 交易內容 - 跟著前面的區塊摘要 (ex. 昨天交易總人數有50人) - 封箱 **區塊鏈 = 賬本 = 冊子** 交易內容太多了,搜尋要很久 每一天的交易內容切塊,一個接一個 帳本的大小會愈來愈大,目前約2TB,但帳本的成長速度會低於硬碟容量成長速度(摩爾定律?),所以基本上帳本沒有大小上限。 交易衝突 1.只有50塊,卻花了200塊買衣服。 2.一個50塊,跟A買了50塊外套,同時跟B買了50塊飲料,雙重交易。 每一時間單位,每個人的賬本會收斂成最完整最正確的一條鏈 ## 區塊的構成: Hash function特性: - 固定長度 - 相同的東西會有相同的結果,但只要有些微差異,答案就會不一樣 - hash collision? - 機率很低,ex:為什麼地球上沒有兩個一模一樣的人? - 無法回推 - 唯一的方法:暴力法(猜出所有可能排列組合) - 難度依靠在產生的長度 - 256 bits=16(123...~abc...f)^256種可能 hash 前面要有N個零 這關係到困難度 會由系統決定 hash = Nonce(猜數字) + Data + PrevHash(ParentHash) 改Data的話,會改變hash(前面四個零變不見),礦工就要重新猜數字,產生前面有四個零的新hash --- 工作量證明共識機制**可能**會被量子電腦擊潰 對抗方法: - 讓系統安全性不依賴在挖礦速度上,ex:1秒就可以產生區塊 - 量子電腦開根號也是1秒,所以在速度上不會差異太大 --- 除了創世區塊,每一個區塊都包含了前一個區塊的摘要(prev.hash) ## 共識算法及代表性的區塊鏈 #### PoW(Proof of Work): 乙太坊、比特幣 - 工作量證明,也就是挖礦 - 問題:其實浪費很多資源,大家都在做同一件事情,但其實大部分的人都在做白工 - 100個人都在挖礦,但只有一個人會挖成功 #### PoS(Proof of Stake) - 權益證明,不讓大家都挖礦 - 假設系統內有越多資源的人會越在意這個系統的穩定性、流通性... - 100個內誰最有錢,誰就是最長鏈 - 或是前10有錢的人出來投票 - 問題1:有錢的越來越有錢(資源都在你身上) - 問題2:比例分配的問題 - 如果妳現實世界的100%錢只佔了區塊鏈的1%,就不符合PoS假設 #### PoA(Proof of Authority): Hyperledger Fabric、Ripple cryptocurrency - 就選幾個人出來負責這些事情 - 為什麼要這樣? - 測試鏈,不然系統還沒正式開發上市就先燒錢燒光了,到時候上主鏈在用PoW #### DPoS(Delegate-PoS): EOS - 類似美國議會的機制 - 最有錢的10個人出來選出一群人來認證這些交易 - 透過一定程度的中心化,大幅提升效能 #### PoI(Proof of Importance): NEM - 除了考量必有多少之外,也考慮你對於該網路的重要性 - 在網路內的活躍度(發行次數...)決定你有多少票 --- #### 為了防止用區塊超車使交易失效,要等六個以上的區塊確認。 - 六次是中本聰說的(論文裡面),對於風險越高的交易,次數越多越保險 - 對於商家來說,區塊被認證一定次數後才會承認這筆交易是有效的,如此的話要複寫某個交易資訊就會變得非常難 --- ## Fork - Bitcoin vs. Bitcoin Cash - Ethereum vs. Ethereum Classic #### Hard fork vs. Soft fork - Hard fork: 分岔之後,舊的版本是不合法的,不可使用 - 上述兩個例子都是Hard fork - Soft fork: 分岔之後,舊的仍可以使用 --- **From Public Key to BTC Address:** https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses --- ## 運用WEI單位來取代小數,才安全 # 問題: 1. ERC20是什麼? ERC20跟ERC721差在哪裡? > ERC20是交易所通用的虛擬貨幣規則,定義一個虛擬貨幣會用到的基礎設定(轉帳功能,帳本調閱等等)。由於ERC20的限制在於每個貨幣都是完全相同的,ERC721提出非同質貨幣,讓我們可以創造兩個相異的單位貨幣,比方說加密貓(CryptoKitties) 2. EOS、DEXON、Hyperledger Fabric 、乙太坊、Corda 哪個區塊鏈聯盟會勝利? > 每個區塊鏈都有自己的優缺點,如果有時間的話會補充,可以私下來討論,太多內容囉 3. 有哪些私有鏈的成功商業案例呀? > 私有鏈就是只有特定人才能接觸的鏈,通常用於公司內部,所以目前沒有特別普及大眾的私有鍊 4. 要怎麼讓智慧合約具有法律效力? > 要跟法院談合作,可以參考OpenLaw 5. 如果所有使用者都不同步區塊在自己的本機上,怎麼做到分布式帳本? > 區塊鏈假設所有使用者間不互相信任 所以不會集體合作不同步 6. 對於廣大使用者來說,同步區塊到本機上沒有多大的好處,又占空間,那為什麼要同步呢? > 只有同步才能挖礦賺錢,通常只有礦工會同步 7. 所以分布式帳本,之所以能成立,完全依靠礦工嗎? > 是xD(那跟村莊的例子差很多耶!) 8. 可是能賺錢的礦工,全部都是礦場,所以共識節點不就集中在很少數人的手中了嗎? > 是Q 所以..才會有其他共識算法被提出 只是還沒真的被用到以太坊區塊鏈上,其他區塊鏈有用礦工之外的機制 10. 所以乙太坊最終一定會完全被取代或是失敗嗎? 只是時間問題? > 區塊鏈可以有soft/hard fork 也就是改變區塊鏈底層的code 11. 區塊鏈有沒有最佳節點數?就是大概多少節點來運行區塊鏈,是接近符合不可能三角? > 以太坊約有7000個節點 單純節點數多少跟不可能三角沒有直接關係 是整體算力才有關 節點數x節點算力=區塊鏈整體算力 影響不可能三角裡的scalability 12. nonce 和礦工費有關係嗎? > 沒有噢, nonce只是一個礦工猜對的數字 13. 以太幣跟比特幣有礦工進行記錄(並賺取補助金),那現在的一些小幣是怎麼讓足夠多的人幫忙記錄?目前大部分小幣(如果也是工作量證明區塊鏈)都是用同樣礦工機制 >我的意思是,使用者少這種機制不就相對不可靠了? > 上課馬上會介紹到這部分~ 14. 礦工挖礦的難易度機制調整是誰決定的,目前是誰在扮演上帝? > 難易度機制是預先寫在“節點軟體”裡的,因為所有的比特幣規則都寫在軟體裡,所謂上帝就是軟體 15. 想請問我再送一個Nounce值能不能撤銷交易 > 整個Ethereum其實有兩種nonce,上課所教的是block nonce,決定一個區塊的封箱答案。另外transaction nonce是附加在每一條transaction上的,決定transaction的先後順序。所以如果是重發一個相同transaction nonce的交易(交易衝突),就有可能被礦工拒絕接受。 16. 請問自然人憑證算是用非對稱性加密嗎? > 不太算是,認為自然人憑證並沒有依賴密碼學 17. 非對稱加密:假設A要給->B東西, A要用B發出的公鑰(施一個魔法)加密給B,全世界只有B可以用口袋的私鑰打開 --->請問是這樣嗎? > 完全正確 18. 那Gas可以不使用Ether來支付嗎?如果可以的話,以太幣是否有可能因此失去價值? > Gas必須要用Ether來支付~ 19. 所以其實交易方式比較接近:把錢匯到智能合約再由智能合約分送錢給指定的地址嗎? > 這是其中一種作法,智能合約可以提供任何程式可以做到的功能 20. 關於用智能合約做貨到付款功能,我還是不太明白,要怎麼確認,買方真的有收到貨呀? 如果貨有瑕疵要怎麼辦? > 其中一種作法可能是,買家有三天的時間可以撤除付款,所以賣家會在三天後買家沒有撤除付款的狀況下,領到扣留在智能合約裡的資金 21. 為什麼智能合約是無法竄改的? 那若將來想對Dapp做更新或修正時要怎麼做? > 智能合約因為是區塊鏈上的資料,所以不能竄改。如果DApp要更新智能合約的部分的話,就要重新部署(Deploy)智能合約,或是利用代理器(proxy)來更改智能合約版-->「非常進階」。參考資料: [1](https://hackernoon.com/upgradeable-smart-contracts-a7e9aef76fdd), [2](https://medium.com/quillhash/how-to-write-upgradable-smart-contracts-in-solidity-d8f1b95a0e9a) 22. 一般的程式碼儲存資料是在運作平台,智能合約是儲存在哪裡呢?或是在哪裡運作呢? > 智能合約會存在他被部署的那個區塊上,並且會在村民(節點)的CPU裡運作 23. 可否看別人智能合約的原始碼? > 要看別人的智能合約有沒有在Etherscan上面公布,或是擺在Github上面~比方說:https://etherscan.io/address/0x0498e54b6598e96b7a42ade3d238378dc57b5bb2#code 24. 請問寫智能合約都是使用solidity這個程式語言嗎?可以使用其他的(python java javascript..)來開發嗎 > 目前Ethereum還能用一些其他語言Serpent之類的來寫,不過Solidity比較廣泛。其他的區塊鏈則有提供其他語言來撰寫~ > 25. 請問當我們剛剛在建立錢包的時候,我們自己算是其中一個節點嗎? > 建立錢包不算唷,成為節點必須要從正式運作節點軟體(官網安裝)才算~ 26. 如果我們自己是一個節點(角色工作:礦工or村民),那我們自己的電腦上是不是就會開始從MainNet上下載2TB的帳本? > 沒錯,我們稱之為syncing(同步) 27. 請問Ethereum上的主鏈(MainNet),是由誰來託管的呀? 任何有帳本的人嗎? > 完全正確,Mainnet是由每個礦工共同管理維護的 28. 假如企業想做的服務不涉及真錢,那Ropsten、Koven 這些測試鏈,能否穩定的使用在生產環境下? > 答案是不建議,因為測試網的速度通常會有很大的變幅,而且有中央管理者(e.g. Parity)可以直接關閉運行 29. 假如企業做了一個遊戲Dapp,消費者的數據區塊都保存到MainNet上,這是合邏輯的嗎? 因為MainNet上有各種不相干的數據區塊耶! 這對企業在管理資料來說會不會很不方便? > 儘管所有的資料都散佈在區塊鏈上,不過企業管理的智能合約有唯一的地址,區塊鏈允許迅速的由地址過濾相關的資訊,所以用起來是完全不會受其他人影響的(除了網絡速度與gas價格) 30. 如何讓區塊鏈的運用方式,符合一般數據庫(SQL/NoSQL)的操作邏輯? 或者,如何互相配合使用? > 看來你差不多懂了!在一個fullstack專案中,blockchain/smart-contract是所謂”後端“的部分,所以可以使用Web3.js來模仿資料庫的存取~操作邏輯和SQL/NoSQL理念上是一樣的 31. 假如我的服務已經在那Ropsten或Koven上,測試了一段時間了,我有辦法在不丟失先前所有數據區塊的前提下,把服務移動到MainNet嗎? > 這需要一些時間,通常做法是直接snapshot之前的資料 32. 先前很夯的{社交軟體挖礦}(秘銀幣),是屬於哪一種共識機制呀? 消費者要如何識別他們的共識機制是合理的? > 共識機制是PoS, Proof of Stake, 通常會需要去研究source code源代碼,才能真正知道是否合理 33. 不論商業策略,企業有沒有義務及責任公開透明自己Dapp的共識機制細節,給消費者知道? 法律有沒有保障? > 簡答是企業沒有義務公開,但通常大眾看到未公開的合約就不會相信這家公司,法律目前未嚴格規定要公開 34. (腦洞題) 在EOS中,有屬於EOS社區自己的憲法、公投還有仲裁,假如EOS在最終成為最大贏家,是不是暗示{區塊鏈社區}有能力主導各國的法律及世界經濟的模式? > 是!!這就是區塊鏈的終極目標 (WOW 好興奮) 35. 如果哈希函數已經是無法被攻破的亂數函數,那為什麼運用其產生的亂數函數不是真正的隨機函數呢? > 那要看生成嘻哈數的方式。目前在以太坊上無法產稱『真正的亂數』,因為目前大多是靠『目前時間』 36. 為什麼礦池老闆要一直換address? > 礦池老闆不想被大家知道他賺多少錢XD 37. 區塊鏈如何洗錢防制 > 區塊鏈的特性就是匿名性,所以洗錢會自動匿名,目前銀行還在努力中解決這件事,還沒成功XD 38. 部署到區塊鏈上的計價是以容量來計還是以有多少的函數功能來計算? > 可以分層兩個層面 > > 『一』 > 執行智能合約的GAS。在合約上的每一個步驟『定義變數、計算等等的』都> 需要消耗GAS,[可參考這裡](https://ethgasstation.info/)。 > > 『二』 > 你希望給礦工的GAS。換句話來說,當非常塞車的時候而且你希望的 transaction被礦工優先處理,你就需要給更高的GAS FEE 39. 智能合約要怎麼確定貨到買家手上了可以轉錢給賣家呢? > 目前是用買家付款時,同時會透過智能合約產生一個Event當做付款收據,可以參考: https://github.com/ethereum/EIPs/issues/1586 40.傳統資料庫 transation 會有 deadlock問題,區塊鏈上同時修改一筆資料會發生deadlock嗎?我們需要自己處理嗎或是區塊鏈會自動處理? > 不會有deadlock,因為一次只會有一個礦工『出塊/寫入ETH 帳本』 41.比特幣、大部分的虛擬貨幣以及剛剛教學的發幣都要設定總發行量,有任何方法進行改動嗎(即使必須公開)?我看有人說區塊鏈貨幣最好都要有總發行量,那以太幣不設總發行量的考量跟優缺點在? > 有一點要先釐清,現在市面上有『幣』和『代幣』。這邊我們先討論『智能合約代幣』 > > 『智能合約代幣ERC20』是一個大家同意的『發代幣合約的格式』,如果你寫了『可以印鈔的合約』,理論上就不符合『ERC20代幣的合約格式』 42.若已有一個 ERC20 的 xxx token 合約,可否另發一個合約,實作出一鍵批次發送 ERC20 xxx token 行為? > 當然可以,但是contract address會不一樣 43.同42題,在 EasyPayAndWithDraw.sol 中,若要改 withdraw 指定的 ERC20 xxx token,請問如何在 msg.sender.transfer(value) 指定 ERC20 Ccontract address 呢? > 簡單來說 > msg.sender.transfer(value) 只適用於Native Currency『ETH』。 > 因為使用者是在這個ERC20 contract ledger上擁有這個ERC20。 > > 然而在Solidity語言內,智能合約是可以相互溝通,其實是可以達成你想做的事情『withdraw ERC20』,但是需透過不少work around。 44.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully