mirror of
https://github.com/status-im/research.git
synced 2025-01-27 07:15:14 +00:00
Added minimum utxo scheme
This commit is contained in:
parent
b4e235303e
commit
9a417389fa
@ -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')
|
||||
|
@ -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)
|
||||
|
26
utxo_tester.py
Normal file
26
utxo_tester.py
Normal file
@ -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')
|
19
utxos.v.py
Normal file
19
utxos.v.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user