-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanonymity.go
More file actions
72 lines (66 loc) · 2.1 KB
/
anonymity.go
File metadata and controls
72 lines (66 loc) · 2.1 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
func analysTransactions(trans []TXO, known []uint32) (guesses []uint32, err error) {
return
}
type AnalysisInfo interface {
// GetTXO requires a proof that you should be able to see this transaction, providing
// a chain that leads back to a transaction in which you were involved.
GetTXO(id uint32, chain []uint32) (TXO, error)
}
func NaiveAnalysis(incoming, outgoing []TXO, identities map[uint32]uint32, ai AnalysisInfo) (txoSeen []TXO, identified map[uint32]uint32) {
// First gather all the transactions that I can get based on tracing the ones I have been involved
// in backwards and store them
transs := append(incoming, outgoing...)
kTrans := make(map[uint32]TXO)
var rec func(uint32, []uint32)
rec = func(tid uint32, chain []uint32) {
if _, ok := kTrans[tid]; ok {
return
}
// get this one using the chain, and recurse down, building the chain
t, e := ai.GetTXO(tid, chain)
if e != nil {
panic(e.Error())
}
kTrans[t.id] = t
if t.from != nil {
for _, tt := range t.from {
rec(tt, append(chain, tid))
}
}
}
for _, t := range transs {
rec(t.id, []uint32{})
}
txoSeen = make([]TXO, 0, len(kTrans))
for _, v := range kTrans {
txoSeen = append(txoSeen, v)
}
// And now try to find out which transactions belong to which bank
identified = make(map[uint32]uint32)
for k, v := range identities {
identified[k] = v
}
// One by one move out the items from kTrans if we can identify the playes, keep this going
// untile we have been through one complete round without adding any one.
for nod := 1; nod > 0; {
nod = 0
Outer:
for id, t := range kTrans {
// If we know any one of the from we know all of them, so update identified
for _, fid := range t.from {
if iden, ok := identified[fid]; ok {
// // so update all the from, remove it and continue
for _, ffid := range t.from {
identified[ffid] = iden
}
delete(kTrans, id)
nod++
continue Outer
}
}
}
// TODO: CAN WE DO MORE HERE, ANY OTHER DETERMINSITIC LOGIC WE CAN USE TO CORRELATE MORE? ANYTHING IF WE DO PROBABILISTIC?
}
return txoSeen, identified
}