0% found this document useful (0 votes)
155 views30 pages

Smart Contract

The document discusses upgradable smart contracts, which allow for updating distributed application logic while preserving data. It notes several options that are currently available for upgradable contracts, including using assembly, generic open proxies, library-based delegate call proxies, and eternal storage split logic proxies. Most examples currently utilize the delegateCall() function. The document also provides sample Solidity code for a key-value storage contract with a proxy that could allow for upgradable contracts by separating data and logic.

Uploaded by

blueiconus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views30 pages

Smart Contract

The document discusses upgradable smart contracts, which allow for updating distributed application logic while preserving data. It notes several options that are currently available for upgradable contracts, including using assembly, generic open proxies, library-based delegate call proxies, and eternal storage split logic proxies. Most examples currently utilize the delegateCall() function. The document also provides sample Solidity code for a key-value storage contract with a proxy that could allow for upgradable contracts by separating data and logic.

Uploaded by

blueiconus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

UPGRADABLE SMART CONTRACTS

( updating distributed application logic whilst preserving data )

www.BCE.asia
INTRODUCTIONS

The Blockchain Embassy of Asia


( registered non-profit blockchain consortium )

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”


ONE OF THE PROJECTS WE ARE WORKING ON ...

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
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
PLATFORMS USED FOR SMART CONTRACT TOKENIZATION PROJECTS
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
US$5 BILLION RAISED IN 2017 FROM ICOs
WHAT DO THESE DUMB DISTRIBUTED CODE SNIPPETS DO ?
CONTEXT
why is upgradability important ?
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 ...


ERC20 VS ERC721

FUNGIBLE TOKENS NON-FUNGIBLE TOKENS


110K+ ERC20 contracts deployed 150+ ERC721 contracts deployed

-- Every unit has the same value -- Every unit has different value
-- Currencies, points & commodities -- Shares, titles and other IP

-- ERC20 > ERC223 > ERC777 -- ERC721 > ERC998 > ERC1155
-- ERC223 prevents lost ether -- ERC998 introduced composables
-- ERC777 uses contract registrars -- ERC1155 crypto items standard
SHOUT OUT TO FELLOW MALAYSIANS @ ETHERSCAN.io
THE BENEFITS OF STANDARDIZATION
0x PROTOCOL ADOPTION

( August 2017 - May 2018 )


THE BUSINESS OF STANDARDIZATION
REMEMBER THESE ? ( THIS ONE COST RM 600,000 )
THE BENEFITS OF FUNDED STANDARDIZATION
PROGRESS
what options are already available ?
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()


BUILDING UPON STANDARDS - SOON TO BE UPGRADABLE CONTRACTS ?
SOLIDITY CODE FOR DELEGATE CALL BASED PROXIES

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 SPLITTING ETERNAL DATA AND LOGIC

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;
}
}
RESULTS
what does www.BCE.asia do ?
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 ...
SOLIDITY CODE FOR BASIC KEY VALUE STORE WITH PROXY

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 SETTING STANDARDS FROM STORED DATA

contract ERC20
{
proxy db;

function ERC20(address proxyContractAddress)


{
db = proxy(proxyContractAddress);
}
function balanceOf(address Address) returns(uint)
{
return db.getUint(Address, ‘balanceOf’);
}
}
INTERESTING SIDE EFFECTS OF USING THIS METHOD

ERC 20 ERC 721

Token Factories

Distributed Access Control eWallets


Allows for Upgradable Smart Contracts Provide Standardized Interfaces
Exchange
Automated Exchange

Trustee
Automated Escrow Services

Trusts
Unit Trusts (Collections)
Distributed Key Value Store P2P Markets
Database Containing ALL Data Allow Users to Utilize Central Bank Services

Automated Central Banking


HOW WE USE OUR TOKEN FACTORIES

ERC 20
TOKENS
(fungible)

Atoms Resources Energy Credits Workers


Universal properties Tradable Weight of atoms as Central currency Children that are
defined by actual commodities such as cost chemistrial controlled by central attached to a
Periodic Table wood & steel changes AI bank corporation
PLAYERS
(linked to public
addresses)

ERC 721
TOKENS
(non fungible) Actions
Forming Alliances
Get Married
Have Kids
Mine Atoms
Planets Buildings & Vehicles Children Corporation Trade Goods
Maintains its own uniquely named bundles of resources with Generated by any Uniquely named Switch Locations
collection of specific utility function to players and/or 2 players bundle of workers Construct Things
un-mined atoms planet owners consummating and buildings
WHAT’S THE CATCH / COSTS ? -- MORE IMPORTANTLY, HOW WILL IT SCALE ?
WANT TO LEARN MORE ?
[email protected]

www.BCE.asia

You might also like