Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
2c177f2a
Unverified
Commit
2c177f2a
authored
Jul 08, 2021
by
Viktor Trón
Committed by
GitHub
Jul 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(pss): improve trojan mining (#2287)
parent
b0e9ca5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
18 deletions
+15
-18
mining_test.go
pkg/pss/mining_test.go
+3
-3
trojan.go
pkg/pss/trojan.go
+12
-15
No files found.
pkg/pss/mining_test.go
View file @
2c177f2a
...
@@ -30,11 +30,11 @@ func BenchmarkWrap(b *testing.B) {
...
@@ -30,11 +30,11 @@ func BenchmarkWrap(b *testing.B) {
depth
int
depth
int
}{
}{
{
1
,
1
},
{
1
,
1
},
{
4
,
1
},
{
256
,
2
},
{
16
,
1
},
{
8
,
1
},
{
256
,
1
},
{
16
,
2
},
{
16
,
2
},
{
64
,
2
},
{
64
,
2
},
{
256
,
2
},
{
256
,
3
},
{
256
,
3
},
{
4096
,
3
},
{
4096
,
3
},
{
16384
,
3
},
{
16384
,
3
},
...
...
pkg/pss/trojan.go
View file @
2c177f2a
...
@@ -201,8 +201,7 @@ func contains(col Targets, elem []byte) bool {
...
@@ -201,8 +201,7 @@ func contains(col Targets, elem []byte) bool {
}
}
// mine iteratively enumerates different nonces until the address (BMT hash) of the chunkhas one of the targets as its prefix
// mine iteratively enumerates different nonces until the address (BMT hash) of the chunkhas one of the targets as its prefix
func
mine
(
ctx
context
.
Context
,
odd
bool
,
f
func
(
nonce
[]
byte
)
(
swarm
.
Chunk
,
error
))
(
r
swarm
.
Chunk
,
e
error
)
{
func
mine
(
ctx
context
.
Context
,
odd
bool
,
f
func
(
nonce
[]
byte
)
(
swarm
.
Chunk
,
error
))
(
swarm
.
Chunk
,
error
)
{
seeds
:=
make
([]
uint32
,
8
)
initnonce
:=
make
([]
byte
,
32
)
initnonce
:=
make
([]
byte
,
32
)
if
_
,
err
:=
io
.
ReadFull
(
random
.
Reader
,
initnonce
);
err
!=
nil
{
if
_
,
err
:=
io
.
ReadFull
(
random
.
Reader
,
initnonce
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -212,26 +211,23 @@ func mine(ctx context.Context, odd bool, f func(nonce []byte) (swarm.Chunk, erro
...
@@ -212,26 +211,23 @@ func mine(ctx context.Context, odd bool, f func(nonce []byte) (swarm.Chunk, erro
}
else
{
}
else
{
initnonce
[
28
]
&=
0xfe
initnonce
[
28
]
&=
0xfe
}
}
for
i
:=
range
seeds
{
seeds
[
i
]
=
binary
.
BigEndian
.
Uint32
(
initnonce
[
i
*
4
:
i
*
4
+
4
])
}
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
defer
cancel
()
eg
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
eg
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
result
:=
make
(
chan
swarm
.
Chunk
,
8
)
result
:=
make
(
chan
swarm
.
Chunk
,
8
)
for
i
:=
0
;
i
<
8
;
i
++
{
for
i
:=
0
;
i
<
8
;
i
++
{
j
:=
i
eg
.
Go
(
func
()
error
{
eg
.
Go
(
func
()
error
{
nonce
:=
make
([]
byte
,
32
)
nonce
:=
make
([]
byte
,
32
)
copy
(
nonce
,
initnonce
)
copy
(
nonce
,
initnonce
)
for
seed
:=
seeds
[
j
];
;
seed
+=
2
{
for
{
select
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
return
ctx
.
Err
()
default
:
default
:
}
}
binary
.
BigEndian
.
PutUint32
(
nonce
[
j
*
4
:
j
*
4
+
4
],
seed
)
if
_
,
err
:=
io
.
ReadFull
(
random
.
Reader
,
nonce
[
:
4
]);
err
!=
nil
{
return
err
}
res
,
err
:=
f
(
nonce
)
res
,
err
:=
f
(
nonce
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -243,15 +239,16 @@ func mine(ctx context.Context, odd bool, f func(nonce []byte) (swarm.Chunk, erro
...
@@ -243,15 +239,16 @@ func mine(ctx context.Context, odd bool, f func(nonce []byte) (swarm.Chunk, erro
}
}
})
})
}
}
errc
:=
make
(
chan
error
)
var
err
error
go
func
()
{
go
func
()
{
errc
<-
eg
.
Wait
()
err
=
eg
.
Wait
()
result
<-
nil
}()
}()
select
{
r
:=
<-
result
case
r
=
<-
result
:
if
r
==
nil
{
case
e
=
<-
errc
:
return
nil
,
err
}
}
return
r
,
e
return
r
,
nil
}
}
// extracts ephemeral public key from the chunk data to use with el-Gamal
// extracts ephemeral public key from the chunk data to use with el-Gamal
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment