From 9a417389fa502b4a0c027efae555ee4fee36178c Mon Sep 17 00:00:00 2001 From: Vitalik Buterin Date: Fri, 16 Jun 2017 03:29:50 -0400 Subject: [PATCH] Added minimum utxo scheme --- forwarder.py | 2 +- iceage.py | 8 ++++---- utxo_tester.py | 26 ++++++++++++++++++++++++++ utxos.v.py | 19 +++++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 utxo_tester.py create mode 100644 utxos.v.py diff --git a/forwarder.py b/forwarder.py index 97a7b6b..786e311 100644 --- a/forwarder.py +++ b/forwarder.py @@ -26,7 +26,7 @@ def increment_moose(i: num) -> num: def test(): from ethereum.tools import tester2 c = tester2.Chain() - x = c.contract(kode, language='viper') + x = c.contract(kode, language='viper', sender=tester2.k3) fwdcode = mk_forwarder(x.address) initcode = mk_wrapper(fwdcode) y = c.contract(initcode, language='evm') diff --git a/iceage.py b/iceage.py index 4ae1a8e..931f0ad 100644 --- a/iceage.py +++ b/iceage.py @@ -1,12 +1,12 @@ import random import datetime -diffs = [512.60 * 10**12] -hashpower = diffs[0] / 15.50 -times = [1496227377] +diffs = [677.20 * 10**12] +hashpower = diffs[0] / 16.30 +times = [1497319121] -for i in range(3797763, 6010000): +for i in range(3863874, 6010000): blocktime = random.expovariate(hashpower / diffs[-1]) adjfac = max(1 - int(blocktime / 10), -99) / 2048. newdiff = diffs[-1] * (1 + adjfac) diff --git a/utxo_tester.py b/utxo_tester.py new file mode 100644 index 0000000..f6d1ad6 --- /dev/null +++ b/utxo_tester.py @@ -0,0 +1,26 @@ +from ethereum.tools import tester as t +from ethereum import utils as u +c = t.Chain() +x = c.contract(open('utxos.v.py').read(), language='viper', sender=t.k0) +assert u.normalize_address(x.get_utxos__owner(u.encode_int32(1))) == t.a0 +assert x.get_utxos__value(u.encode_int32(1)) == 2**32 + +sigdata = u.encode_int32(1) + u.encode_int32(0) + b'\x00' * 12 + t.a2 + \ + u.encode_int32(2**30) + b'\x00' * 12 + t.a2 + u.encode_int32(3 * 2**30) +sighash = u.sha3(sigdata) + +v, r, s = u.ecsign(sighash, t.k0) + +assert x.tx(u.encode_int32(1), u.encode_int32(0), t.a2, 2**30, t.a2, 3 * 2**30, v, r, s) == sighash +assert u.normalize_address(x.get_utxos__owner(sighash)) == t.a2 +assert x.get_utxos__value(sighash) == 2**30 + +sigdata2 = sighash + u.encode_int32(0) + b'\x00' * 12 + t.a3 + \ + u.encode_int32(2**29) + b'\x00' * 12 + t.a3 + u.encode_int32(2**29) +sighash2 = u.sha3(sigdata2) + +v, r, s = u.ecsign(sighash2, t.k2) + +assert x.tx(sighash, u.encode_int32(0), t.a3, 2**29, t.a3, 2**29, v, r, s) == sighash2 + +print('Tests passed') diff --git a/utxos.v.py b/utxos.v.py new file mode 100644 index 0000000..828998a --- /dev/null +++ b/utxos.v.py @@ -0,0 +1,19 @@ +utxos: public({owner: address, value: num}[bytes32]) + +def __init__(): + self.utxos[as_bytes32(1)] = {owner: msg.sender, value: 4294967296} + +def tx(in1: bytes32, in2: bytes32, out1: address, value1: num, + out2: address, value2: num, v: num256, r: num256, s: num256) -> bytes32: + sighash = sha3(concat(in1, in2, as_bytes32(out1), as_bytes32(value1), as_bytes32(out2), as_bytes32(value2))) + sender = ecrecover(sighash, v, r, s) + assert self.utxos[in1].owner == sender or not in1 + assert self.utxos[in2].owner == sender or not in2 + value = self.utxos[in1].value + self.utxos[in2].value + assert value == value1 + value2 + self.utxos[in1] = {owner: None, value: None} + self.utxos[in2] = {owner: None, value: None} + self.utxos[sighash] = {owner: out1, value: value1} + self.utxos[as_bytes32(bitwise_xor(as_num256(sighash), as_num256(1)))] = \ + {owner: out2, value: value2} + return sighash