-
Notifications
You must be signed in to change notification settings - Fork 110
/
sortition_spk.erl
41 lines (39 loc) · 1.66 KB
/
sortition_spk.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-module(sortition_spk).
-export([verify/2, hash/1, merkelize_pubkeys/1]).
-include("../../records.hrl").
serialize_sortition_child(SSC) ->
SC = SSC#signed.data,
Sig = SSC#signed.sig,
Pub = SC#sortition_child.pubkey,
SID = SC#sortition_child.sid,
SR = SC#sortition_child.sortition_root,
<<Pub/binary,
SID/binary,
SR/binary,
Sig/binary>>.
hash(P = <<_:520>>) ->
hash:doit(P);
hash(SC) when (element(1, SC) == signed) ->
D = SC#signed.data,
Type = element(1, D),
case Type of
sortition_child ->
hash:doit(serialize_sortition_child(SC));
_ -> 1=2
end.
verify_merkle(Root, Contracts) ->
%verify that it has valid merkel proof.
ok.
verify_chalang(Contracts, Dict) ->
%make sure all the binary condition contracts return true.
ok.
verify(Contract, Dict) ->
%define(merkle_contract, {root, height, contracts}).
Root = Contract#merkle_contract.root,
CS = Contract#merkle_contract.contracts,
{Pubkeys, Valid0} = verify_merkle(Root, CS), %record a list of pubkeys who make up the list of sortition chain operators going back to the mainchain. This list of pubkeys along with the height the contract was generated is the evidence we record instead of a nonce like a state channel. This way if we are lying, all someone needs to show is that one of the pubkeys in our list was not a sortition operator for this part of the probability space at this point in time.
{Contract2, Valid1} = verify_chalang(CS, Dict),
%Contract2 is either state_channel or sortition_child, or the winner's pubkey.
{Pubkeys, Contract2, Valid0 and Valid1}.
merkelize_pubkeys(Pubkeys) ->
ok.