Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

An Introduction to Upgradable Smart Contracts

165 views

Published on

Presented on behalf of www.BCE.asia at the Blockchain Developer Malaysia meetup on August the 22nd

Published in: Technology
  • Be the first to comment

An Introduction to Upgradable Smart Contracts

  1. 1. UPGRADABLE SMART CONTRACTS ( updating distributed application logic whilst preserving data ) www.BCE.asia
  2. 2. INTRODUCTIONS Mark Smalley CEO @ Neuroware.io | Tweet Me: @m_smalley Volunteer at Blockchain Embassy Living in Malaysia for 20 Years Building FinTech Applications for 15 Years Building Blockchain Applications for 6 Years Disclaimer: “I bought Bitcoin when they were US$10” The Blockchain Embassy of Asia ( registered non-profit blockchain consortium )
  3. 3. ownership automatically assigned to whatever address you choose during the generation stage with the DNA then being used to generate planet colours, evolutionary species, ruling family names and other meta information Urban Rural Ocean ONE OF THE PROJECTS WE ARE WORKING ON ...
  4. 4. SMART CONTRACTS ARE NEITHER SMART NOR CONTRACTUAL ● Even Bitcoin utilizes basic smart contracts (with over 100 script functions) ● Smart contracts are snippets of code stored and executed by the network ● They can perform transactional based events if defined conditions are met
  5. 5. PLATFORMS USED FOR SMART CONTRACT TOKENIZATION PROJECTS
  6. 6. WHAT MAKES ETHEREUM DIFFERENT TO STANDARD STACKED OPs ? ● Raised US$15 Million in token-sales when launching their Ether currency ● Aiming to be the first turing complete blockchain, they almost achieved it ● Heavily supported by Microsoft and also used by IBM for their IoT platform ● Unlike BTC, we know who built it - currently uses PoW, plans to switch to PoS ● However, the more moving parts a system has - the more likely it is to break
  7. 7. US$5 BILLION RAISED IN 2017 FROM ICOs
  8. 8. WHAT DO THESE DUMB DISTRIBUTED CODE SNIPPETS DO ?
  9. 9. CONTEXT why is upgradability important ?
  10. 10. OVER 34K ETHEREUM SMART CONTRACTS ARE VULNERABLE TO BUGS ● Immutable logic is VERY different to immutable data … With UTXO methods such as Bitcoin OP_Returns, this is not a problem ● 2016: 3M+ Ether lost @ DAO (Worth US$80M at time - now US$1B+) ● 2017: 150K Ether lost @ Parity MS leading to US$300M+ frozen ● 2018: 2K Ether lost @ POWH Coin from an integer underflow! ● The ever evolving journey of ERC standards ...
  11. 11. ERC20 VS ERC721 FUNGIBLE TOKENS 110K+ ERC20 contracts deployed -- Every unit has the same value -- Currencies, points & commodities -- ERC20 > ERC223 > ERC777 -- ERC223 prevents lost ether -- ERC777 uses contract registrars NON-FUNGIBLE TOKENS 150+ ERC721 contracts deployed -- Every unit has different value -- Shares, titles and other IP -- ERC721 > ERC998 > ERC1155 -- ERC998 introduced composables -- ERC1155 crypto items standard
  12. 12. SHOUT OUT TO FELLOW MALAYSIANS @ ETHERSCAN.io
  13. 13. THE BENEFITS OF STANDARDIZATION
  14. 14. 0x PROTOCOL ADOPTION ( August 2017 - May 2018 )
  15. 15. THE BUSINESS OF STANDARDIZATION
  16. 16. REMEMBER THESE ? ( THIS ONE COST RM 600,000 )
  17. 17. THE BENEFITS OF FUNDED STANDARDIZATION
  18. 18. PROGRESS what options are already available ?
  19. 19. MOST POPULAR CURRENT METHODS ● Assembly to the rescue? ● Generic Open Proxies & Dispatches ● Library Based Delegate Call Proxies ● Eternal Storage Split Logic Proxies ● Key Value Data Storage Proxies ● Nearly every example seen to date utilizes the delegateCall()
  20. 20. BUILDING UPON STANDARDS - SOON TO BE UPGRADABLE CONTRACTS ?
  21. 21. contract OpenProxy { function () { assembly { let result := delegatecall(gas, _impl, add(data, 0x20), mload(data), 0, 0) let size := returndatasize let ptr := mload(0x40) returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } } } SOLIDITY CODE FOR DELEGATE CALL BASED PROXIES
  22. 22. contract TokenStorage { uint256 internal _totalSupply; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _allowances; } contract TokenLogic { TokenStorage storage; storage = TokenStorage(0xStorageContractAddress); function totalSupply(){ return storage._totalSupply; } } SOLIDITY CODE FOR SPLITTING ETERNAL DATA AND LOGIC
  23. 23. RESULTS what does www.BCE.asia do ?
  24. 24. COMBINING THE BEST OF BOTH WORLDS ? ● It all starts with a master key value store sharded by msg.sender ● Key value store read / write access limited to specific proxy addresses ● Proxies are merely channels for accessing key value functions ● Allows other contracts communicating with proxy to be upgraded ● One proxy per project stakeholder provides user role management ● No assembly or delegateCall used as proxy functions mirror key value The immutability of data remains the same within final contracts ...
  25. 25. contract keyValueStore { mapping(address => mapping(address => mapping(string => uint))) addressedUints; function _getUint(address Address, string key) returns(uint) { return addressedUints[msg.sender][Address][key]; } } contract proxy { keyValueStore kv; function proxy(address keyValueContractAddress){ kv = keyValueStore(keyValueContractAddress); } function getUint(address Address, string key) returns(uint){ return kv._getUint(Address, key); } } SOLIDITY CODE FOR BASIC KEY VALUE STORE WITH PROXY
  26. 26. contract ERC20 { proxy db; function ERC20(address proxyContractAddress) { db = proxy(proxyContractAddress); } function balanceOf(address Address) returns(uint) { return db.getUint(Address, ‘balanceOf’); } } SOLIDITY CODE FOR SETTING STANDARDS FROM STORED DATA
  27. 27. Distributed Key Value Store Database Containing ALL Data Distributed Access Control Allows for Upgradable Smart Contracts ERC 20 ERC 721 Exchange Automated Exchange Trustee Automated Escrow Services Trusts Unit Trusts (Collections) Automated Central Banking eWallets Provide Standardized Interfaces P2P Markets Allow Users to Utilize Central Bank Services Token Factories INTERESTING SIDE EFFECTS OF USING THIS METHOD
  28. 28. Planets Maintains its own collection of un-mined atoms ERC 20 TOKENS (fungible) ERC 721 TOKENS (non fungible) Atoms Universal properties defined by actual Periodic Table Resources Tradable commodities such as wood & steel Energy Weight of atoms as cost chemistrial changes Credits Central currency controlled by central AI bank Workers Children that are attached to a corporation Buildings & Vehicles uniquely named bundles of resources with specific utility function to players and/or planet owners Children Generated by any 2 players consummating Corporation Uniquely named bundle of workers and buildings PLAYERS (linked to public addresses) Actions Forming Alliances Get Married Have Kids Mine Atoms Trade Goods Switch Locations Construct Things HOW WE USE OUR TOKEN FACTORIES
  29. 29. WHAT’S THE CATCH / COSTS ? -- MORE IMPORTANTLY, HOW WILL IT SCALE ?
  30. 30. WANT TO LEARN MORE ? info@bce.world www.BCE.asia

×