Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
ae9f25aa
Commit
ae9f25aa
authored
5 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[perf] sign block with buggy nacl for perf & verify sig when found proof
parent
00f753da
No related branches found
No related tags found
1 merge request
!1283
Resolve "Duniter uses a buggy version of TweetNaCl"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/modules/prover/lib/proof.ts
+29
-9
29 additions, 9 deletions
app/modules/prover/lib/proof.ts
with
29 additions
and
9 deletions
app/modules/prover/lib/proof.ts
+
29
−
9
View file @
ae9f25aa
...
@@ -17,7 +17,7 @@ import {hashf} from "../../../lib/common"
...
@@ -17,7 +17,7 @@ import {hashf} from "../../../lib/common"
import
{
DBBlock
}
from
"
../../../lib/db/DBBlock
"
import
{
DBBlock
}
from
"
../../../lib/db/DBBlock
"
import
{
ConfDTO
}
from
"
../../../lib/dto/ConfDTO
"
import
{
ConfDTO
}
from
"
../../../lib/dto/ConfDTO
"
import
{
ProverConstants
}
from
"
./constants
"
import
{
ProverConstants
}
from
"
./constants
"
import
{
KeyGen
}
from
"
../../../lib/common-libs/crypto/keyring
"
import
{
KeyGen
,
verify
,
verifyBuggy
}
from
"
../../../lib/common-libs/crypto/keyring
"
import
{
dos2unix
}
from
"
../../../lib/common-libs/dos2unix
"
import
{
dos2unix
}
from
"
../../../lib/common-libs/dos2unix
"
import
{
rawer
}
from
"
../../../lib/common-libs/index
"
import
{
rawer
}
from
"
../../../lib/common-libs/index
"
import
{
ProcessCpuProfiler
}
from
"
../../../ProcessCpuProfiler
"
import
{
ProcessCpuProfiler
}
from
"
../../../ProcessCpuProfiler
"
...
@@ -36,7 +36,9 @@ export function createPowWorker() {
...
@@ -36,7 +36,9 @@ export function createPowWorker() {
// By default, we do not prefix the PoW by any number
// By default, we do not prefix the PoW by any number
let
prefix
=
0
;
let
prefix
=
0
;
let
signatureFunc
:
any
,
lastSecret
:
any
,
lastVersion
:
number
,
currentCPU
=
1
;
let
sigFuncSaved
:
(
msg
:
string
)
=>
string
;
let
verifyFuncSaved
:
(
msg
:
string
,
sig
:
string
)
=>
boolean
;
let
lastSecret
:
any
,
lastVersion
:
number
,
currentCPU
:
number
=
1
;
process
.
on
(
'
uncaughtException
'
,
(
err
:
any
)
=>
{
process
.
on
(
'
uncaughtException
'
,
(
err
:
any
)
=>
{
console
.
error
(
err
.
stack
||
Error
(
err
))
console
.
error
(
err
.
stack
||
Error
(
err
))
...
@@ -115,24 +117,36 @@ export function createPowWorker() {
...
@@ -115,24 +117,36 @@ export function createPowWorker() {
prefix
*=
100
*
ProverConstants
.
NONCE_RANGE
prefix
*=
100
*
ProverConstants
.
NONCE_RANGE
}
}
const
highMark
=
stuff
.
highMark
;
const
highMark
=
stuff
.
highMark
;
// Define sigFunc
// Use Buggy version for performance reasons
let
sigFunc
=
null
;
let
sigFunc
=
null
;
if
(
signatureFunc
&&
lastSecret
===
pair
.
sec
&&
lastVersion
===
block
.
version
)
{
if
(
sigFuncSaved
&&
lastSecret
===
pair
.
sec
)
{
sigFunc
=
signatureFunc
;
sigFunc
=
sigFuncSaved
;
}
else
{
lastSecret
=
pair
.
sec
;
sigFunc
=
(
msg
:
string
)
=>
KeyGen
(
pair
.
pub
,
pair
.
sec
).
signSyncBuggy
(
msg
)
}
// Define verifyFunc
let
verifyFunc
=
null
;
if
(
verifyFuncSaved
&&
lastSecret
===
pair
.
sec
&&
lastVersion
===
block
.
version
)
{
verifyFunc
=
verifyFuncSaved
;
}
else
{
}
else
{
lastSecret
=
pair
.
sec
;
lastSecret
=
pair
.
sec
;
lastVersion
=
block
.
version
;
lastVersion
=
block
.
version
;
if
(
block
.
version
>=
12
)
{
if
(
block
.
version
>=
12
)
{
sig
Func
=
(
msg
:
string
)
=>
KeyGen
(
pair
.
pub
,
pair
.
sec
).
signSync
(
msg
)
verify
Func
=
(
msg
:
string
,
sig
:
string
)
=>
verify
(
msg
,
sig
,
pair
.
pub
)
}
else
{
}
else
{
sig
Func
=
(
msg
:
string
)
=>
KeyGen
(
pair
.
pub
,
pair
.
sec
).
signSyncBuggy
(
msg
)
verify
Func
=
(
msg
:
string
,
sig
:
string
)
=>
verifyBuggy
(
msg
,
sig
,
pair
.
pub
)
}
}
}
}
let
pow
=
""
,
sig
=
""
,
raw
=
""
;
/*****************
/*****************
* GO!
* GO!
****************/
****************/
let
pow
=
""
,
sig
=
""
,
raw
=
""
;
let
pausePeriod
=
1
;
let
pausePeriod
=
1
;
let
testsCount
=
0
;
let
testsCount
=
0
;
let
found
=
false
;
let
found
=
false
;
...
@@ -198,6 +212,12 @@ export function createPowWorker() {
...
@@ -198,6 +212,12 @@ export function createPowWorker() {
}
}
if
(
charOK
)
{
if
(
charOK
)
{
found
=
!!
(
pow
[
nbZeros
].
match
(
new
RegExp
(
'
[0-
'
+
highMark
+
'
]
'
)))
found
=
!!
(
pow
[
nbZeros
].
match
(
new
RegExp
(
'
[0-
'
+
highMark
+
'
]
'
)))
if
(
found
)
{
let
sigOk
=
verifyFunc
(
raw
,
sig
);
if
(
!
sigOk
)
{
found
=
false
;
}
}
}
}
if
(
!
found
&&
nbZeros
>
0
&&
j
-
1
>=
ProverConstants
.
POW_MINIMAL_TO_SHOW
)
{
if
(
!
found
&&
nbZeros
>
0
&&
j
-
1
>=
ProverConstants
.
POW_MINIMAL_TO_SHOW
)
{
pSend
({
pow
:
{
pow
:
pow
,
block
:
block
,
nbZeros
:
nbZeros
}});
pSend
({
pow
:
{
pow
:
pow
,
block
:
block
,
nbZeros
:
nbZeros
}});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment