發表文章

目前顯示的是 6月, 2017的文章

公平結果驗證

網上博彩最容易被大眾標籤的地方是結果產生欠透明度,公平性成疑。如何有效建立彼此的信任,是長遠經營成功的關鍵!這裡會分享一下,一個非常有趣而且聰明的數學方法去針對這方面需要。 首先,在數學層面,有一項加密方式叫SHA256,它是由美國國家安全局於2008年所發表的,詳細資料可按 這裡 。它的特色是,可以把任何字串句子,加密成一串長32個字母混合數字的字串,例如: 把"Hello"加密成: "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969" 但如果我們輕輕把"Hello"改成"Hella",那結果將會是完全不同: "62197ce641a17c96cf39ed51e72e86fd486f3de7b0135f8b8f0f7364dc010e54" 試嘗加密其他可到 這裡 。 而且,有一個非常重要的特性,就是這個加密是 單向 的!即是說,如果我們只有加密後的結果,是無法運算出原本的字串,唯一方法是隨機撞中,但那需要極多的時間,或極大的hashing power,這大概是不可行。 正正應用以上特性,遊戲的結果可以結合伺服器方的秘密種子(即"Hello")及由玩家提供的輸入/隨機字串所產生,而在下注及結果產生之前,伺服器方會把已加密的結果字串("185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969"),傳給玩家作記錄。當結果公怖後,伺服器方的秘密種子("Hello")也隨之公開,那玩家就可以利用SHA256加密工具去驗證一次,那秘密種子加密後,是不是跟"185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969"一致。如果是,那代表,"Hello"是在結果產生及下注前已經存在,而不是針對自己的下注決定所產生出來欺騙玩家。

Smart Contract and Random Number

圖片
It is really awesome that Ethereum support easy-deployment of smart contract by individual developers! The language / script is using called Solidity. However, unlike coding in ordinary environment, it is running in blockchain network, so we don't have a function simply to seed and generate numbers, as all outputs from blockchain network are deterministic. Blockhash This is an approach for games which are merely for fun or with a relatively small bet, as its number generation algorithm is transparent and shown in the smart contract and also its inputs, like blockhash (an unique long text for labelling a block) and block number (completely deterministic). Normally, blockhash is unpredictable but if the bet is extremely large or worthy, miners can choose to whether publish a new block to the network, so they can have some degrees of control in blockhash generation for result manipulation. Here is a simple: contract random { /* Generates a random number from 0 to 1

Ethereum is a destructive stuff for web3!

With the growth of blockchain technology, it keeps changing the world. It makes our Internet be more transparent and having higher level of security.  In recent years, Bitcoin creates lots of discussions and critics. People in general associate it with illegal activities and evil money, but actually it is a very very realistic example in the success of blockchain application in real world! Please note that, blockchain is not equal of Bitcoin, but Bitcoin's operation relies on  blockchain technology. Similarly, Bitcoin is not an only crytocurrency but many many alternative coins do exist. For example Litecoin, Ripple and Dogecoin are quite popular. An indispensable one, Ethereum, a very promising public blockchain infrastructure in the coming future! It allows individual developers deploying smart contract to a sophisticated public network in which stakeholders of a contract all understand the contract details, things fairly without cheating, an awesome environment to repla

 智能合約的好處

智能合約與區塊鏈的關係 如果說區塊鏈1.0是以比特幣為代表,解決了貨幣和支付手段的去中心化問題,那麼區塊鏈2.0就是更宏觀的對整個市場去中心化,利用區塊鏈技術來轉換許多不同的數字資產而不僅僅是比特幣,通過轉讓來創建不同資產的價值。區塊鏈技術的去中心化賬本功能可以被用來創建、確認、轉移各種不同類型的資產及合約。幾乎所有類型的金融交易都可以被改造成在區塊鏈上使用,包括股票、私募股權、眾籌、債券和其他類型的金融衍生品如期貨、期權等。 薩博關於智能合約的工作理論遲遲沒有實現,一個重要原因是因為缺乏能夠支持可編程合約的數字系統和技術。區塊鏈技術的出現解決了該問題,不僅可以支持可編程合約,而且具有去中心化、不可篡改、過程透明可追踪等優點,天然適合於智能合約。因此,也可以說,智能合約是區塊鏈技術的特性之一。 智能合約看上去就是一段計算機執行程序,滿足可準確自動執行即可,那麼為什麼用傳統的技術為何很難實現,而需要區塊鏈技術等新技術呢?傳統技術即使通過軟件限制、性能優化等方法,也無法同時實現區塊鏈的特性: 1. 是數據無法刪除、修改,只能新增,保證了歷史的可追溯,同時作惡的成本將很高,因為其作惡行為將被永遠記錄; 2. 是去中心化,避免了中心化因素的影響。 基於區塊鏈技術的智能合約不僅可以發揮智能合約在成本效率方面的優勢,而且可以避免惡意行為對合約正常執行的干擾。將智能合約以數字化的形式寫入區塊鏈中,由區塊鏈技術的特性保障存儲、讀取、執行整個過程透明可跟踪、不可攥改。同時,由區塊鏈自帶的共識算法構建出一套狀態機系統,使得智能合約能夠高效地運行。 智能合約工作原理 基於區塊鏈的智能合約包括事務處理和保存的機制,以及一個完備的狀態機,用於接受和處理各種智能合約;並且事務的保存和狀態處理都在區塊鏈上完成。事務主要包含需要發送的數據;而事件則是對這些數據的描述信息。事務及事件信息傳入智能合約後,合約資源集合中的資源狀態會被更新,進而觸發智能合約進行狀態機判斷。如果自動狀態機中某個或某幾個動作的觸發條件滿足,則由狀態機根據預設信息選擇合約動作自動執行。 智能合約系統根據事件描述信息中包含的觸發條件,當觸發條件滿足時,從智能合約自動發出預設的數據資源,以及包括觸發條件的事件;整個智能合約系統的核心就在於智能合約以事務和事件的