ECC (Part II) & Smart Contracts
- Sep. 16, 2019
ECC (Part II) & Smart Contracts Sep. 16, 2019 Overview - - PowerPoint PPT Presentation
ECC (Part II) & Smart Contracts Sep. 16, 2019 Overview Cryptography with ECC How to send secret messages Bitcoins Stack Machine scripts Review Limitations Ethereums answer to those limitations
P + Q n nP P − Q
P Q P+Q
can be added to itself, the new point is
G H = 2G k F = kG mod n y2 mod n = x3 + ax + b mod n
Q P P+Q
Inverse addition problem
, find so that
itself to reach ?
G, H a ∈ ℤp H = aG p = (x, y) q
H G
Inverse addition problem
H G
Inverse addition problem
random number generators that made points predictable
H G
Inverse addition problem
random number generators that made points predictable
H G
Inverse addition problem
generators that made points predictable
H G
P + Q, H = aG, etc. ⋅ g ⋅ h, ga
)
P + Q, H = aG, etc. g ⋅ h, ga ab mod n (gahγ)
x
“A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines. With consistency a great soul has simply nothing to do.”
— Ralph Waldo Emerson (poet) ⇒ We will use additive and multiplicative notations in this course
Find , so that
a y = ga mod n
can be added to itself, the new point is
and a second point , it is not possible to efficiently compute integer so that
H = 2G k F = kG G R r ∈ ℤp R = rG
g a y y g a y a g
g a y y g a y a g
One popular curve (Curve25519) has points (7237005577332262213973186563042994240857116359379907606001950938285455250989)
7.237 ⋅ 1075
for curve
(does not have to be prime)
a, b ∈ ℤ, n (y2 mod n) = (x3 + ax + b mod n) G n ∈ ℕ nG
Whitfield Diffie and Martin Hellman
Q=P+(ab)G to Bob
communication, can compute the point P . All they see is Q
Alice Bob aG b(aG) bG a(bG) Q=P+a(bG) Q P=Q-b(aG)
secret message as a point
cryptography systems
compute x
public key
signature public Key
Program (scriptPubKey) Init state of stack (scriptSig)
data
Program (scriptPubKey) Init state of stack (scriptSig)
present
Program (scriptPubKey) Init state of stack (scriptSig)
another signature
3-out-of-5 signatures are present
Program (scriptPubKey) Init state of stack (scriptSig)
signature C signature A signature E
3-out-of-5 signatures are present
Program (scriptPubKey) Init state of stack (scriptSig)
signature C signature A signature E 3
3-out-of-5 signatures are present
Program (scriptPubKey) Init state of stack (scriptSig)
signature C signature A signature E 3 pubKey1
3-out-of-5 signatures are present
Program (scriptPubKey) Init state of stack (scriptSig)
signature C signature A signature E 3 pubKey1 pubKey4
…
3-out-of-5 signatures are present
Program (scriptPubKey)
signature C signature A signature E 3 pubKey1 pubKey4
…
pubKey5
3-out-of-5 signatures are present
Program (scriptPubKey)
signature C signature A signature E 3 pubKey1 pubKey4
…
pubKey5 5
OP_CHECKMULTISIG: read m read m public keys read n read n signatures return TRUE if all signatures can be verified (no duplicates)
regulations)
—Mitt Romney
into Bitcoin’s scripting language
ultimately goes to people. Where do you think it goes?”
Can we do more?
program to run
transactions, etc.”
program to run
def transactionCode(self): done = False while(not done): pass
def transactionCode(self): done = False while(not done): pass
program to run
a code can run
in fully fledged Turing-complete programming language”
1024 etc 1024 etc 45 eth 122 eth — code data 1024 etc 1024 eth
Machine (EVM)
State 0 State 1
ad6bb32b:
…
1024 etc 1024 etc 45 eth 126 eth — code data’ 1024 etc 1020 eth
…
712d9a77: b39458a7: ad6bb32b: 712d9a77: b39458a7: from: ad6bb32b to: 712d9a7 value: 4 eth call: send(xyz)
tx 0
Machine (EVM)
State 0 State 1 tx 0 APPLY(S[0], Tx[0]) S[1]
→
Machine (EVM)
Ethereum White Paper https://github.com/ethereum/wiki/wiki/White-Paper
messages to it
Ethereum new coin transactions
→ →
class MyCoin: def __init__(self): self.balance = dict() self.balance[“CentralBank”] = 1000000000
if Smart Contracts were written in Python
Initialize by giving 1B MyCoins to the central bank
class MyCoin: def __init__(self): self.balance = dict() self.balance[“CentralBank”] = 1000000000 def getBalance(self, accountID): if accountID in self.balance: return self.balance return 0
if Smart Contracts were written in Python
reading the account balance 0 if the account doesn’t exist
class MyCoin: def __init__(self): self.balance = dict() self.balance[“CentralBank”] = 1000000000 def getBalance(self, accountID): if accountID in self.balance: return self.balance return 0 def transfer(self, accountID, amount, to): maxTransferrable = min(self.getBalance(accountID), amount) self.balance[accountID] -= maxTransferrable self.balance[to] = maxTransferrable
if Smart Contracts were written in Python
transfer amount from the sender (accountID) to the recipient (to). If the balance is less than the amount, transfer
available
class MyCoin: def __init__(self): self.balance = dict() self.balance[“CentralBank”] = 1000000000 def getBalance(self, accountID): if accountID in self.balance: return self.balance return 0 def transfer(self, accountID, amount, to): maxTransferrable = min(self.getBalance(accountID), amount) self.balance[accountID] -= maxTransferrable self.balance[to] = maxTransferrable def buy(self, accountID, amount): self.balance[accountID] += amount
if Smart Contracts were written in Python
buy MyCoins by sending eth
(Python is not a good language for this)
external reference might have changed
contract GavCoin { mapping(address=>uint) balances; uint constant totalCoins = 100000000000; function GavCoin(){ balances[msg.sender] = totalCoins; } function balance(address who) constant returns (uint256 balanceInmGAV) { balanceInmGAV = balances[who]; } function send(address to, uint256 valueInmGAV) { if (balances[msg.sender] >= valueInmGAV) { balances[to] += valueInmGAV; balances[msg.sender] -= valueInmGAV; } } }
https://en.wikipedia.org/wiki/Solidity
Endows creator of contract with 100B GAV 100 ⋅ 109 = 100B
Send $(valueInmGAV) GAV from the account of $(message.caller.address()), to an account accessible only by $(to.address()) getter function for the balance
several other lectures