Solidity 
What and Why
Problem 
Need people to write contracts. 
Correct contracts. 
Lots of people.
Solutions 
Tend to be Web devs 
Syntax similar to JavaScript 
...to minimise barriers to entry and leverage existing skillset
Solutions 
Express common concepts clearly 
First-class contracts as classes 
...for transparent integration and reuse 
Storage constructs 
...for ease of contract STORE usage 
Variadic returns 
...for ease of contract RETURN passing
Solutions 
Make things likely to be correct 
Unit tests 
...that are easier to use than not 
Formal proofing 
...that makes statements guaranteed always true
Solutions 
Documentation fundamental 
Inbuilt documentation system 
(See later talk)
Contracts as first-class citizens 
contract StoreNumber { 
void set(uint n) { ... } 
uint get() const { ... } 
... 
} 
contract Other { 
Other() { 
StoreNumber s = ...; 
s.set(69); 
... 
uint n = s.get(); 
} 
}
(Easy) Storage Facilities 
contract StoreNumber { 
function set(uint n) { m_n = n; } 
function get() const returns (uint) { 
return m_n; 
} 
uint m_n; 
}
(Easy) Storage Facilities 
struct Endpoint { 
uint32 ipv4; 
uint16 port; 
} 
contract Endpoints { 
function set(uint32 _ipv4, uint16 _port) { 
var end = new Endpoint({ipv4: _ipv4, port: 
_port}); 
m_ends[msg.caller] = end; 
} 
function kill() { delete m_ends[msg.caller]; } 
mapping { address => Endpoint } m_ends; 
}
Variadic Returns 
contract Endpoints { 
function set(uint32 _ipv4, uint16 _port) { 
var end = new Endpoint({ipv4: _ipv4, port: 
_port}); 
m_ends[msg.caller] = end; 
} 
function kill() { delete m_ends[msg.caller]; } 
function get(address _a) const 
returns (uint32, uint16) { 
return m_ends[_a]; 
} 
mapping { address => Endpoint } m_ends; 
}
Formal Proofing 
contract Cash { 
function give(address _a, uint32 _amount) { 
if (m_balances[msg.caller] >= _amount) { 
m_balances[msg.caller] -= _amount; 
m_balances[_a] += _amount; 
} 
} 
function balance(address _a) const returns (uint32) 
{ 
return m_balances[_a]; 
} 
mapping { address => uint64 } m_balances; 
construction: 
m_balances[msg.caller] = 1000000000; 
invariant: 
reduce(+, map(valueOf, m_balances)) == 1000000000; 
}
Inbuilt Docs (NatSpec) 
contract Cash { 
/// Transfers `_amount` cash from your account 
/// `msg.caller` to the account controlled by `_a`. 
function give(address _a, uint32 _amount) { 
if (m_balances[msg.caller] >= _amount) { 
m_balances[msg.caller] -= _amount; 
m_balances[_a] += _amount; 
} 
} 
/// Returns the amount of cash controlled by account 
/// `_a`. 
function balance(address _a) const returns (uint32) 
{ 
return m_balances[_a]; 
} 
mapping { address => uint64 } m_balances; 
construction: 
/// Creator of contract is endowed with balance of 
/// 1000000000. 
m_balances[msg.caller] = 1000000000; 
invariant: 
/// Total cash in system is always 1000000000. 
reduce(+, map(valueOf, m_balances)) == 1000000000; 
}
Solidity 
What and Why 
Over to Christian

Solidity

  • 1.
  • 2.
    Problem Need peopleto write contracts. Correct contracts. Lots of people.
  • 3.
    Solutions Tend tobe Web devs Syntax similar to JavaScript ...to minimise barriers to entry and leverage existing skillset
  • 4.
    Solutions Express commonconcepts clearly First-class contracts as classes ...for transparent integration and reuse Storage constructs ...for ease of contract STORE usage Variadic returns ...for ease of contract RETURN passing
  • 5.
    Solutions Make thingslikely to be correct Unit tests ...that are easier to use than not Formal proofing ...that makes statements guaranteed always true
  • 6.
    Solutions Documentation fundamental Inbuilt documentation system (See later talk)
  • 7.
    Contracts as first-classcitizens contract StoreNumber { void set(uint n) { ... } uint get() const { ... } ... } contract Other { Other() { StoreNumber s = ...; s.set(69); ... uint n = s.get(); } }
  • 8.
    (Easy) Storage Facilities contract StoreNumber { function set(uint n) { m_n = n; } function get() const returns (uint) { return m_n; } uint m_n; }
  • 9.
    (Easy) Storage Facilities struct Endpoint { uint32 ipv4; uint16 port; } contract Endpoints { function set(uint32 _ipv4, uint16 _port) { var end = new Endpoint({ipv4: _ipv4, port: _port}); m_ends[msg.caller] = end; } function kill() { delete m_ends[msg.caller]; } mapping { address => Endpoint } m_ends; }
  • 10.
    Variadic Returns contractEndpoints { function set(uint32 _ipv4, uint16 _port) { var end = new Endpoint({ipv4: _ipv4, port: _port}); m_ends[msg.caller] = end; } function kill() { delete m_ends[msg.caller]; } function get(address _a) const returns (uint32, uint16) { return m_ends[_a]; } mapping { address => Endpoint } m_ends; }
  • 11.
    Formal Proofing contractCash { function give(address _a, uint32 _amount) { if (m_balances[msg.caller] >= _amount) { m_balances[msg.caller] -= _amount; m_balances[_a] += _amount; } } function balance(address _a) const returns (uint32) { return m_balances[_a]; } mapping { address => uint64 } m_balances; construction: m_balances[msg.caller] = 1000000000; invariant: reduce(+, map(valueOf, m_balances)) == 1000000000; }
  • 12.
    Inbuilt Docs (NatSpec) contract Cash { /// Transfers `_amount` cash from your account /// `msg.caller` to the account controlled by `_a`. function give(address _a, uint32 _amount) { if (m_balances[msg.caller] >= _amount) { m_balances[msg.caller] -= _amount; m_balances[_a] += _amount; } } /// Returns the amount of cash controlled by account /// `_a`. function balance(address _a) const returns (uint32) { return m_balances[_a]; } mapping { address => uint64 } m_balances; construction: /// Creator of contract is endowed with balance of /// 1000000000. m_balances[msg.caller] = 1000000000; invariant: /// Total cash in system is always 1000000000. reduce(+, map(valueOf, m_balances)) == 1000000000; }
  • 13.
    Solidity What andWhy Over to Christian